Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
Comment on lines +42 to +45

Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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?


@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();
});
}
}
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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
public class AwsProtocolsIntegration implements PythonIntegration {
@Override
public List<ProtocolGenerator> getProtocolGenerators() {
return List.of(new AwsQueryProtocolGenerator());
return List.of(
new AwsQueryProtocolGenerator(),
new AwsJson10ProtocolGenerator(),
new AwsJson11ProtocolGenerator());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,14 @@ public void initializeProtocol(GenerationContext context, PythonWriter writer) {
// it will need to generate some protocol-specific comparators.
@Override
public void generateProtocolTests(GenerationContext context) {
context.writerDelegator().useFileWriter("./tests/test_protocol.py", "tests.test_protocol", writer -> {
new HttpProtocolTestGenerator(
context,
getProtocol(),
writer,
(shape, testCase) -> filterTests(testCase)).run();
});
context.writerDelegator()
.useFileWriter("./tests/test_restjson_protocol.py", "tests.test_restjson_protocol", writer -> {
new HttpProtocolTestGenerator(
context,
getProtocol(),
writer,
(shape, testCase) -> filterTests(testCase)).run();
});
}

private boolean filterTests(HttpMessageTestCase testCase) {
Expand Down
44 changes: 44 additions & 0 deletions codegen/protocol-test/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,50 @@
}
}
},
"aws-json-1-0": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": [
"aws.protocoltests.json10#JsonRpc10"
]
}
},
{
"name": "removeUnusedShapes"
}
],
"plugins": {
"python-client-codegen": {
"service": "aws.protocoltests.json10#JsonRpc10",
"module": "awsjson10",
"moduleVersion": "0.0.1"
}
}
},
"aws-json-1-1": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": [
"aws.protocoltests.json#JsonProtocol"
]
}
},
{
"name": "removeUnusedShapes"
}
],
"plugins": {
"python-client-codegen": {
"service": "aws.protocoltests.json#JsonProtocol",
"module": "awsjson11",
"moduleVersion": "0.0.1"
}
}
},
"aws-query": {
"transforms": [
{
Expand Down
Loading
Loading