dtsgenerator
dtsgenerator copied to clipboard
PathParameters are not generated properly when parameter is declared in the component
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
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.
That's correct. Any plan to fix it?
Yes, I will fix it.
Thank you
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 $ref
erenced 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.