[Bug]: content.examples $ref not resolved in request bodies or parameters
评估
调研方向
首先使用启用 resolve 和 resolveFully 的 ParseOptions,通过 OpenAPIParser.readContents 重现该问题,并使用所示的 request-body 和 parameter 示例。跟踪解析器如何处理 content 示例,并比较这两个位置;完成的标准是:解析后的 OpenAPI 结果中每个示例引用都被替换为被引用示例的数据,并且两个情况都有回归测试覆盖。
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Java
- 星标
- 870
- 派生
- 565
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
swagger-api/swagger-parser 的其他 Issue
-
InlineModelResolver.uniqueName throws StringIndexOutOfBoundsException for titles starting with a separator (camelCaseFlattenNaming)可能已有人在做 @arimu1 于 51 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
swagger-api/swagger-parser#2386 ·
-
难度 2/5 1-3 小时 新手友好度 72/100
swagger-api/swagger-parser#2168 ·
-
ResolveFully fails on internal references when the initial spec is read from a file URL可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 65/100
swagger-api/swagger-parser#1922 · 2 条评论 · 1 个 reaction ·
-
[Bug]: Discriminator mapping of a oneOf nested in array items gets a null key and is no longer updated after external ref resolution (regression since 2.1.36)可能已有人在做 @wyhasany 于 6 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 25/100
swagger-api/swagger-parser#2406 · 1 条评论 ·
-
[Question]: Guidance on jackson-coreutils vulnerabilities in legacy Swagger compatibility dependency未关闭Question
难度 5/5 一周以上 新手友好度 8/100
swagger-api/swagger-parser#2405 ·
查看 swagger-api/swagger-parser 的全部 Issue
相似的 Issue
-
[Bug] dubbo.protocol.triple.max-message-size is only read from OS environment variables可能已有人在做 @CCCLL 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 64/100
hierynomus/sshj#1070 ·
-
难度 2/5 1-3 小时 新手友好度 84/100
intellij-elixir/intellij-elixir#4492 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 77/100
-
难度 2/5 1-3 小时 新手友好度 76/100
quarkiverse/quarkus-openapi-generator#1796 · 1 条评论 ·