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

Unexpected error when property schemas are boolean #2198

Closed
2 tasks done
StefanTerdell opened this issue Mar 13, 2025 · 3 comments · Fixed by #2199
Closed
2 tasks done

Unexpected error when property schemas are boolean #2198

StefanTerdell opened this issue Mar 13, 2025 · 3 comments · Fixed by #2199
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library

Comments

@StefanTerdell
Copy link
Contributor

openapi-typescript version

7.6.1

Node.js version

20.5.1

OS + version

macOS 15.3.1

Description

If an object property is defined with a boolean schema transformation will fail. There is precedent in the codebase to handle these as unknown and never respectively (see additionalProperties).

Reproduction

See the test in the linked PR.

Expected result

See the test in the linked PR.

Required

  • My OpenAPI schema is valid and passes the Redocly validator (npx @redocly/cli@latest lint)

Extra

@StefanTerdell StefanTerdell added bug Something isn't working openapi-ts Relevant to the openapi-typescript library labels Mar 13, 2025
@StefanTerdell StefanTerdell mentioned this issue Mar 13, 2025
3 tasks
@drwpow
Copy link
Contributor

drwpow commented Mar 18, 2025

Thanks for the issue and PR. We’d be willing to accept it given there’s a precedent here. Is there a link to the specification where this is valid, either according to any OpenAPI 3.x version, or JSONSchema? This is the first time I’ve seen this syntax before

@StefanTerdell
Copy link
Contributor Author

StefanTerdell commented Mar 19, 2025

Sure! A boolean is always a valid JSON schema in versions later than draft 4 regardless of keyword. See the type keyword in either of these meta schemas:
https://json-schema.org/draft/2020-12/schema
https://json-schema.org/draft/2019-09/schema
https://json-schema.org/draft-07/schema
https://json-schema.org/draft-06/schema

Draft 4 (which OpenAPI <=3.0 was based on) only accepts them for specific keywords:
https://json-schema.org/draft-04/schema

It's my understanding that OpenAPI >=3.1 supports draft 2020 though.

Thanks!

@drwpow
Copy link
Contributor

drwpow commented Mar 19, 2025

Thanks for the reference! That works for me. This library doesn’t require a specific JSONSchema version; as long as a JSONSchema feature doesn’t conflict with any existing behavior it’s a simple add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working openapi-ts Relevant to the openapi-typescript library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants