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

Nullable properties have additional | null declaration in OpenAPI 3.1 #1817

Open
RinseV opened this issue Jan 13, 2025 · 0 comments · May be fixed by #1818
Open

Nullable properties have additional | null declaration in OpenAPI 3.1 #1817

RinseV opened this issue Jan 13, 2025 · 0 comments · May be fixed by #1818
Labels
bug Something isn't working
Milestone

Comments

@RinseV
Copy link
Contributor

RinseV commented Jan 13, 2025

What are the steps to reproduce this issue?

  1. Generate the type for a nullable property from an OpenAPI 3.1 schema:
openapi: 3.1.0
info:
  title: Nullables
  description: 'OpenAPI 3.1 examples'
  version: 1.0.0
paths: {}
components:
  schemas:
    Test:
      properties:
        example_nullable:
          type:
            - string
            - 'null'
      title: Test
      type: object

What happens?

The type is generated as follows:

export interface Test {
  example_nullable?: TestExampleNullable;
}

export type TestExampleNullable = string | null | null;

What were you expecting to happen?

Type type is generated as follows:

export type TestExampleNullable = string | null;

Any logs, error output, etc?

N/A

Any other comments?

This is due to this PR that now also checks whether a null type is included in the array of types. However, with the OpenAPI 3.1 specification, nullable properties are declared by adding the null type to the type array in the property, rather than specifying nullable: true. As such, the nullable variable is now true for the property where it was false before. I'm not entirely sure where the second | null is coming from however.

What versions are you using?

 System:
    OS: macOS 15.2
    CPU: (8) arm64 Apple M3
    Memory: 136.42 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    @tanstack/react-query: ^5.63.0 => 5.63.0 
    @tanstack/vue-query: ^4.22.0 => 4.22.0 
    axios: ^0.26.1 => 0.26.1 
    msw: ^2.0.2 => 2.0.2 
    react: ^18.3.1 => 18.3.1 
    swr: ^2.2.4 => 2.2.4 
    vue: ^3.3.4 => 3.3.4 
    zod: ^3.23.8 => 3.23.8

I'm using Orval 7.4.1, but this issue was introduced in 7.4.0.

@AllieJonsson AllieJonsson linked a pull request Jan 13, 2025 that will close this issue
@melloware melloware added this to the 7.4.2 milestone Jan 13, 2025
@melloware melloware added the bug Something isn't working label Jan 13, 2025
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