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

Tagged enums as if else #96

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

jhoobergs
Copy link

@jhoobergs jhoobergs commented Aug 6, 2021

Currently internally tagged enums are converted to an any_of of all possible variants and each of these variants gets a field for the tag with one possible value. For validation purposes, this might be fine. I was, however, using it in combination with https://github.com/redhat-developer/yaml-language-server and the results where not satisfactory.

Due to the fact that the tag field is added to each variant, the autocomplete could not show me all possible (enum) values for the tag field. In this PR, I changed the serialization of tagged enum to an object with a field for the tag and a subschema with an all_of. This all_of contains each variants, but only conditionally, where the condition is that the tag field equals the value for the specific enum.

I did also see #91 but that solution is not JsonSchema compatible.

I submit this as a draft because of three reasons:

  • I am not sure that you like this behavior? I do personally think that is it better
  • I'm not sure if my implementation is 100% correct. Mainly for the case of unit-variants, I am not sure.
  • The tests are now failing, and I don't know where I should change the 'expected value' for the test

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.

1 participant