Skip to content

Referenced nullable object types are not generated as possibly null #2030

Open
hey-api/openapi-ts
#33
@raphael-verdier

Description

@raphael-verdier

Describe the bug

Referenced nullable objects are not correctly generated as either an object or null.

Considering those two schemas that should result in the same typing:

NullableObject:
  type: object
  nullable: true
  description: An object that can be null.
  properties:
    testProperty:
      type: string

CoreObjectBug:
  type: object
  properties:
    referenceA:
      $ref: '#/NullableObject'


CoreObjectWorkaround:
  type: object
  properties:
    referenceA:
      type: object
      nullable: true
      description: An object that can be null.
      properties:
        testProperty:
          type: string

The generated type for NullableObject is the following, which is wrong:

export type NullableObject = {
    testProperty?: string;
};

The generated type for CoreObjectWorkaround is the following, which is correct:

export type CoreObjectWorkaround = {
    /**
     * An object that can be null.
     */
    referenceA?: {
        testProperty?: string;
    } | null;
};

This bug is isolated to referenced object types as I use referenced atomic nullable types that don't have this bug.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions