Skip to content
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

Null type is ignored when generating object types #634

Closed
lsdch opened this issue May 27, 2024 · 4 comments
Closed

Null type is ignored when generating object types #634

lsdch opened this issue May 27, 2024 · 4 comments
Labels
bug 🔥 Something isn't working info needed ❓ Further information is required

Comments

@lsdch
Copy link
Contributor

lsdch commented May 27, 2024

Description

When generating types from schemas having "type": ["object", "null"], the null part is not accounted for: I expected that a union type <object type> | null would be generated, as is the case for scalar types

OpenAPI specification (optional)

{
  "components" : {
    "schemas": {
        "SomeObjectType": {
           "properties": {
             "someProp": { "type" : "string" },
             "someNullableProp": { "type" : ["string" , "null"]}, // Correctly generated as `string | null` ts type
           },
          "type": ["object", "null"] // ignored
        }
      }
  }
}

Configuration

openapi-ts -i openapi.json -o src/api

// openapi-ts.config.ts
export default defineConfig({
  input: "./openapi.json",
  output: "src/api",
  client: "fetch",
  format: "prettier",
  types: {
    dates: true,
    name: "PascalCase",
  }
})

System information (optional)

pnpm v9.1.2
node v20.11.0

@lsdch lsdch added the bug 🔥 Something isn't working label May 27, 2024
@mrlubos
Copy link
Contributor

mrlubos commented May 27, 2024

Hey @lsdch, is this an OpenAPI 2.0 spec? Why isn't SomeObjectType in #/components/schemas?

@mrlubos mrlubos added the info needed ❓ Further information is required label May 27, 2024
@lsdch
Copy link
Contributor Author

lsdch commented May 27, 2024

Sorry, I messed up the example, schemas was supposed to be here. Edited the issue to fix this. The actual spec I'm using is OpenAPI 3.1.0

@mrlubos
Copy link
Contributor

mrlubos commented May 28, 2024

Would you be able to create a reproducible example? I had a look at this yesterday and we have a type with array containing object and null in tests and it generates the expected result, so I wasn't able to reproduce

@lsdch
Copy link
Contributor Author

lsdch commented May 28, 2024

I just realized the issue was I am not using the latest version of openapi-ts, still on v0.42. Upgrading to v0.46 makes it all work as expected. Sorry, I'm closing this, apologies for wasting your time!

@lsdch lsdch closed this as completed May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working info needed ❓ Further information is required
Projects
None yet
Development

No branches or pull requests

2 participants