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": true is not respected for empty objects. #1940

Open
1 of 2 tasks
BillyBobFry opened this issue Oct 4, 2024 · 0 comments
Open
1 of 2 tasks

"nullable": true is not respected for empty objects. #1940

BillyBobFry opened this issue Oct 4, 2024 · 0 comments
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@BillyBobFry
Copy link

Description

When a JSON API spec has "nullable": true for an empty object, the resulting TS type does not include null.

Reproduction

Copy the following into a JSON API spec:

    "NullableEmptyObject": {
        "nullable": true,
        "properties": {},
        "title": "NullableEmptyObject",
        "type": "object"
      },
      "NullableObject": {
        "nullable": true,
        "properties": {
          "name": {
            "type": "string"
          }
        },
        "title": "NullableObject",
        "type": "object"
      },
      "NullableString": {
        "nullable": true,
        "title": "NullableString",
        "type": "string"
      },

The generated TS types are

        /** NullableEmptyObject */
        NullableEmptyObject: Record<string, never>;
        /** NullableObject */
        NullableObject: {
            name?: string;
        } | null;
        /** NullableString */
        NullableString: string | null;

Expected result

NullableEmptyObject should be typed as Record<string, never> | null.

Checklist

I could open a PR in a few weeks, but I'm not able to do so right now!

@BillyBobFry BillyBobFry added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Oct 4, 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 openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

No branches or pull requests

1 participant