-
-
Notifications
You must be signed in to change notification settings - Fork 517
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
Nullable ignored if non-null default is present #2144
Comments
There is no
# Correct
type: integer
nullable: true
# Incorrect
type: null
# Incorrect as well
type:
- integer
- null See https://swagger.io/docs/specification/v3_0/data-models/data-types/ Edit: The idea behind this is to avoid having union lists and being able to differentiate them e.g. a Edit 2: To avoid confusion: There is no 'boolean' type neither. See https://www.json.org/json-en.html for further information. The values |
Maybe before posting snarky memes, you should read the documentation. As I specify in my issue, I'm using 3.1 which does have a null type. I also ran my spec through Redocly, which gave no validation issues.
https://swagger.io/specification/
https://datatracker.ietf.org/doc/html/draft-bhutton-json-schema-validation-00#section-6.1.1 |
Edit: Long explainationEdit: Imagine The relationship between OpenAPI and JSON Schema can be a source of some confusion. Here's a breakdown of why OpenAPI has its own schema definition, and how it relates to JSON Schema: Key Differences and Purposes:
Why OpenAPI Has Its Own Definition:
But there is hope: OpenAPI and JSON Schema Integration:
TLDRIn essence, OpenAPI is a higher-level specification that uses JSON Schema as a component for data modeling. They serve different but complementary purposes. |
Once again, you’re referencing 3.0. 3.1 introduces “null” as a valid type. If you want proof just run my spec through Redocly. Nice ChatGPT edit there. |
Where do you get this? The doc (which I wrote btw) is clearly saying that Note that there is no null type; instead, the nullable attribute is used as a modifier of the base type.
Thank you 😂 It's Google Gemini Advanced. My last words in this matterI hope everything is clear now. If you have any further questions, feel free to ask. I'm gonna allow you the dignity to reject your own PR, otherwise I'm gonna reject it anyway in 2 weeks. |
Nice try. I’ll wait for the last word from an actual maintainer 😂 |
😏But now for real: Yes I'm not the maintainer nor did I contribute a single char into the code. And afaik the maintainer of the repo here (openapi-typescript) are not affiliated to the maintainers of Swagger nor OpenAPI Schema? My strongest argument: But I guess you understand that a null type would allow to have union types in lists? e.g. How are you going to differ between them? Imo (I'm just engaging in a fantasy rn) OpenAPI should replace OpenAPI Schema not with JSON Schema, but use directly TypeScript itself as schema for an API, that would OP because what JSON Schema and OpenAPI Schema are doing (imo) is just replicating the features that TypeScript already offers. |
The description of how nulls are handled different between OpenAPI 3.0 and 3.1 is accurate. This does indeed appear to be a bug. 🐞 Handling
|
openapi-typescript version
7.6.1
Node.js version
23.7.0
OS + version
macOS 15.3
Description
Take the example property defined as "nullable" using OpenAPI 3.1 syntax.
Results in:
However, if you add a non-null default:
It eliminates the null type:
This is problematic because my API has properties that have non-null defaults, but null is still a valid value to return.
I also tried with
--default-non-nullable false
but the behavior is the same.This is very possibly the same issue as #2055, but using the 3.1 syntax.
Reproduction
Gives (in part):
Expected result
Required
npx @redocly/cli@latest lint
)Extra
The text was updated successfully, but these errors were encountered: