feat(api): expose swagger and graphql spec flags

This commit is contained in:
Virgil 2026-04-02 08:57:41 +00:00
parent d40ff2c294
commit 57ff0d2a48
4 changed files with 22 additions and 0 deletions

View file

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

View file

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

View file

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

View file

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