-
Notifications
You must be signed in to change notification settings - Fork 31
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
Open
jonathan343
wants to merge
8
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e76618e
smithy-json: support non-finite number serde
jonathan343 bb2f8ec
smithy-aws-core: add AWS JSON client protocols
jonathan343 e883dbb
codegen: add AWS JSON protocol generators
jonathan343 59b9c4d
Update tests
jonathan343 c67e230
smithy-aws-core: resolve awsJson errors by shape name across namespaces
jonathan343 8a80ab1
smithy-aws-core: align awsJson error resolution with restJson
jonathan343 d6e903e
smithy-aws-core: mark pytest.raises match pattern as a raw string
jonathan343 db3d072
smithy-core: import RetryStrategyOptions from its public module
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
83 changes: 83 additions & 0 deletions
83
...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,83 @@ | ||
| /* | ||
| * 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( | ||
| // These tests essentially try to assert nan == nan, which is never true. | ||
| // The generator needs protocol-specific assertions before enabling them. | ||
| "AwsJson10SupportsNaNFloatInputs", | ||
|
|
||
| // TODO: support the request compression trait. | ||
| "SDKAppliedContentEncoding_awsJson1_0", | ||
| "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0", | ||
|
|
||
| // TODO: fix default value behavior for JSON RPC. | ||
| "AwsJson10ClientPopulatesDefaultValuesInInput", | ||
| "AwsJson10ClientSkipsTopLevelDefaultValuesInInput", | ||
| "AwsJson10ClientUsesExplicitlyProvidedMemberValuesOverDefaults", | ||
| "AwsJson10ClientPopulatesDefaultsValuesWhenMissingInResponse", | ||
| "AwsJson10ClientIgnoresNonTopLevelDefaultsOnMembersWithClientOptional", | ||
|
|
||
| // TODO: support the endpoint trait. | ||
| "AwsJson10EndpointTrait", | ||
| "AwsJson10EndpointTraitWithHostLabel", | ||
|
|
||
| // 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_awsjson10_protocol.py", "tests.test_awsjson10_protocol", writer -> { | ||
| new HttpProtocolTestGenerator( | ||
| context, | ||
| getProtocol(), | ||
| writer, | ||
| (shape, testCase) -> TESTS_TO_SKIP.contains(testCase.getId())).run(); | ||
| }); | ||
| } | ||
| } | ||
71 changes: 71 additions & 0 deletions
71
...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,71 @@ | ||
| /* | ||
| * 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( | ||
| // These tests essentially try to assert nan == nan, which is never true. | ||
| // The generator needs protocol-specific assertions before enabling them. | ||
| "AwsJson11SupportsNaNFloatInputs", | ||
|
|
||
| // TODO: support the request compression trait. | ||
| "SDKAppliedContentEncoding_awsJson1_1", | ||
| "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1", | ||
|
|
||
| // TODO: support the endpoint trait. | ||
| "AwsJson11EndpointTrait", | ||
| "AwsJson11EndpointTraitWithHostLabel"); | ||
|
|
||
| @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_awsjson11_protocol.py", "tests.test_awsjson11_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
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.
Didn't you say you fixed this?
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.
No, maybe you're thinking of the error namespace mismatch fallback behavior I added?