Skip to content

Default values of 0 are not generated #1558

Open
@seriouslag

Description

@seriouslag

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,
    }: {
    ...
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions