swagger-api / swagger-api/swagger-parser
OpenAPIParser is resolving the wrong schema for an operation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
See the following repo for a minimal reproduction of this issue:
- https://github.com/simondean/swagger-request-validator-filename-issue
- https://github.com/simondean/swagger-request-validator-filename-issue/blob/main/src/test/java/IssueDemoTest.java
- https://github.com/simondean/swagger-request-validator-filename-issue/blob/main/example-openapi.yaml
Here's an example OpenAPI spec that demonstrates the issue:
https://github.com/simondean/swagger-request-validator-filename-issue/blob/main/example-openapi.yaml
openapi: 3.0.1
info:
title: Example OpenAPI spec
version: 0.0.1
paths:
'/example':
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/ExamplePost'
responses:
204:
description: No content
components:
schemas:
# Renaming this key from `Example` to `ExampleGet` stops the issue from occurring
# Removing this key stops the issue from occurring
Example:
$ref: example.get.yaml
ExamplePost:
$ref: example.post.yaml
The comments in the code snippet show how the issue only happens when the unused schema is called Example. Rename it to ExampleGet or delete it, and the issue stops. The word Example is unimportant, other than it seems to need to be similar to the other schema that is used. Both schemes could be renamed to Anything and AnythingPost and you would still get the issue
Expected Behaviour
The following assertion should pass:
assertEquals("POST Example", api.getPaths()
.get("/example")
.getPost()
.getRequestBody()
.getContent()
.get("application/json")
.getSchema()
.getTitle());
Actual Behaviour
Swagger Parser loads the wrong request body schema for the POST operation. It's request body description is set to GET Example when it should be POST Example:
expected: <POST Example> but was: <GET Example>
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 linked IssueDemoTest.java and example-openapi.yaml to reproduce the incorrect POST schema resolution. Trace how OpenAPIParser resolves the referenced schemas, then confirm the assertion expects "POST Example" rather than "GET Example" when the unused Example schema is present.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100