You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm surprised by this because the "required" array is part of the offical JSON schema spec, whereas the default value is (to the best of my knowledge) not. The closest thing I could find to documentation was here, where the docs say:
Unless stated otherwise, the property definitions follow those of JSON Schema and do not add any additional semantics.
So I would expect the ? types to be determined by "required" fields only.
Checklist
My OpenAPI schema passes the Redocly validator (npx @redocly/cli@latest lint)
I’m willing to open a PR (see CONTRIBUTING.md) (I may be open to this, but don't want to commit to it as I'm not familiar with this project and unsure how tough it would be)
The text was updated successfully, but these errors were encountered:
Ah! Yeah setting defaultNonNullable to false does indeed fix this. For what it's worth I find this default behavior a bit surprising... but the option is clear and well documented, so works for me!
Thanks to you and all the other contributors for all your hard work on this project.
Description
Generated types don't allow
undefined
inputs on fields with default values, even if they're not part of the"required"
fields array.openapi-typescript
7.0.2
v20.12.2
macOS 14.5
Reproduction
Create a
package.json
like:Add a
docs-json
file with:and a
generate-types.ts
file with:Run
yarn start
in one terminal window andyarn generate
in another. This creates anopenapi-output.ts
file.Expected result
I expect a schema which looks like this:
But this is what the script outputs:
I'm surprised by this because the
"required"
array is part of the offical JSON schema spec, whereas thedefault
value is (to the best of my knowledge) not. The closest thing I could find to documentation was here, where the docs say:So I would expect the
?
types to be determined by"required"
fields only.Checklist
npx @redocly/cli@latest lint
)The text was updated successfully, but these errors were encountered: