Default values of 0 are not generated
If a default value of 0 is specified then it is not generated. I traced it to this line but I do not yet know .hbs if someone wants to take a stab at correcting this.
A workaround is provided below.
Lines I believe with logic error: https://github.com/ferdikoomen/openapi-typescript-codegen/blob/a0807fa78d7c19ae90985e63c32caaf1e04f2581/src/templates/partials/parameters.hbs#L5
and
https://github.com/ferdikoomen/openapi-typescript-codegen/blob/a0807fa78d7c19ae90985e63c32caaf1e04f2581/src/templates/partials/parameters.hbs#L25
if !default then there is no default value. This is incorrect as 0 should be able to be a default value. I could argue that null could be a default value as well but beyond the scope here I think.
example:
limit:
name: limit
in: query
required: false
schema:
type: integer
format: int32
default: 25
page:
name: page
in: query
required: false
schema:
type: integer
format: int32
default: 0
- Generates *
public getMyStuff({
page,
limit = 25,
}: {
...
}
'limit' would be generated with a default value of 25 but 'page' would not have a default value.
the workaround would look like this
limit:
name: limit
in: query
required: false
schema:
type: integer
format: int32
default: '25'
page:
name: page
in: query
required: false
schema:
type: integer
format: int32
default: '0'
- Generates *
public getMyStuff({
page = 0,
limit = 25,
}: {
...
}
This is fixed in our fork of the repository @hey-api/openapi-ts
This is fixed in our fork of the repository @hey-api/openapi-ts
Funny enough I have a PR open moving to your package, https://github.com/7nohe/openapi-react-query-codegen/pull/50