Skip to content

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

Open
@BillyBobFry

Description

@BillyBobFry

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!

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingopenapi-tsRelevant to the openapi-typescript library

Type

No type

Projects

Status

No status

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions