Skip to content

fix: correctly generate anyOf on unions with string and boolean constant #2208

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

Open
wants to merge 1 commit into
base: next
Choose a base branch
from

Conversation

pixunil
Copy link

@pixunil pixunil commented Mar 24, 2025

as far as I understood while debugging through the test code, StringType is used for string while LiteralType is used for a string constant like "s", thus StringType cannot be part of a literal union.

noticed that there is some magic regarding string which is hard to incorporate outside of LiterallUnionTypeFormatter. but it appears to me that a StringType could get discarded when it is not marked as preserve literals

closes #2207

}
]
},
"var8": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm unsure if we can use enum and type[] in the same type. Especially the combination of boolean, string, and true.

I'd bet that even if allowed, this would break in a lot of community parsers. Could we make this be a anyOf boolean const true and string enum s?

Copy link
Author

@pixunil pixunil Mar 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn’t this the analog case for var4 and var6, apart from using a number instead of boolean?
regarding whether it is allowed, at least for type and enum I don’t see a indication that they are exclusive (https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-6.1.1). it feels a bit redundant to specify both, as enum implicitly specifies type

@pixunil pixunil force-pushed the fix-union-string-with-constant-boolean branch from b6dcdaa to 56bdaf7 Compare March 27, 2025 22:47
@pixunil pixunil requested a review from arthurfiorette March 31, 2025 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Union with string and false creates wrong output
2 participants