Skip to content

required fields that are nullable generate as NonNullable in typescript #1639

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

Closed
ohnoah opened this issue Jan 29, 2025 · 3 comments
Closed
Labels
bug 🔥 Something isn't working

Comments

@ohnoah
Copy link

ohnoah commented Jan 29, 2025

Description

"type": "array",
              "items": {
                  "type": "object",
                  "properties": {
                      "first_name": {
                          "type": "string"
                      },
                      "profile_picture_url": {
                          "type": "string",
                          "nullable": True,
                      },
                  },
                  "required": [
                      "unique_id",
                      "first_name",
                      "last_name",
                      "profile_picture_url",
                  ],
              }

In this example OpenAPI spec, I get a generated type where profile_picture_url is of type string, not string | undefined or string | null.

Reproducible example or configuration

"type": "array",
              "items": {
                  "type": "object",
                  "properties": {
                      "first_name": {
                          "type": "string"
                      },
                      "profile_picture_url": {
                          "type": "string",
                          "nullable": True,
                      },
                  },
                  "required": [
                      "unique_id",
                      "first_name",
                      "last_name",
                      "profile_picture_url",
                  ],
              }
                `"npx",
                "@hey-api/openapi-ts",
                "-i",
                "generated/openapi.json",
                "-o",
                output_dir,
                "-c",
                "@hey-api/client-fetch",`

OpenAPI specification (optional)

"type": "array",
              "items": {
                  "type": "object",
                  "properties": {
                      "first_name": {
                          "type": "string"
                      },
                      "profile_picture_url": {
                          "type": "string",
                          "nullable": True,
                      },
                  },
                  "required": [
                      "unique_id",
                      "first_name",
                      "last_name",
                      "profile_picture_url",
                  ],
              }

System information (optional)

Latest versions of everything as of Jan 29

@ohnoah ohnoah added the bug 🔥 Something isn't working label Jan 29, 2025
@mrlubos
Copy link
Member

mrlubos commented Jan 29, 2025

Hi @ohnoah, which OpenAPI version is your spec?

@ohnoah
Copy link
Author

ohnoah commented Jan 29, 2025

3.1.0 @mrlubos

@mrlubos
Copy link
Member

mrlubos commented Jan 29, 2025

@ohnoah yeah that's not a valid specification, see OAI/OpenAPI-Specification#2244

@mrlubos mrlubos closed this as not planned Won't fix, can't repro, duplicate, stale Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants