-
Notifications
You must be signed in to change notification settings - Fork 218
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 support for 1.0 downgrades and serialization #1403
Conversation
This commit adds the ability to downgrade the in-memory semantic model to 1.0 models, and adds support for serializing 1.0 JSON AST models to ModelSerializer.
@@ -116,6 +116,11 @@ public Builder id(ShapeId shapeId) { | |||
return this; | |||
} | |||
|
|||
@Override |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fluent interface here needed this override for it to work
@@ -63,6 +63,14 @@ public void testRoundTrip(Path path) { | |||
ObjectNode expected = Node.parse(IoUtils.readUtf8File(path)).expectObjectNode(); | |||
|
|||
Node.assertEquals(actual, expected); | |||
|
|||
// Now validate the file is serialized correctly when downgraded to 1.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would we be able to have a test that starts a 1.0 model, loads it and serializes it as 1.0 and compares?
for (StructureShape structure : model.getStructureShapes()) { | ||
for (MemberShape member : structure.getAllMembers().values()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could have been getMemberShapesWithTrait like above?
smithy-model/src/main/java/software/amazon/smithy/model/transform/DowngradeToV1.java
Show resolved
Hide resolved
* @param model Model to downgrade. | ||
* @return Returns the downgraded model. | ||
*/ | ||
public Model downgradeToV1(Model model) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The javadoc does say 'remove' a bunch, but probably worth an explicit callout that this is lossy.
+ "structure Struct {\n" | ||
+ " @default(10)\n" | ||
+ " foo: MyInteger\n" | ||
+ " baz: PrimitiveInteger = null\n" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to add a member which has the zero value and make assertions on that
This commit adds the ability to downgrade the in-memory semantic model to 1.0 models, and adds support for serializing 1.0 JSON AST models to ModelSerializer.
Issue #, if available:
Description of changes:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.