smithy-lang / smithy

Smithy is a protocol-agnostic interface definition language and set of tools for generating clients, servers, and documentation for any programming language.
https://smithy.io
Apache License 2.0
1.79k stars 215 forks source link

Default and constraint traits #1500

Closed 82marbag closed 1 year ago

82marbag commented 1 year ago

What is the expected behavior when default and constraint traits are both applied? What happens if the two don't agree (the default value is outside the constraints)?

david-perez commented 1 year ago

A related discussion is in https://github.com/awslabs/smithy/issues/1121.

mtdowling commented 1 year ago

They have to agree with the exception of the range trait. I think we need to add some of this content to the spec, but you can see the rules here: https://github.com/awslabs/smithy/blob/main/designs/defaults-and-model-evolution.md#default-value-constraints

From that link:

The @default trait accepts a document type. The value of the trait MUST be compatible with the shape targeted by the member and adhere to the following constraints:

82marbag commented 1 year ago

Are all these checks implemented in smithy already? Can we trust a model has already performed static checks?

I've seen at least @range constraints are validated

mtdowling commented 1 year ago

Yep!