Summary
Swagger Codegen v3 fails to produce meaningful types for OpenAPI 3.1 specs that use $dynamicRef / $dynamicAnchor. Schemas containing $dynamicAnchor result in empty interfaces or any types because swagger-parser does not preserve these fields through the parse/dereference cycle.
Reproduction
Minimal fixtures demonstrating the issue:
docker run --rm \
-v $(pwd)/recursive-category-tree.yaml:/spec.json \
swaggerapi/swagger-codegen-cli-v3 generate \
-i /spec.json -l typescript-fetch -o /out
Result: interface PaginatedUserResponse {} — empty interface, all type information lost.
Root Cause
The failure originates in swagger-parser (shared dependency with OpenAPI Generator). The OAS 3.1 dereferencer:
- Crashes when component schemas have both
$id and $ref (resolves #/components/schemas/... against the $id URI instead of the document root)
- Loses
$dynamicRef, $dynamicAnchor, and $defs during the dereference cycle
- Does not traverse
$defs sub-schemas
A fix PR is open: swagger-api/swagger-parser#2332
Expected Behavior
After the swagger-parser fix is merged and swagger-codegen updates its dependency:
- Specs with
$dynamicRef / $dynamicAnchor should parse without errors.
- The codegen layer should then be updated to resolve
$dynamicRef to concrete types instead of emitting any or empty interfaces.
Blocking Dependency
Compatibility Evidence
A cross-generator compatibility matrix is tracked at:
https://github.com/aqeelat/openapi-dynamicref-adoption-tracker
This issue was drafted with assistance from AI tooling. The submitter is responsible for reviewing and validating the contents before submission.
Summary
Swagger Codegen v3 fails to produce meaningful types for OpenAPI 3.1 specs that use
$dynamicRef/$dynamicAnchor. Schemas containing$dynamicAnchorresult in empty interfaces oranytypes because swagger-parser does not preserve these fields through the parse/dereference cycle.Reproduction
Minimal fixtures demonstrating the issue:
docker run --rm \ -v $(pwd)/recursive-category-tree.yaml:/spec.json \ swaggerapi/swagger-codegen-cli-v3 generate \ -i /spec.json -l typescript-fetch -o /outResult:
interface PaginatedUserResponse {}— empty interface, all type information lost.Root Cause
The failure originates in swagger-parser (shared dependency with OpenAPI Generator). The OAS 3.1 dereferencer:
$idand$ref(resolves#/components/schemas/...against the$idURI instead of the document root)$dynamicRef,$dynamicAnchor, and$defsduring the dereference cycle$defssub-schemasA fix PR is open: swagger-api/swagger-parser#2332
Expected Behavior
After the swagger-parser fix is merged and swagger-codegen updates its dependency:
$dynamicRef/$dynamicAnchorshould parse without errors.$dynamicRefto concrete types instead of emittinganyor empty interfaces.Blocking Dependency
$dynamicRef/$dynamicAnchorsupportCompatibility Evidence
A cross-generator compatibility matrix is tracked at:
https://github.com/aqeelat/openapi-dynamicref-adoption-tracker
This issue was drafted with assistance from AI tooling. The submitter is responsible for reviewing and validating the contents before submission.