[BUG][JAVA][spring] Local components shadow ones from other files with the same name
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? -
Have you searched for related issues/PRs? -
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
If a component defined in the same file as an operation has the same name as one that is used on that operation via a $ref
to another file, the local one is used instead of the one matching the file qualifier.
(Of course, this kind of naming would not be great even if code generation worked; the matching names have probably been introduced inadvertently to our codebase.)
openapi-generator version
This issue was encountered on openapi-generator versions:
- 6.1.1-20220917.160402-11,
- 6.4.0 as well as
- 6.5.0-20230319.123008-55.
It is a regression; it was not present on
- 5.3.0 and
- 6.1.1-20220916.054356-10.
OpenAPI declaration file content or url
Root catalog.yaml
:
openapi: 3.0.2
info: { title: Catalog, version: "1.0" }
components:
parameters:
manufacturerIdParam:
in: path
required: true
name: manufacturerId
schema: { type: string }
paths:
/products:
get:
operationId: getProducts
parameters:
- $ref: "queryParameters.yaml#/components/parameters/manufacturerIdParam"
responses:
"200": { description: Ok }
Auxiliary queryParameters.yaml
:
openapi: 3.0.2
info: { title: Shared query parameters, version: "1.0" }
components:
parameters:
manufacturerIdParam:
in: query
required: false
name: manufacturerId
schema: { type: string }
paths: {}
Generation Details
java -jar openapi-generator-cli.jar generate -i catalog.yaml -g spring
Steps to reproduce
Check the generated src/main/java/org/openapitools/api/ProductsApi.java
file.
Expected: the String manufacturerId
parameter of ProductsApi::getProducts
should be annotated @Parameter(name = "manufacturerId", description = "") @Valid @RequestParam(value = "manufacturerId", required = false)
(i.e. queryParameters.yaml#/components/parameters/manufacturerIdParam
).
Actual result: It is annotated @Parameter(name = "manufacturerId", description = "", required = true) @PathVariable("manufacturerId")
(i.e. catalog.yaml#/components/parameters/manufacturerIdParam
) instead.
Related issues/PRs
My guess is this was introduced by #13133
Suggest a fix
?