Skip to content

Commit e6027b5

Browse files
kevwilliamsclaude
andcommitted
fix: resolve OpenAPI spec $ref naming mismatch
DefaultOpenAPIV3Config pre-computes the Definitions map immediately using the default GetDefinitionName (without ToRESTFriendlyName). The kube-openapi builder (builder3/openapi.go) prefers the pre-computed Definitions map over calling GetDefinitions again — so when main.go overrides GetDefinitionName to add ToRESTFriendlyName, the schema component keys get the friendly names but the $ref strings inside the pre-computed map do not. This caused the generated OpenAPI spec to have mismatched naming conventions between $ref values and schema component keys, breaking clients that rely on ref resolution (e.g. openapi-ts code generators). Fix: nil out Definitions after overriding GetDefinitionName so the builder falls through to GetDefinitions and builds fresh $refs using the corrected GetDefinitionName, keeping both sides consistent. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent dd4a121 commit e6027b5

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

cmd/search/main.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,12 @@ func (o *SearchServerOptions) Config() (*searchapiserver.Config, error) {
190190
friendlyName, extensions := namer.GetDefinitionName(name)
191191
return openapiutil.ToRESTFriendlyName(friendlyName), extensions
192192
}
193+
// Nil out the pre-computed Definitions map so the OpenAPI builder re-invokes
194+
// GetDefinitions with a fresh ref callback that uses the updated GetDefinitionName
195+
// above. Without this, the builder uses the pre-computed $refs (which were built
196+
// before GetDefinitionName was overridden) and the schema component keys diverge
197+
// from the $ref values in the generated spec.
198+
genericConfig.OpenAPIV3Config.Definitions = nil
193199

194200
// Configure OpenAPI v2
195201
genericConfig.OpenAPIConfig = genericapiserver.DefaultOpenAPIConfig(openapi.GetOpenAPIDefinitionsWithUnstructured, namer)

0 commit comments

Comments
 (0)