Skip to content

[openapi-typescript] Incorrect type generated for nullable objects #1821

Closed
@JohanAlteruna

Description

@JohanAlteruna

Thanks everyone for the new updates of openapi-typescript! I have found an issue which I believe might be related to the new major version (7).

Description

In version 7.3.0 and OpenAPI version 3.0.3, combining type: object and nullable: true does not produce the expected union type.

Reproduction

Run the CLI with default options on the following schema:

openapi: "3.0.3"
info: { title: "Test", version: "0" }
servers:
  - url: "example.com"
components:
  schemas:
    obj1:
      type: object
      nullable: true
paths: {}

Expected result

schemas: {
  obj1: Record<string, never> | null;
};

Actual Result

schemas: {
  obj1: Record<string, never>;
};

Checklist

The example given above works fine with type: string and nullable: true. It also works in openapi-typescript version 6.7.6.

Metadata

Metadata

Assignees

Labels

PRs welcomePRs are welcome to solve this issue!bugSomething isn't workinggood first issueStraightforward problem, solvable for first-time contributors without deep knowledge of the projectopenapi-tsRelevant to the openapi-typescript library

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions