-
Notifications
You must be signed in to change notification settings - Fork 225
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
Constraint trait for mutually exclusive structure members #786
Comments
Mutually exclusive structure members is something we've been kicking around for a while, and I think it would have a lot of value. To achieve this today, service owners need to implement validation in code manually. A trait coupled with code generated validation would be useful. At first glance, I like the second approach because it means we can do things like use selectors if needed to find members that are used as part of an exclusive list. I also think the idea of forcing the exclusion to be reciprocal to help with readability too. I think we'd need to ensure that members that are part of an exclusion list couldn't be marked as required if that's impossible. For example, the following is impossible:
|
Yes absolutely agreed: However, there is one subtlety here: What if, within a set of exclusive fields, there is a requirement that at least one is set? (The constraint "At least one of A or B, but not both, must be set" is not uncommon in my experience.) That gets a bit more complicated if there is more than one field involved. Again I can think of two approaches here, one with a trait on the structure and one with a trait on the members... Alterative 1@requireOneOf("Foo", "Bar", "Ham")
structure U {
@excludes(["Bar", "Ham"])
Foo: MyString,
@excludes("Foo")
Bar: MyString,
@excludes(["Eggs", "Foo"])
Ham: MyString,
@excludes("Ham")
Eggs: MyString
} Alternative 2structure U {
@excludes(["Bar", "Ham"])
@required({"Unless": { "Or": ["Bar", "Ham"] }})
Foo: MyString,
@excludes("Foo")
Bar: MyString,
@excludes(["Eggs", "Foo"])
Ham: MyString,
@excludes("Ham")
Eggs: MyString
} |
Has this been added? Think it would still be useful |
No it hasn't been added. Something with as little conditional logic and as simple as possible is necessary for this to be considered. We won't expand the scope of the |
My team is using Smithy extensively for API modelling and getting some great results!
One gap we are finding is in the constraint traits. The ones that exist are pretty great, however they are not capturing some repetitive use cases we have. One such use case is:
structure
fields. This is the simpler use case. A structure has two fields,Foo
andBar
. Either one may be specified, but both cannot be specified together. We would like a constraint trait to assist with this.My team owns our own code generator for our server side code, so we translate the Smithy model into code ourselves. If these constraints are implemented into the language, we can take it from there by updating our code generator to auto-generate the code from the constraints that we're currently writing by hand.
Examples
Alternative 1
Alternative 2
Tracking: SMITHY-438
The text was updated successfully, but these errors were encountered: