feat(openapi): default graphql path for playground specs

Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
Virgil 2026-04-02 03:00:51 +00:00
parent f53617c507
commit 85d6f6dd6e
2 changed files with 31 additions and 1 deletions

View file

@ -191,7 +191,11 @@ func (sb *SpecBuilder) buildPaths(groups []preparedRouteGroup) map[string]any {
},
}
if graphqlPath := strings.TrimSpace(sb.GraphQLPath); graphqlPath != "" {
graphqlPath := strings.TrimSpace(sb.GraphQLPath)
if graphqlPath == "" && sb.GraphQLPlayground {
graphqlPath = defaultGraphQLPath
}
if graphqlPath != "" {
graphqlPath = normaliseOpenAPIPath(graphqlPath)
paths[graphqlPath] = graphqlPathItem(graphqlPath, operationIDs)
if sb.GraphQLPlayground {

View file

@ -304,6 +304,32 @@ func TestSpecBuilder_Good_GraphQLPlaygroundEndpoint(t *testing.T) {
}
}
func TestSpecBuilder_Good_GraphQLPlaygroundDefaultsToGraphQLPath(t *testing.T) {
sb := &api.SpecBuilder{
Title: "Test",
Version: "1.0.0",
GraphQLPlayground: true,
}
data, err := sb.Build(nil)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
var spec map[string]any
if err := json.Unmarshal(data, &spec); err != nil {
t.Fatalf("invalid JSON: %v", err)
}
paths := spec["paths"].(map[string]any)
if _, ok := paths["/graphql"].(map[string]any); !ok {
t.Fatal("expected default /graphql path when playground is enabled")
}
if _, ok := paths["/graphql/playground"].(map[string]any); !ok {
t.Fatal("expected default /graphql/playground path when playground is enabled")
}
}
func TestSpecBuilder_Good_WebSocketEndpoint(t *testing.T) {
sb := &api.SpecBuilder{
Title: "Test",