swagger-api / swagger-api/swagger-parser
RequestBody and Response Examples with relativePath are not resolved
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
Description
We have OpenAPI 3.0.1 spec with examples on relative path, we want to generate a single API file while creating API spec artifact.
Our API Looks like as specified in OpenAPI spec
https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.1.md#media-type-object
as spec stats that examples could be a map of example/reference values
{
"application/json": {
"schema": {
"$ref": "#/components/schemas/Pet"
},
"examples": {
"cat" : {
"$ref": "./examples/pet/cat.json"
},
"dog": {
"$ref": "./examples/pet/dog.json"
},
"frog": {
"$ref": "./examples/pet/dog.json"
}
}
}
}
}
Source code to generate the single API
ParseOptions parseOptions = new ParseOptions();
parseOptions.setResolve(true); // not resolving relative path examples as expected, even with resolveFully
parseOptions.setValidateExternalRefs(true);
SwaggerParseResult result = new OpenAPIV3Parser().readLocation(inputSpec, null, parseOptions);
result.getMessages().forEach(System.out::println);
Debugging in Intellij shows that ResolverCache.java was able to load the example ref but your code not assigning this as value to your Example.java, hence we see a lot of
attribute ..xxx is unexpected
At the end generated API does not have those example values.
Could you please check if it is a bug or we are missing something in our understanding?
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
Reproduce the issue with the supplied OpenAPI 3.0.1 example and ParseOptions configuration, then inspect ResolverCache.java and Example.java where the relative example reference is loaded and represented. Done means the generated single API artifact contains the referenced example values without unexpected-attribute messages.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100