Skip to content

PathParameters are not generated properly when parameter is declared in the component #510

Open
@yidongw

Description

@yidongw

example yaml:

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
paths:
  /pets/{id}:
    get:
      description: Returns a user based on a single ID, if the user does not have access to the pet
      operationId: find pet by id
      parameters:
        - $ref: '#/components/parameters/PetId'
      responses:
        '200':
          description: OK
    delete:
      description: deletes a single pet based on the ID supplied
      operationId: deletePet
      parameters:
        - $ref: '#/components/parameters/PetId'
      responses:
        '200':
          description: OK
components:
  parameters:
    PetId:
      schema:
        type: integer
        format: int64
      in: path
      name: id
      description: Pet ID
      required: true

generated types:

declare namespace Components {
    namespace Parameters {
        export type PetId = number; // int64
    }
    export interface PathParameters {
        PetId?: Parameters.PetId /* int64 */;
    }
}
declare namespace Paths {
    namespace DeletePet {
        namespace Parameters {
            export type $0 = Components.Parameters.PetId /* int64 */;
        }
        namespace Responses {
            export interface $200 {
            }
        }
    }
    namespace FindPetById {
        namespace Parameters {
            export type $0 = Components.Parameters.PetId /* int64 */;
        }
        namespace Responses {
            export interface $200 {
            }
        }
    }
}

VS

openapi: "3.0.0"
info:
  version: 1.0.0
  title: Swagger Petstore
  description: A sample API that uses a petstore as an example to demonstrate features in the OpenAPI 3.0 specification
paths:
  /pets/{id}:
    get:
      description: Returns a user based on a single ID, if the user does not have access to the pet
      operationId: find pet by id
      parameters:
        - in: path
          schema:
            type: integer
            format: int64
          name: id
          description: Pet ID
          required: true
      responses:
        '200':
          description: OK
    delete:
      description: deletes a single pet based on the ID supplied
      operationId: deletePet
      parameters:
        - in: path
          schema:
            type: integer
            format: int64
          name: id
          description: Pet ID
          required: true
      responses:
        '200':
          description: OK

and

declare namespace Paths {
    namespace DeletePet {
        namespace Parameters {
            export type Id = number; // int64
        }
        export interface PathParameters {
            id: Parameters.Id /* int64 */;
        }
        namespace Responses {
            export interface $200 {
            }
        }
    }
    namespace FindPetById {
        namespace Parameters {
            export type Id = number; // int64
        }
        export interface PathParameters {
            id: Parameters.Id /* int64 */;
        }
        namespace Responses {
            export interface $200 {
            }
        }
    }
}

The top one's generated PathParameters are correct, but the bottom is not.

DeletePet and FindPetById should have PathParameters interface instead of Parameters

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions