From 57ff0d2a48b073222635ee29b9b679773bd8128e Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 08:57:41 +0000 Subject: [PATCH] feat(api): expose swagger and graphql spec flags --- openapi.go | 8 ++++++++ openapi_test.go | 6 ++++++ spec_builder_helper.go | 2 ++ spec_builder_helper_test.go | 6 ++++++ 4 files changed, 22 insertions(+) diff --git a/openapi.go b/openapi.go index 9d91947..5406142 100644 --- a/openapi.go +++ b/openapi.go @@ -25,7 +25,9 @@ type SpecBuilder struct { Summary string Description string Version string + SwaggerEnabled bool SwaggerPath string + GraphQLEnabled bool GraphQLPath string GraphQLPlayground bool WSPath string @@ -94,6 +96,12 @@ func (sb *SpecBuilder) Build(groups []RouteGroup) ([]byte, error) { if swaggerPath := strings.TrimSpace(sb.SwaggerPath); swaggerPath != "" { spec["x-swagger-ui-path"] = normaliseSwaggerPath(swaggerPath) } + if sb.SwaggerEnabled { + spec["x-swagger-enabled"] = true + } + if sb.GraphQLEnabled { + spec["x-graphql-enabled"] = true + } if graphqlPath := sb.effectiveGraphQLPath(); graphqlPath != "" { spec["x-graphql-path"] = normaliseOpenAPIPath(graphqlPath) spec["x-graphql-playground"] = sb.GraphQLPlayground diff --git a/openapi_test.go b/openapi_test.go index 4f95653..56de063 100644 --- a/openapi_test.go +++ b/openapi_test.go @@ -200,6 +200,12 @@ func TestSpecBuilder_Good_EmptyGroups(t *testing.T) { if _, ok := spec["security"]; ok { t.Fatal("expected no global security requirement in the document") } + if _, ok := spec["x-swagger-enabled"]; ok { + t.Fatal("expected no swagger enabled flag in the document when swagger is disabled") + } + if _, ok := spec["x-graphql-enabled"]; ok { + t.Fatal("expected no graphql enabled flag in the document when graphql is disabled") + } } func TestSpecBuilder_Good_CustomSecuritySchemesAreMerged(t *testing.T) { diff --git a/spec_builder_helper.go b/spec_builder_helper.go index 1801047..0d541ad 100644 --- a/spec_builder_helper.go +++ b/spec_builder_helper.go @@ -52,6 +52,7 @@ func (e *Engine) OpenAPISpecBuilder() *SpecBuilder { Summary: swagger.Summary, Description: swagger.Description, Version: swagger.Version, + SwaggerEnabled: swagger.Enabled, TermsOfService: swagger.TermsOfService, ContactName: swagger.ContactName, ContactURL: swagger.ContactURL, @@ -65,6 +66,7 @@ func (e *Engine) OpenAPISpecBuilder() *SpecBuilder { } builder.SwaggerPath = transport.SwaggerPath + builder.GraphQLEnabled = transport.GraphQLEnabled builder.GraphQLPath = transport.GraphQLPath builder.GraphQLPlayground = transport.GraphQLPlayground builder.WSPath = transport.WSPath diff --git a/spec_builder_helper_test.go b/spec_builder_helper_test.go index 3155742..dc95486 100644 --- a/spec_builder_helper_test.go +++ b/spec_builder_helper_test.go @@ -75,6 +75,12 @@ func TestEngine_Good_OpenAPISpecBuilderCarriesEngineMetadata(t *testing.T) { if got := spec["x-swagger-ui-path"]; got != "/docs" { t.Fatalf("expected x-swagger-ui-path=/docs, got %v", got) } + if got := spec["x-swagger-enabled"]; got != true { + t.Fatalf("expected x-swagger-enabled=true, got %v", got) + } + if got := spec["x-graphql-enabled"]; got != true { + t.Fatalf("expected x-graphql-enabled=true, got %v", got) + } if got := spec["x-graphql-path"]; got != "/gql" { t.Fatalf("expected x-graphql-path=/gql, got %v", got) }