swagger-api / swagger-api/swagger-codegen
[BUG] Cannot parse OpenAPI 3.1 specs using $dynamicRef / $dynamicAnchor (blocked by swagger-parser)
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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:
- Recursive category tree: https://github.com/aqeelat/openapi-dynamicref-adoption-tracker/blob/main/fixtures/recursive-category-tree.yaml
- Nested workspace resources: https://github.com/aqeelat/openapi-dynamicref-adoption-tracker/blob/main/fixtures/nested-workspace-resources.yaml
- Pagination/generic wrapper (named schemas): https://github.com/aqeelat/openapi-dynamicref-adoption-tracker/blob/main/fixtures/generic-schema-binding.yaml
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
$idand$ref(resolves#/components/schemas/...against the$idURI instead of the document root) - Loses
$dynamicRef,$dynamicAnchor, and$defsduring the dereference cycle - Does not traverse
$defssub-schemas
A fix PR is open: https://github.com/swagger-api/swagger-parser/pull/2332
Expected Behavior
After the swagger-parser fix is merged and swagger-codegen updates its dependency:
- Specs with
$dynamicRef/$dynamicAnchorshould parse without errors. - The codegen layer should then be updated to resolve
$dynamicRefto concrete types instead of emittinganyor empty interfaces.
Blocking Dependency
- https://github.com/swagger-api/swagger-parser/pull/2332 — fixes parser-level
$dynamicRef/$dynamicAnchorsupport
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided Docker command with the recursive-category-tree.yaml fixture and inspect the generated typescript-fetch output. Review swagger-parser PR #2332 and the dependency path used by swagger-codegen, then trace how $dynamicRef, $dynamicAnchor, and $defs reach code generation. Done means the parser update is available and these fixtures generate concrete types instead of any or empty interfaces.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- openapi, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100