diff --git a/pkg/builder3/openapi.go b/pkg/builder3/openapi.go index e59844786..081dae306 100644 --- a/pkg/builder3/openapi.go +++ b/pkg/builder3/openapi.go @@ -326,6 +326,9 @@ func BuildOpenAPISpecFromRoutes(webServices []common.RouteContainer, config *com if err != nil { return nil, err } + if config.PostProcessSpec != nil { + return config.PostProcessSpec(a.spec) + } return a.spec, nil } diff --git a/pkg/builder3/openapi_test.go b/pkg/builder3/openapi_test.go index 381307167..d75c8c0ed 100644 --- a/pkg/builder3/openapi_test.go +++ b/pkg/builder3/openapi_test.go @@ -436,6 +436,11 @@ func TestBuildOpenAPISpec(t *testing.T) { Description: "Test API", Version: "unversioned", }, + VendorExtensible: spec.VendorExtensible{ + Extensions: map[string]any{ + "hello": "world", // set from PostProcessSpec callback + }, + }, }, Version: "3.0.0", Paths: &spec3.Paths{ @@ -451,6 +456,12 @@ func TestBuildOpenAPISpec(t *testing.T) { }, }, } + config.PostProcessSpec = func(s *spec3.OpenAPI) (*spec3.OpenAPI, error) { + s.Info.Extensions = map[string]any{ + "hello": "world", + } + return s, nil + } swagger, err := BuildOpenAPISpec(container.RegisteredWebServices(), config) if !assert.NoError(err) { return diff --git a/pkg/common/common.go b/pkg/common/common.go index 2e15e163c..e4ce843b0 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -164,6 +164,9 @@ type OpenAPIV3Config struct { // It is an optional function to customize model names. GetDefinitionName func(name string) (string, spec.Extensions) + // PostProcessSpec runs after the spec is ready to serve. It allows a final modification to the spec before serving. + PostProcessSpec func(*spec3.OpenAPI) (*spec3.OpenAPI, error) + // SecuritySchemes is list of all security schemes for OpenAPI service. SecuritySchemes spec3.SecuritySchemes