generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 28
Add protocol support for AWS JSON-RPC #645
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
Draft
jonathan343
wants to merge
6
commits into
develop
Choose a base branch
from
json-rpc-v1
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,189
−105
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5c1d94b
Add AWS JSON 1.0 and 1.1 traits
jonathan343 d6704da
smithy-json: support quoted non-finite numeric serde
jonathan343 2eb2023
codegen: improve generated protocol test assertions
jonathan343 ad43c77
smithy-http: preserve host prefixes when applying endpoints
jonathan343 0243826
smithy-aws-core: add awsJson client protocol support
jonathan343 5a4659c
codegen: add awsJson protocol generators and tests
jonathan343 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
...e/src/main/java/software/amazon/smithy/python/aws/codegen/AwsJson10ProtocolGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.aws.codegen; | ||
|
|
||
| import java.util.Set; | ||
| import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait; | ||
| import software.amazon.smithy.model.node.ArrayNode; | ||
| import software.amazon.smithy.model.node.ObjectNode; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.python.codegen.ApplicationProtocol; | ||
| import software.amazon.smithy.python.codegen.GenerationContext; | ||
| import software.amazon.smithy.python.codegen.HttpProtocolTestGenerator; | ||
| import software.amazon.smithy.python.codegen.SymbolProperties; | ||
| import software.amazon.smithy.python.codegen.generators.ProtocolGenerator; | ||
| import software.amazon.smithy.python.codegen.writer.PythonWriter; | ||
| import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
|
||
| @SmithyInternalApi | ||
| public final class AwsJson10ProtocolGenerator implements ProtocolGenerator { | ||
| private static final Set<String> TESTS_TO_SKIP = Set.of( | ||
| // TODO: support the request compression trait | ||
| // https://smithy.io/2.0/spec/behavior-traits.html#smithy-api-requestcompression-trait | ||
| "SDKAppliedContentEncoding_awsJson1_0", | ||
| "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0", | ||
|
|
||
| // TODO: Fix for both REST-JSON and JSON-RPC | ||
| "AwsJson10ClientPopulatesDefaultValuesInInput", | ||
| "AwsJson10ClientSkipsTopLevelDefaultValuesInInput", | ||
| "AwsJson10ClientUsesExplicitlyProvidedMemberValuesOverDefaults", | ||
| "AwsJson10ClientPopulatesDefaultsValuesWhenMissingInResponse", | ||
| "AwsJson10ClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional", | ||
| "AwsJson10ClientIgnoresDefaultValuesIfMemberValuesArePresentInResponse", | ||
|
|
||
| // TODO: support client error-correction behavior when the server | ||
| // omits required values in modeled error responses. | ||
| "AwsJson10ClientErrorCorrectsWhenServerFailsToSerializeRequiredValues", | ||
| "AwsJson10ClientErrorCorrectsWithDefaultValuesWhenServerFailsToSerializeRequiredValues"); | ||
|
|
||
| @Override | ||
| public ShapeId getProtocol() { | ||
| return AwsJson1_0Trait.ID; | ||
| } | ||
|
|
||
| @Override | ||
| public ApplicationProtocol getApplicationProtocol(GenerationContext context) { | ||
| var service = context.settings().service(context.model()); | ||
| var trait = service.expectTrait(AwsJson1_0Trait.class); | ||
| var config = ObjectNode.builder() | ||
| .withMember("http", ArrayNode.fromStrings(trait.getHttp())) | ||
| .withMember("eventStreamHttp", ArrayNode.fromStrings(trait.getEventStreamHttp())) | ||
| .build(); | ||
| return ApplicationProtocol.createDefaultHttpApplicationProtocol(config); | ||
| } | ||
|
|
||
| @Override | ||
| public void initializeProtocol(GenerationContext context, PythonWriter writer) { | ||
| writer.addDependency(AwsPythonDependency.SMITHY_AWS_CORE.withOptionalDependencies("json")); | ||
| writer.addImport("smithy_aws_core.aio.protocols", "AwsJson10ClientProtocol"); | ||
| var serviceSymbol = context.symbolProvider().toSymbol(context.settings().service(context.model())); | ||
| var serviceSchema = serviceSymbol.expectProperty(SymbolProperties.SCHEMA); | ||
| writer.write("AwsJson10ClientProtocol($T)", serviceSchema); | ||
| } | ||
|
|
||
| @Override | ||
| public void generateProtocolTests(GenerationContext context) { | ||
| context.writerDelegator().useFileWriter("./tests/test_protocol.py", "tests.test_protocol", writer -> { | ||
| new HttpProtocolTestGenerator( | ||
| context, | ||
| getProtocol(), | ||
| writer, | ||
| (shape, testCase) -> TESTS_TO_SKIP.contains(testCase.getId())).run(); | ||
| }); | ||
| } | ||
| } |
63 changes: 63 additions & 0 deletions
63
...e/src/main/java/software/amazon/smithy/python/aws/codegen/AwsJson11ProtocolGenerator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
| package software.amazon.smithy.python.aws.codegen; | ||
|
|
||
| import java.util.Set; | ||
| import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait; | ||
| import software.amazon.smithy.model.node.ArrayNode; | ||
| import software.amazon.smithy.model.node.ObjectNode; | ||
| import software.amazon.smithy.model.shapes.ShapeId; | ||
| import software.amazon.smithy.python.codegen.ApplicationProtocol; | ||
| import software.amazon.smithy.python.codegen.GenerationContext; | ||
| import software.amazon.smithy.python.codegen.HttpProtocolTestGenerator; | ||
| import software.amazon.smithy.python.codegen.SymbolProperties; | ||
| import software.amazon.smithy.python.codegen.generators.ProtocolGenerator; | ||
| import software.amazon.smithy.python.codegen.writer.PythonWriter; | ||
| import software.amazon.smithy.utils.SmithyInternalApi; | ||
|
|
||
| @SmithyInternalApi | ||
| public final class AwsJson11ProtocolGenerator implements ProtocolGenerator { | ||
| private static final Set<String> TESTS_TO_SKIP = Set.of( | ||
| // TODO: support the request compression trait | ||
| // https://smithy.io/2.0/spec/behavior-traits.html#smithy-api-requestcompression-trait | ||
| "SDKAppliedContentEncoding_awsJson1_1", | ||
| "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1"); | ||
|
|
||
| @Override | ||
| public ShapeId getProtocol() { | ||
| return AwsJson1_1Trait.ID; | ||
| } | ||
|
|
||
| @Override | ||
| public ApplicationProtocol getApplicationProtocol(GenerationContext context) { | ||
| var service = context.settings().service(context.model()); | ||
| var trait = service.expectTrait(AwsJson1_1Trait.class); | ||
| var config = ObjectNode.builder() | ||
| .withMember("http", ArrayNode.fromStrings(trait.getHttp())) | ||
| .withMember("eventStreamHttp", ArrayNode.fromStrings(trait.getEventStreamHttp())) | ||
| .build(); | ||
| return ApplicationProtocol.createDefaultHttpApplicationProtocol(config); | ||
| } | ||
|
|
||
| @Override | ||
| public void initializeProtocol(GenerationContext context, PythonWriter writer) { | ||
| writer.addDependency(AwsPythonDependency.SMITHY_AWS_CORE.withOptionalDependencies("json")); | ||
| writer.addImport("smithy_aws_core.aio.protocols", "AwsJson11ClientProtocol"); | ||
| var serviceSymbol = context.symbolProvider().toSymbol(context.settings().service(context.model())); | ||
| var serviceSchema = serviceSymbol.expectProperty(SymbolProperties.SCHEMA); | ||
| writer.write("AwsJson11ClientProtocol($T)", serviceSchema); | ||
| } | ||
|
|
||
| @Override | ||
| public void generateProtocolTests(GenerationContext context) { | ||
| context.writerDelegator().useFileWriter("./tests/test_protocol.py", "tests.test_protocol", writer -> { | ||
| new HttpProtocolTestGenerator( | ||
| context, | ||
| getProtocol(), | ||
| writer, | ||
| (shape, testCase) -> TESTS_TO_SKIP.contains(testCase.getId())).run(); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back 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.
I'm not a fan of this. When you do a plain assert with two dataclasses, pytest will give you a nice result showing you the diff if they're not equal. This will fail at the first non-equal value. Also, since it only recurses on dataclasses it'll never find nan in a list or map.
In the spirit of moving things out of Java, it might be best to have a test-utils package that implements an assert that builds up an error. It could go in test dependencies so normal installs don't catch it.