[Bug]: content.examples $ref not resolved in request bodies or parameters
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 52/100
Research direction
Start by reproducing the issue through OpenAPIParser.readContents with ParseOptions resolve and resolveFully enabled, using the request-body and parameter examples shown. Trace how the parser handles the content examples and compare both locations; done means each example reference is replaced by the referenced example data in the parsed OpenAPI result, with regression coverage for both cases.
Written by the indexing model from the issue text.
Description
Description
When using resolveFully(true) to parse OpenAPI 3.0.x specs, $ref pointers within content.examples (in request bodies and parameters) are not resolved. The $ref remains as a pointer instead of being replaced with the referenced example.
Affected Version
- 2.1.36
Steps to Reproduce
You can reproduce this issue by passing in an Open API 3.0.x spec with content examples into a parser with resolve options enabled.
String spec = """
{
"openapi": "3.0.3",
"info": {
"title": "Example Reference Demo API",
"version": "1.0"
},
"paths": {
"/users": {
"post": {
"summary": "Create a user",
"parameters": [
{
"name": "filter",
"in": "query",
"content": {
"application/json": {
"schema": {
"type": "object"
},
"examples": {
"simpleFilter": {
"$ref": "#/components/examples/FilterExample"
}
}
}
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/User"
},
"examples": {
"defaultUser": {
"$ref": "#/components/examples/UserExample"
}
}
}
}
},
"responses": {
"201": {
"description": "Created"
}
}
}
}
},
"components": {
"schemas": {
"User": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"name": {
"type": "string"
}
}
}
},
"examples": {
"UserExample": {
"summary": "A sample user",
"value": {
"id": "12345",
"name": "John Doe"
}
},
"FilterExample": {
"summary": "A sample filter",
"value": {
"status": "active"
}
}
}
}
}
""";
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setResolveFully(true);
SwaggerParseResult openAPIresult = new OpenAPIParser().readContents(spec, null, options);
OpenAPI result = openAPIResult.getOpenAPI();
System.out.println("OpenAPI result: " + result);
Expected Behavior
Content examples are resolved:
{
"paths": {
"/users": {
"post": {
"summary": "Create a user",
"parameters": [
{
"name": "filter",
"in": "query",
"content": {
"application/json": {
"schema": { "type": "object" },
"examples": {
"simpleFilter": {
"summary": "A sample filter",
"value": { "status": "active" }
}
}
}
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" }
}
},
"examples": {
"defaultUser": {
"summary": "A sample user",
"value": { "id": "12345", "name": "John Doe" }
}
}
}
}
},
"responses": { "201": { "description": "Created" } }
}
}
}
}
Actual Behavior
Content examples remain as $ref pointers:
{
"paths": {
"/users": {
"post": {
"summary": "Create a user",
"parameters": [
{
"name": "filter",
"in": "query",
"content": {
"application/json": {
"schema": { "type": "object" },
"examples": {
"simpleFilter": {
"$ref": "#/components/examples/FilterExample"
}
}
}
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": { "type": "string" },
"name": { "type": "string" }
}
},
"examples": {
"defaultUser": {
"$ref": "#/components/examples/UserExample"
}
}
}
}
},
"responses": { "201": { "description": "Created" } }
}
}
}
}
Logs / Stack Traces
N/A
Environment
- Java version: 21
- Build tool: Maven 3.9
- OS: macOS
Additional Context
N/A
Checklist
- I have searched the existing issues and this is not a duplicate.
- I have provided sufficient information for maintainers to reproduce the issue.
- Dominant language
- Java
- Stars
- 868
- Forks
- 560
- Avg merge
- 7m
- Merged PRs (30d)
- 2
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing 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.
More from swagger-api/swagger-parser
-
InlineModelResolver.uniqueName throws StringIndexOutOfBoundsException for titles starting with a separator (camelCaseFlattenNaming)Possibly taken @arimu1 claimed this 36 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
swagger-api/swagger-parser#2386 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
swagger-api/swagger-parser#2168 ·
-
ResolveFully fails on internal references when the initial spec is read from a file URLPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
swagger-api/swagger-parser#1922 · 2 comments · 1 reaction ·
-
[Bug]: `ResolverFully` does not process OAS 3.1 combinators and skips nested OAS 3.1 schema-valued keywordsPossibly taken A pull request linked to this issue is open or already merged. OpenBug
Difficulty 4/5 3-5 days Newbie friendliness 25/100
swagger-api/swagger-parser#2403 ·
-
[Bug]: Regression: resolveFully fails when components key does not match external file basenamePossibly taken A pull request linked to this issue is open or already merged. OpenBug
Difficulty 4/5 3-5 days Newbie friendliness 58/100
swagger-api/swagger-parser#2399 · 3 comments ·
All issues in swagger-api/swagger-parser
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
[Bug] The shared instance selector's placeholder and no-match text ignore the display languagePossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
apache/rocketmq-dashboard#5561 ·
Maintainers usually reply within 3 days
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
HMCL-dev/HMCL#6934 · 1 comment ·
Maintainers usually reply within 1 day
-
test(setup): GitHub configuration tests fail when the temp path is long enough for YAML foldingOpenbug good first issue help wanted priority medium size S
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
martin-francois/symphony-trello#776 · 1 comment ·
Maintainers usually reply within 1 day
-
Console.printHexOpengood first issue kernel
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
JackFurton/who-would-build-a-kernel-in-java#33 · 2 comments ·
Maintainers usually reply within 1 day