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

Make items objects instead of arrays for tuples #2

Merged
merged 2 commits into from
Feb 3, 2023

Conversation

avandecreme
Copy link

Workaround for biocad#31

If the tuples has homogeneous types, the generated schema is strict. On the other hand if there are heterogeneous types, the schema is not very strict because the order in which the types must come is not specified.

Also, I had to use anyOf instead of oneOf because for example the int in (Int, Float) matches both Integer and Number.

Finally, special care had to be taken to handle nullables.

Workaround for biocad#31

If the tuples has homogeneous types, the generated schema is strict.
On the other hand if there are heterogeneous types, the schema is not very strict because the order in which the types must come is not specified.

Also, I had to use anyOf instead of oneOf because for example the int in (Int, Float) matches both Integer and Number.

Finally, special care had to be taken to handle nullables.
@avandecreme avandecreme marked this pull request as draft February 3, 2023 08:19
@teto teto self-requested a review February 3, 2023 09:32
@avandecreme avandecreme marked this pull request as ready for review February 3, 2023 10:16
prop "(Set Bool)" $ shouldValidate (Proxy :: Proxy (Set Bool))
prop "(NonEmpty Bool)" $ shouldValidate (Proxy :: Proxy (NonEmpty Bool))
prop "(HashSet Bool)" $ shouldValidate (Proxy :: Proxy (HashSet Bool))
prop "(Either Int String)" $ shouldValidate (Proxy :: Proxy (Either Int String))
prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))
-- prop "(Int, String)" $ shouldValidate (Proxy :: Proxy (Int, String))
Copy link

Choose a reason for hiding this comment

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

are these commented tests expected ? didn't want to update the template schema ?

Copy link
Author

Choose a reason for hiding this comment

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

Those tests are checking that for any JSON value generated matching the schema generated by the ToSchema instance of (Int, String), we are able to parse it to (Int, String).

An example might make it clearer, we try to check whether we can parse [1, "hello"] to a (Int, String) which we can.
However, since the only constraints we have is having two elements of type Int or String, we also try [1, 1], ["hello", "bye"] and ["hello", 1] which we cannot parse to (Int, String).

Copy link

Choose a reason for hiding this comment

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

makes sense

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.

2 participants