Repository navigation
Description
Summary
When the base spec references a response defined in an external file via import-mapping, the generated client-with-responses wrapper builds the imported type name from the raw component name. It does not honour the Go name the external package actually generated, so the base package can reference a type the imported package never declares, and the generated client fails to compile.
This was discovered while fixing #2308 (external path item responses). The path-item case is fixed there, but the same gap exists for direct external response refs and is broader.
Two cases
1. x-go-name on the external response (direct ref).
spec-ext.yaml:
components:
responses:
Outcome:
x-go-name: OutcomeResult
content:
application/json:
schema: { type: string }spec-base.yaml (direct ref, no path item):
paths:
/direct:
get:
responses:
'200':
$ref: 'spec-ext.yaml#/components/responses/Outcome'The external package declares type OutcomeResult = string, but the base client emits:
JSON200 *externalRef0.Outcome // undefined: imported package only declares OutcomeResult2. Cross-package collision renames.
If the external document's name resolver renames a component because of a collision within that document, the base run cannot reproduce that name: each codegen run resolves names independently and there is no shared resolved-name map / artifact between them. So the base package again references a name the imported package never declared.
Why it happens
For external refs the name is resolved with RefPathToGoType → refPathToGoTypeSelf, which keys off the root spec (resolvedNameForComponent / findSchemaNameByRefPath against globalState.spec) and otherwise falls back to SchemaNameToTypeName(<rawName>). It never consults the external component's x-go-name, nor the external document's own name resolution.
Note that x-go-name is recoverable (it rides along on the resolved $ref value's Extensions), so case 1 is fixable locally — that is exactly what the #2308 fix does for the path-item branch. Case 2 (collision renames) is not recoverable without resolving the external document.
Scope / suggestion
- Honour
x-go-nameon the resolved external component for direct external refs too, so it matches the path-item behaviour landed in PathItem support missing #2308 (symmetry; fixes case 1). - Cross-package collision naming (case 2) likely needs a shared/persisted resolved-name map between codegen runs, or a documented constraint that external components avoid collision-driven renames.
Reproduction
x-go-name case reproduces with generate: { client: true, models: true } plus an import-mapping entry for spec-ext.yaml, using the specs above.
Activity
fix: honour external package's Go name for direct response refs (#2423)
fix: honour external package's Go name for direct response refs (oapi…