-
-
Notifications
You must be signed in to change notification settings - Fork 493
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
[openapi-typescript] Incorrect type generated for nullable objects #1821
Comments
As a side note, I also think that |
You’re right I don’t think we’re testing for this. This should be an easy fix and we’d welcome a PR on it from anyone 🙂
We’ve had this suggestion before. But this library’s whole purpose is to help you catch where your runtime code deviates from your declared schema. As documented, if you declare an empty object in your schema, TS is going to flag this for you as a potential bug. Perhaps you’re autogenerating these schemas and there was a bug! It’s being overly strict for your benefit, to alert you of where your schema is incomplete, which is also at the boundary of where TS can’t typecheck for you anymore. Appreciate the suggestion, and we’ll always look for newer and better ways to do things. But in situations like this, we’ll always err on the side of being too strict rather than too loose. |
I found a similar issue: the nullable is not taken into account on a Reproduction openapi: "3.0.3"
info: { title: "Test", version: "0" }
servers:
- url: "example.com"
components:
schemas:
obj1Ref:
properties:
id:
type: string
obj1:
type: object
nullable: true
$ref: '#/components/schemas/obj1Ref'
paths: {} Expected result obj1: components["schemas"]["obj1Ref"] | null; Actual Result obj1: components["schemas"]["obj1Ref"]; Maybe I, or one of my colleagues, can try to open a PR for both cases |
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 version3.0.3
, combiningtype: object
andnullable: true
does not produce the expected union type.Reproduction
Run the CLI with default options on the following schema:
Expected result
Actual Result
Checklist
npx @redocly/cli@latest lint
)The example given above works fine with
type: string
andnullable: true
. It also works inopenapi-typescript
version6.7.6
.The text was updated successfully, but these errors were encountered: