From 8dd15251ea4152789605e2c6af7f95bb2efb97c0 Mon Sep 17 00:00:00 2001 From: Virgil Date: Fri, 3 Apr 2026 04:56:48 +0000 Subject: [PATCH] fix(api): omit disabled graphql playground spec metadata Co-Authored-By: Virgil --- openapi.go | 10 +++++++--- openapi_test.go | 3 +++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/openapi.go b/openapi.go index 66260b7..82d0cc2 100644 --- a/openapi.go +++ b/openapi.go @@ -123,10 +123,14 @@ func (sb *SpecBuilder) Build(groups []RouteGroup) ([]byte, error) { } if graphqlPath := sb.effectiveGraphQLPath(); graphqlPath != "" { spec["x-graphql-path"] = normaliseOpenAPIPath(graphqlPath) - spec["x-graphql-playground"] = sb.GraphQLPlayground + if sb.GraphQLPlayground { + spec["x-graphql-playground"] = true + } } - if playgroundPath := sb.effectiveGraphQLPlaygroundPath(); playgroundPath != "" { - spec["x-graphql-playground-path"] = normaliseOpenAPIPath(playgroundPath) + if sb.GraphQLPlayground { + if playgroundPath := sb.effectiveGraphQLPlaygroundPath(); playgroundPath != "" { + spec["x-graphql-playground-path"] = normaliseOpenAPIPath(playgroundPath) + } } if wsPath := sb.effectiveWSPath(); wsPath != "" { spec["x-ws-path"] = normaliseOpenAPIPath(wsPath) diff --git a/openapi_test.go b/openapi_test.go index b983392..aa67c86 100644 --- a/openapi_test.go +++ b/openapi_test.go @@ -562,6 +562,9 @@ func TestSpecBuilder_Good_GraphQLEndpoint(t *testing.T) { if !found { t.Fatal("expected graphql tag in spec") } + if _, ok := spec["x-graphql-playground"]; ok { + t.Fatal("expected x-graphql-playground to be omitted when playground is disabled") + } paths := spec["paths"].(map[string]any) pathItem, ok := paths["/graphql"].(map[string]any)