fix(api): omit disabled graphql playground spec metadata

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-03 04:56:48 +00:00
parent a3a1c20e7a
commit 8dd15251ea
2 changed files with 10 additions and 3 deletions

View file

@ -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)

View file

@ -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)