feat(api): expose swagger enabled transport flag

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 08:45:20 +00:00
parent 51b176c1cf
commit 83d12d6024
2 changed files with 23 additions and 1 deletions

View file

@ -299,6 +299,9 @@ func TestEngine_Good_TransportConfigCarriesEngineMetadata(t *testing.T) {
}
cfg := e.TransportConfig()
if !cfg.SwaggerEnabled {
t.Fatal("expected Swagger to be enabled")
}
if cfg.SwaggerPath != "/docs" {
t.Fatalf("expected swagger path /docs, got %q", cfg.SwaggerPath)
}
@ -325,6 +328,23 @@ func TestEngine_Good_TransportConfigCarriesEngineMetadata(t *testing.T) {
}
}
func TestEngine_Good_TransportConfigReportsDisabledSwaggerWithoutUI(t *testing.T) {
gin.SetMode(gin.TestMode)
e, err := api.New(api.WithSwaggerPath("/docs"))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
cfg := e.TransportConfig()
if cfg.SwaggerEnabled {
t.Fatal("expected Swagger to remain disabled when only the path is configured")
}
if cfg.SwaggerPath != "/docs" {
t.Fatalf("expected swagger path /docs, got %q", cfg.SwaggerPath)
}
}
func TestEngine_Good_OpenAPISpecBuilderExportsDefaultSwaggerPath(t *testing.T) {
gin.SetMode(gin.TestMode)

View file

@ -13,9 +13,10 @@ import "strings"
//
// cfg := api.TransportConfig{SwaggerPath: "/swagger", WSPath: "/ws"}
type TransportConfig struct {
SwaggerEnabled bool
SwaggerPath string
GraphQLPath string
GraphQLEnabled bool
GraphQLEnabled bool
GraphQLPlayground bool
WSPath string
SSEPath string
@ -37,6 +38,7 @@ func (e *Engine) TransportConfig() TransportConfig {
}
cfg := TransportConfig{
SwaggerEnabled: e.swaggerEnabled,
GraphQLEnabled: e.graphql != nil,
GraphQLPlayground: e.graphql != nil && e.graphql.playground,
PprofEnabled: e.pprofEnabled,