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

Discriminated Union discriminators should be required #84

Closed
lewisjkl opened this issue Jan 27, 2022 · 5 comments
Closed

Discriminated Union discriminators should be required #84

lewisjkl opened this issue Jan 27, 2022 · 5 comments

Comments

@lewisjkl
Copy link
Contributor

https://github.com/disneystreaming/smithy4s/blob/main/modules/protocol/src/smithy4s/api/validation/DiscriminatedUnionValidator.java

We should be validating that the target structures containing the discriminator have the discriminating field marked as required. If the field is optional, then that means the discriminator may not be present which defeats the purpose.

@Baccata
Copy link
Contributor

Baccata commented Jan 28, 2022

I disagree, the field should not be part of the model. If anything we should validate that the field doesn't exist, to avoid collision with the serialisation mechanism

@Baccata
Copy link
Contributor

Baccata commented Jan 28, 2022

The openapi conversion however should ensure that the field exists and is marked as required in the output openapi model

@lewisjkl
Copy link
Contributor Author

I disagree, the field should not be part of the model. If anything we should validate that the field doesn't exist, to avoid collision with the serialisation mechanism

This works for me 👍

The openapi conversion however should ensure that the field exists and is marked as required in the output openapi model

In openapi, it seems like the field that is a discriminator is almost implied to be required, not sure though... I guess it wouldn't hurt to mark it as required in any case.

@Baccata
Copy link
Contributor

Baccata commented Jan 28, 2022

In openapi, it seems like the field that is a discriminator is almost implied to be required, not sure though... I guess it wouldn't hurt to mark it as required in any case.

Yup. In fact, not only should the field be required, but it should also be constrained as enumeration with a single value : the one corresponding to the alternative

@Baccata
Copy link
Contributor

Baccata commented Feb 9, 2022

The validation of the discriminated trait has been added there : #86

@Baccata Baccata closed this as completed Feb 9, 2022
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

No branches or pull requests

2 participants