feat(api): expose swagger path in config snapshot
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
d06f4957a3
commit
2fb2c6939f
2 changed files with 17 additions and 0 deletions
|
|
@ -17,6 +17,7 @@ import (
|
|||
// cfg := api.SwaggerConfig{Title: "Service", Summary: "Public API"}
|
||||
type SwaggerConfig struct {
|
||||
Enabled bool
|
||||
Path string
|
||||
Title string
|
||||
Summary string
|
||||
Description string
|
||||
|
|
@ -89,6 +90,7 @@ func (e *Engine) SwaggerConfig() SwaggerConfig {
|
|||
|
||||
return SwaggerConfig{
|
||||
Enabled: e.swaggerEnabled,
|
||||
Path: e.swaggerPath,
|
||||
Title: e.swaggerTitle,
|
||||
Summary: e.swaggerSummary,
|
||||
Description: e.swaggerDesc,
|
||||
|
|
|
|||
|
|
@ -205,6 +205,9 @@ func TestEngine_Good_SwaggerConfigCarriesEngineMetadata(t *testing.T) {
|
|||
if !cfg.Enabled {
|
||||
t.Fatal("expected Swagger to be enabled")
|
||||
}
|
||||
if cfg.Path != "" {
|
||||
t.Fatalf("expected empty Swagger path when none is configured, got %q", cfg.Path)
|
||||
}
|
||||
if cfg.Title != "Engine API" {
|
||||
t.Fatalf("expected title Engine API, got %q", cfg.Title)
|
||||
}
|
||||
|
|
@ -240,6 +243,18 @@ func TestEngine_Good_SwaggerConfigCarriesEngineMetadata(t *testing.T) {
|
|||
t.Fatalf("expected second server to be /, got %q", cfg.Servers[1])
|
||||
}
|
||||
|
||||
cfgWithPath, err := api.New(
|
||||
api.WithSwagger("Engine API", "Engine metadata", "2.0.0"),
|
||||
api.WithSwaggerPath("/docs"),
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
snap := cfgWithPath.SwaggerConfig()
|
||||
if snap.Path != "/docs" {
|
||||
t.Fatalf("expected Swagger path /docs, got %q", snap.Path)
|
||||
}
|
||||
|
||||
apiKeyAuth, ok := cfg.SecuritySchemes["apiKeyAuth"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatal("expected apiKeyAuth security scheme in Swagger config")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue