swagger-api / swagger-api/swagger-parser
[Question] [Bug]: Inconsistent Relative Reference Resolution in Nested Schema Contexts
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
Question
There seems to be a bug when resolving nested schemas.
OpenAPI Generator incorrectly resolves relative $ref paths in schema files when they are referenced through nested contexts (like additionalProperties). The reference resolution context switches from file-relative to root-relative depending on the nesting level, causing build failures when using standard file-relative references.
This creates inconsistent behavior where:
References from path files work correctly using file-relative paths (../components/schemas/...)
References from schema files fail when using file-relative paths (NestedData.yaml)
This violates the OpenAPI 3.0 specification where all relative references should be resolved from the containing file's location.
Any ideas? parentDirectory seems to be resolved wrongly in this case?
Affected Version
Latest
Context
This issue first reported here: https://github.com/OpenAPITools/openapi-generator/issues/21492 (the project uses this library)
# Example OpenAPI or Swagger definition (optional)
Additional Details
Checklist
- I have searched the existing issues and documentation before asking.
- I have provided enough information for others to understand my question.
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 with the reproduction context in OpenAPITools/openapi-generator#21492 and inspect how parentDirectory is handled while resolving relative $ref values through nested additionalProperties schemas. Verify the behavior against the OpenAPI 3.0 file-relative rule, including both path-file and schema-file references; done means nested references resolve consistently without build failures.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100