Skip to content

Optional fields incorrect on object types, expected null fields #2576

@cdaringe

Description

@cdaringe

openapi-typescript version

7.0.2

Node.js version

22

OS + version

15.8

Description

Problem

OpenAPI defines types observed over the wire, but the generated optional types do not match. Specifically, optional types are defined as optional in typescript, versus null

Reproduction

  1. Define a schema: Demo: { type: "object", properties: { foo: { ... }, bar: { ... } }
  2. Generate typescript:
    3. actual: { Demo: { foo?: number, bar?: number }

Expected result

{ Demo: { foo: number | null, bar: number | null }

I expected null

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions