swagger-api / swagger-api/swagger-codegen

[BUG] Cannot parse OpenAPI 3.1 specs using $dynamicRef / $dynamicAnchor (blocked by swagger-parser)

Open
#12,731 0 comments 0 reactions 0 assignees View on GitHub

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:

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:

  1. Crashes when component schemas have both $id and $ref (resolves #/components/schemas/... against the $id URI instead of the document root)
  2. Loses $dynamicRef, $dynamicAnchor, and $defs during the dereference cycle
  3. Does not traverse $defs sub-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:

  1. Specs with $dynamicRef / $dynamicAnchor should parse without errors.
  2. 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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.