Skip to content

[BUG] [DefaultCodeGen] Operation parameters list wrongly filled when parameter defined with $ref is used #20239

@JPPortier

Description

@JPPortier

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator: https://editor-next.swagger.io/
  • 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

Algorithm to compute a parameterId from parameter definition conduct to a collision when parameter is defined by $ref.
It use only name and in to create a String.
When both:

  • a path parameter:
    • is defined at path level
    • is referenced by $ref
  • a query parameter
    • is defined at request level
    • is referenced by $ref

Both of them are generating same Id (null:null), then the path parameter is not added to to parameters list:
(https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L1621)

    private static String generateParameterId(Parameter parameter) {
        return parameter.getName() + ":" + parameter.getIn();
    }
openapi-generator version

7.10 and main

OpenAPI declaration file content or url
openapi: 3.1.0
info:
  title: API Overview 
  version: "v1"
  description: description

tags:
  - name: aTag

paths:
  "/path/{path_parameter}":
    parameters:
      - $ref: "#/components/parameters/path_parameter"
    get:
      tags:
      - aTag    
      operationId: get
      parameters:
      - $ref: "#/components/parameters/query_parameter"  
      responses:
        "200":
          description: no body
components:
  parameters:
    path_parameter:
      name: path_parameter
      in: path
      required: true
      schema:
        type: string

    query_parameter:
      name: query_parameter
      in: query
      schema:
        type: integer
        minimum: 0
        default: 0

Generation Details

java -jar ./modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i ./foo.yaml -g java

Steps to reproduce

see generation details above

Related issues/PRs

#20240

Suggest a fix
    private static String generateParameterId(Parameter parameter) {
        return null == parameter.get$ref() ? parameter.getName() + ":" + parameter.getIn() : parameter.get$ref() ;
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions