Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
yidongw opened this issue Jul 21, 2021 · 5 comments
Labels

Comments

@yidongw
Copy link

yidongw commented Jul 21, 2021

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

@horiuchi
Copy link
Owner

I think the problem is that the PathParameters are not generated in DeletePet and FindPetById in the example above.

In the example below, it is correct that both Parameters and PathParameters are generated.
The Parameters defines properties that are included in all parameters such as query, path, body, etc. Among them, The PathParameters extracts only path properties.

@yidongw
Copy link
Author

yidongw commented Jul 21, 2021

That's correct. Any plan to fix it?

@horiuchi
Copy link
Owner

Yes, I will fix it.

@horiuchi horiuchi added the bug label Jul 21, 2021
@yidongw
Copy link
Author

yidongw commented Jul 21, 2021

Thank you

@tkalliom
Copy link

tkalliom commented Oct 7, 2021

Note that this applies to parameters other than path ones as well. At least for query ones the same thing occurs: if a parameter definition is $referenced instead of being defined inline in the operation, the produced types do not include an object type having the parameter name as the key.

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
components:
  parameters:
    felineFilter:
      schema:
        type: boolean
      in: query
      name: catsOnly
      description: Limits retrieved pets to cats
      required: true
paths:
  /pets:
    get:
      description: Returns a listing of pets.
      parameters:
        - $ref: "#/components/parameters/felineFilter"
      responses:
        "200":
          description: Query was successful

produces

declare namespace Components {
    namespace Parameters {
        export type FelineFilter = boolean;
    }
    export interface QueryParameters {
        felineFilter?: Parameters.FelineFilter;
    }
}
declare namespace Paths {
    namespace Pets {
        namespace Get {
            namespace Parameters {
                export type $0 = Components.Parameters.FelineFilter;
            }
            namespace Responses {
                export interface $200 {
                }
            }
        }
    }
}

when { catsOnly: Parameters.FelineFilter } is desired.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants