-
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
Add breakingChanges property to @trait
#1193
Conversation
We could bring back the idea of jmespath-lite to address those referencing issues |
smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy
Show resolved
Hide resolved
878127e
to
15e38ef
Compare
Yeah I considered JMESPath here, but there were some advantages to JSON Pointer:
Here are examples of how this would look with JMESPath. Given the map key example, I don't think we'd be able to get away with "JMESPath-lite" unfortunately. Match on the entire trait:
Match on specific structure/union members:
Match on list/set members:
Match on map values:
Match on keys:
Match on specific map key value pairs: Note that this is not a proposed feature of this proposal. We don't have this
Match on specific list index: Note that this is not a proposed feature of this proposal. We don't have this
|
smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy
Outdated
Show resolved
Hide resolved
smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy
Show resolved
Hide resolved
smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy
Outdated
Show resolved
Hide resolved
smithy-model/src/main/java/software/amazon/smithy/model/traits/TraitDefinition.java
Outdated
Show resolved
Hide resolved
...del/src/main/java/software/amazon/smithy/model/validation/validators/TraitDiffValidator.java
Outdated
Show resolved
Hide resolved
15e38ef
to
d7a3b13
Compare
...del/src/main/java/software/amazon/smithy/model/validation/validators/TraitDiffValidator.java
Outdated
Show resolved
Hide resolved
smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy
Outdated
Show resolved
Hide resolved
Rather than rely on specialized tags like `diff.error.add`, we can add `breakingChanges` rules to traits directly. Other changes to make this easier to implement include: * Add getMember(String) to Shape simplifies the trait diff validator significantly, and can be used to simplify many other code paths in Smithy if we go back and refactor them. * Added toNode and fromNode to various classes like Severity, NodePointer, etc. * Migrate diff.error.* tags to breakingChanges * Update smithy-diff docs to state that diff tags are deprecated.
d7a3b13
to
d3f437a
Compare
Rather than rely on specialized tags like
diff.error.add
, we can addbreakingChanges
rules to traits directly.Other changes to make this easier to implement include:
significantly, and can be used to simplify many other code paths in
Smithy if we go back and refactor them.
NodePointer, etc.
It is a backward incompatible change to add the following trait to an existing shape:
Note: The above trait definition is equivalent to the following:
It is a backward incompatible change to add or remove the following trait from an existing shape:
It is very likely backward incompatible to change the "foo" member of the following trait or to remove the "baz" member:
So for example, if the following shape:
Is changed to:
Then the change to the
foo
member from "a" to "b" is backward incompatible, as is the removal of thebaz
member.Referring to list and set members
The JSON pointer can path into the members of a list or set using a
member
segment.In the following example, it is a breaking change to change values of lists or sets in instances of the
names
trait:So for example, if the following shape:
Is changed to:
Then the change to the second value of the
names
member is backward incompatible because it changed fromLuke
toChewy
.Referring to map members
Members of a map shape can be referenced in a JSON pointer using
key
and
value
.The following example defines a trait where it is backward incompatible to remove a key value pair from a map:
So for example, if the following shape:
Is changed to:
Then the removal of the "Han" entry of the map is flagged as backward incompatible.
The following example detects when values of a map change.
So for example, if the following shape:
Is changed to:
Then the change to Luke's mapping from "Jedi" to "Ghost" is backward incompatible.
Note:
change
type with a map key has no effect.change
type other than "update" with map values has noeffect.
What this does not support
Note that the current syntax of JSON pointers and validation does not support referring to specific values or a list or set or specific entries in a map. For example, you can't say it's a breaking change to update the first element of a list using
/0
. Nor can you say it's a breaking change to update a specific named entry for a map like/someKeyName
. This was left out for now, but could be added later if needed. For example, kind of special syntax like/[0]
and/[foo]
, or perhaps/member[0]
and/key[foo]
.Possible future extension
If we ever really needed it, a conditional change type could be added to add more complex diff detection.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.