Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #14992
Closed
Open
Issue created Mar 19, 2023 by tkalliom@tkalliom5 of 6 checklist items completed5/6 checklist items

[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

?

Assignee
Assign to
Time tracking