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

Make adoption of Unit easier for existing models #1034

Merged
merged 2 commits into from
Jan 6, 2022

Conversation

adamthom-amzn
Copy link
Contributor

Description of changes:
Prevents Unit from being added to the service closure if it is only used by operation inputs and/or outputs, and
special-cases Unit for both operations and unions in JSONSchema conversion.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Considering Unit a neighbor of operations when it is the declared or implicit
input or output means that any other shape named Unit in the service closure
will be considered conflicting where it was not previously. By removing this
relationship, existing models will continue to work without renames.
@adamthom-amzn adamthom-amzn requested a review from a team January 5, 2022 23:19
@@ -130,6 +135,11 @@ public boolean isInlined(Shape shape) {
return isInlined(target);
}

// smithy.api#Unit is always inlined
if (UnitTypeTrait.UNIT.equals(shape.getId())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think things like API Gateway will generate names for anonymous objects (which this code would cause). Is there a way to generate a Unit shape in the JSON Schema for tagged unions members, but not for operation input?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have hacked this PR to do this, but the implementation via a boolean flag screams "this is not the right way to accomplish this."

This would be so much easier if we had service attached shapes; then I could meaningfully use relationship data to examine what's actually attached to the scope of the conversion, and a lot of this code would be a lot simpler.

@adamthom-amzn adamthom-amzn force-pushed the remove-unit-edge branch 2 times, most recently from 4058704 to 96e288d Compare January 6, 2022 19:14
By always inlining Unit as an empty object rather than creating a pointer
to a Unit schema, models will not need to rename either the built-in Unit or
Units of their own in order to perform JSONSchema conversion.
@adamthom-amzn adamthom-amzn merged commit 7b8eea1 into smithy-lang:main Jan 6, 2022
@adamthom-amzn adamthom-amzn deleted the remove-unit-edge branch January 6, 2022 20:47
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

Successfully merging this pull request may close these issues.

2 participants