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

Attribute "nullable" from OpenAPI 3.0 does not work #25

Closed
simplesmiler opened this issue Feb 9, 2022 · 3 comments
Closed

Attribute "nullable" from OpenAPI 3.0 does not work #25

simplesmiler opened this issue Feb 9, 2022 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@simplesmiler
Copy link
Owner

simplesmiler commented Feb 9, 2022

Current state:

  • JSONSchema, even from ye olden days, always had a proper null type.
  • OpenAPI 3.0 dialect of JSONSchema forbids the use of null type and introduces nullable attribute instead.
  • OpenAPI 3.1 dialect aligns with JSONSchema more closely, deprecating the nullable attribute, and bringing back the null type.
  • Library used by Taxios to convert JSONSchema to TypeScript knows nothing about the dialect and happily ignores nullable attribute. Thus, Taxios generates wrong TypeScript for faithful OpenAPI 3.0 documents.
  • This could be mitigated by using hybrid documents, which are declared as OpenAPI 3.0 but actually use standard JSONSchema instead of the dialect. Although such hybrid documents do not pass validation, and have issues with the authoring tools (e.g. Stoplight reads hybrid documents properly, but converts edited sections back to the dialect).
  • OpenAPI 3.1 is still quite new, and is not supported yet in many places, so Taxios users may be forced to stick with OpenAPI 3.0.

The issue can be fixed by doing yet another pre-pass on the schema before feeding it to TS generator, to convert every nullable attribute into proper JSONSchema null type.

@simplesmiler simplesmiler added the bug Something isn't working label Feb 9, 2022
@simplesmiler simplesmiler mentioned this issue Jan 5, 2023
2 tasks
@simplesmiler
Copy link
Owner Author

Waiting on swagger2openapi (Mermade/oas-kit#529).

Or for a different package that can convert * -> 3.1.

@JaredCE
Copy link

JaredCE commented Feb 20, 2023

Hey hey, wonder if this library would help you: https://github.com/openapi-contrib/openapi-schema-to-json-schema it converts openAPI schemas to JSON Schema draft 04

@simplesmiler simplesmiler self-assigned this Nov 14, 2023
@simplesmiler
Copy link
Owner Author

Hey hey, wonder if this library would help you: https://github.com/openapi-contrib/openapi-schema-to-json-schema it converts openAPI schemas to JSON Schema draft 04

Committed in 0.3.0-alpha.1, will be included in 0.3.0 release. Kudos!

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