Skip to content

Default values of 0 are not generated #1558

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

Open
seriouslag opened this issue May 23, 2023 · 2 comments
Open

Default values of 0 are not generated #1558

seriouslag opened this issue May 23, 2023 · 2 comments

Comments

@seriouslag
Copy link

seriouslag commented May 23, 2023

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:

{{{name}}}{{#if default}} = {{{default}}}{{/if}},

and

{{{name}}}{{>isRequired}}: {{>type}}{{#if default}} = {{{default}}}{{/if}},

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,
    }: {
    ...
    }
@seriouslag seriouslag changed the title Default values of 0 do not get generated Default values of 0 are not generated May 23, 2023
@jordanshatford
Copy link

This is fixed in our fork of the repository @hey-api/openapi-ts

@seriouslag
Copy link
Author

seriouslag commented Mar 31, 2024

This is fixed in our fork of the repository @hey-api/openapi-ts

Funny enough I have a PR open moving to your package, 7nohe/openapi-react-query-codegen#50

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

No branches or pull requests

2 participants