-
Notifications
You must be signed in to change notification settings - Fork 24
Enable shapes-only codegen #373
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
Conversation
5b2ec33 to
46b6ba3
Compare
|
Changes look good, looks like we have a test failing with the changes though.
|
46b6ba3 to
56c766e
Compare
|
I refactored this after all the repo structure changes. I made it so that the new plugin is a separate package and abstracted out some of the functionality that was being done by the client's directed codegen so that it could be shared. |
56c766e to
edb0659
Compare
|
Note that that number of added lines is scarier than reality as I had to copy over a bunch of smithy IDL files for testing. |
codegen/core/src/main/java/software/amazon/smithy/python/codegen/PythonFormatter.java
Show resolved
Hide resolved
...re/src/main/java/software/amazon/smithy/python/codegen/generators/ServiceErrorGenerator.java
Show resolved
Hide resolved
README.md
Outdated
| Input and output shapes (shapes with the `@input` or `@output` traits and | ||
| operation inputs / outputs created as part of an operation definition) are not | ||
| generated by default. To generate these shapes anyway, remove the traits with | ||
| the | ||
| [`excludeTraits` transform](https://smithy.io/2.0/guides/smithy-build-json.html#excludetraits): |
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.
Hmmm.. is this something where there could be a footgun later if they are using a (hypothetical) server plugin or the client plugin? Using type codegen in conjunction with client/server codegen will be common.
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.
I'm just calling it out, because, while it would always be possible, I'm not sure we want to point this capability out if it can lead to problems later.
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.
Also, Smithy Java generates inputs and outputs without needing the exclusion. We should be consistent.
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.
I'd rather they don't generate them tbh. I can make some improvments in this area though
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.
I made it a simple toggle in the settings.
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.
If you run the generation for the weather service example, pyright throws some errors:
examples/weather/build/smithy/types/python-type-codegen/weather/_private/schemas.py:569:1 - error: "STRING_LIST" is constant (because it is uppercase) and cannot be redefined (reportConstantRedefinition)
examples/weather/build/smithy/types/python-type-codegen/weather/_private/schemas.py:1139:1 - error: "STRING_LIST" is constant (because it is uppercase) and cannot be redefined (reportConstantRedefinition)
examples/weather/build/smithy/types/python-type-codegen/weather/_private/schemas.py:1493:1 - error: "NON_EMPTY_STRING" is constant (because it is uppercase) and cannot be redefined (reportConstantRedefinition)
examples/weather/build/smithy/types/python-type-codegen/weather/_private/schemas.py:1507:1 - error: "NON_EMPTY_STRING_LIST" is constant (because it is uppercase) and cannot be redefined (reportConstantRedefinition)
This is because the same constant is being produced in the same file:
STRING_LIST = Schema.collection(
id=ShapeID("aws.auth#StringList"),
shape_type=ShapeType.LIST,
...
)
...
STRING_LIST = Schema.collection(
id=ShapeID("aws.protocols#StringList"),
shape_type=ShapeType.LIST,
...
)
Smithy Java has the same problem, but it's not checked by anything:
static final Schema STRING_LIST = Schema.listBuilder(ShapeId.from("aws.auth#StringList"))
.putMember("member", PreludeSchemas.STRING)
.build();
...
static final Schema STRING_LIST = Schema.listBuilder(ShapeId.from("aws.protocols#StringList"))
.putMember("member", PreludeSchemas.STRING)
.build();
Whether or not this is actually problematic... if the underlying schema is always the same for a given constant, then it's not a problem.
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.
Same root issue, the serde methods are duplicated in models.py, leading to reportRedeclaration:
models.py:892:5 - error: Function declaration "_serialize_string_list" is obscured by a declaration of the same name (reportRedeclaration)
models.py:901:5 - error: Function declaration "_deserialize_string_list" is obscured by a declaration of the same name (reportRedeclaration)
models.py:1123:5 - error: Function declaration "_serialize_string_list" is obscured by a declaration of the same name (reportRedeclaration)
models.py:1132:5 - error: Function declaration "_deserialize_string_list" is obscured by a declaration of the same name (reportRedeclaration)
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.
Yes that's because tons of dependencies have those types. This is why the integ test only generates local shapes. There's not really a great workaround other than raising a conflict exception that's a bit more explicit.
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.
As it turns out, we weren't running validation! I forgot that ModelTransformer doesn't validate by itself. All those string lists were private, so they shouldn't have been pulled in in the first place.
| .withMember("selector", """ | ||
| :test([id|namespace = 'example.weather'], | ||
| [id|namespace = 'example.weather.nested'], | ||
| [id|namespace = 'example.weather.nested.more']) | ||
| """) |
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.
realistically, users probably won't add a selector, so I'd add a test (or modify this one) without the selector. You'll get the build error from pyright throwing reportConstantRedefinition and reportRedeclaration
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.
Eh I disagree. I think most people aren't gonna want to generate every shape in smithy.aws or whatever random trait package they have. The only ways around that are selectors or creating your own service shape.
...en/core/src/main/java/software/amazon/smithy/python/codegen/DirectedPythonClientCodegen.java
Show resolved
Hide resolved
This adds an alternative generation mode that only generates "data shapes".
885e0f2 to
47ef13b
Compare
This adds a validation step to generating a synthetic service to make sure we aren't generating anything too crazy. It also resolves some validation issues that cropped up in the integ test.
bc44291 to
5f3ec15
Compare
...ns/types/src/main/resources/META-INF/services/software.amazon.smithy.build.SmithyBuildPlugin
Outdated
Show resolved
Hide resolved
Co-authored-by: Hayden Baker <haydebak@amazon.com>
This adds an alternative generation mode that only generates "data shapes". It's a widely requested feature for both this code generator (I can't tell you how many DMs about this I've received) and for other Smithy generators.
These generated types could still be used in a rich way thanks to the schemas backing them - they could still be plugged into any
ShapeSerializerorShapeDeserializerBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.