OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] Cross-path references are not properly considered for Parameters
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
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.
openapi-generator version
Version 7.7.0
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.
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 io.swagger.v3.parser.processors.ParameterProcessor and reproduce the issue using the referenced openapi.yaml, OpenAPIParser, and ParseOptions configuration. Inspect why the DELETE operation's PathItem parameters omit the cross-path reference, then verify that the resolved Parameters list contains the referenced parameter without regressing component parameter references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100