Unable to parse Parameter $ref with cross-path references
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
Research direction
Start with io.swagger.v3.parser.processors.ParameterProcessor and reproduce the issue using the supplied OpenAPI YAML and Java parsing snippet with resolve and flatten enabled. Inspect how the $ref to another path is handled, then verify that the DELETE operation's Parameters list contains the referenced parameter rather than being empty.
Written by the indexing model from the issue text.
Description
Description
When parsing the Parameters section from an operation, cross-path reference parameters are ignored. This is not consistent with other elements which are properly included in the final OpenAPI object.
swagger-parser version
Version 2.1.22
OpenAPI declaration file content or url
"/attribute/{namespace}":
delete:
description: |
Delete an attribute namespace and all attributes below.
This operation is the same as the one defined with [DELETE /attribute/{namespace}/_meta](#/Attributes/delete_attribute__namespace___meta).
parameters:
- $ref: "#/paths/~1attribute~1%7Bnamespace%7D/get/parameters/0"
Full spec file is here: https://github.com/APIs-guru/openapi-directory/blob/main/APIs/opensuse.org/obs/2.10.50/openapi.yaml
Generation Details
Use the following code:
OpenAPIParser openAPIV3Parser = new OpenAPIParser();
ParseOptions options = new ParseOptions();
options.setResolve(true);
options.setFlatten(true);
OpenAPI openAPI = openAPIV3Parser.readContents(Files.readString(Paths.get("openapi.yaml")), null, options).getOpenAPI();
PathItem pathItem = openAPI.getPaths().get("/attribute/{namespace}");
You can then check the Parameters list of the DELETE operation is empty instead of having one parameter.
Steps to reproduce
See above
Suggest a fix
The issue seems to be this code from the io.swagger.v3.parser.processors.ParameterProcessor class:
if (parameter.get$ref().startsWith("#") && parameter.get$ref().indexOf("#/components/parameters") <= -1) {
//TODO: Not possible to add warning during resolve doesn't accept result as an input. Hence commented below line.
//result.warning(location, "The parameter should use Reference Object to link to parameters that are defined at the OpenAPI Object's components/parameters.");
continue;
}
Which only includes refs that are from the components section. One possible fix is that it should just include parameters that are referencing other paths 'as is' rather than trying to solve it.
- Dominant language
- Java
- Stars
- 867
- Forks
- 560
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 7
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.
More from swagger-api/swagger-parser
-
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 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
swagger-api/swagger-parser#1922 · 2 comments · 1 reaction ·
-
[Bug]: Regression: resolveFully fails when components key does not match external file basename OpenBug
Difficulty 4/5 3-5 days Newbie friendliness 58/100
swagger-api/swagger-parser#2399 · 3 comments ·
-
Bug
Difficulty 4/5 3-5 days Newbie friendliness 48/100
swagger-api/swagger-parser#2395 ·
All issues in swagger-api/swagger-parser
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
infinispan/infinispan#18150 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
opensearch-project/k-NN#3597 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100