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

Cannot create constant for false #1647

Closed
RinseV opened this issue Sep 30, 2024 · 1 comment · Fixed by #1653
Closed

Cannot create constant for false #1647

RinseV opened this issue Sep 30, 2024 · 1 comment · Fixed by #1653
Assignees
Labels
bug Something isn't working
Milestone

Comments

@RinseV
Copy link
Contributor

RinseV commented Sep 30, 2024

What are the steps to reproduce this issue?

  1. Create an OpenAPI 3.1 schema with const: false in a property
  2. Generate Orval code

Example schema:

openapi: 3.1.0
info:
  version: 1.0.0
  title: Example
  license:
    name: MIT
    identifier: MIT
servers:
  - url: http://api.example.xyz/v1
paths:
  /somePath:
    get:
      operationId: getSomePath
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema: {}
components:
  schemas:
    BooleanConstFalse:
      type: object
      required:
        - value
      properties:
        value:
          type: boolean
          const: false

What happens?

The generated code will produce the field with type: boolean instead of type: false.

Generated code from above sample:

export type BooleanConstFalse = {
  value: boolean;
};

What were you expecting to happen?

The type should be generated with type: false.

Expected code from above sample:

export type BooleanConstFalse = {
  value: false;
};

Any other comments?

Problem is here, if const is false, then this if statement will evaluate to false and thus not set the value. We just need to change the check to if (itemWithConst.const !== undefined). The same probably happens for integers with const: 0.

What versions are you using?

System:
    OS: macOS 15.0
    CPU: (8) arm64 Apple M3
    Memory: 86.31 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    @tanstack/react-query: ^5.56.2 => 5.56.2
    orval: 7.1.1 => 7.1.1
    react: ^18.3.1 => 18.3.1
@melloware
Copy link
Collaborator

PR is welcome @RinseV !

@melloware melloware added the bug Something isn't working label Sep 30, 2024
@melloware melloware added this to the 7.2.0 milestone Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants