Skip to content

Commit d0d4eae

Browse files
authored
Apply AWS_JSON status code mapping to CBOR (#5670)
* Apply AWS_JSON status code mapping to CBOR Note: Kinesis is the only one we currently customize to CBOR. * Fix expected code in test * Add additional testing - Codegen tests - Added tests for CBOR protocol exceptions * Fix depdnency issue
1 parent 65af9c5 commit d0d4eae

File tree

17 files changed

+4463
-2
lines changed

17 files changed

+4463
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "Amazon Kinesis",
4+
"contributor": "",
5+
"description": "Fix an issue where errors that should be `400` are incorrectly classified as `500`."
6+
}

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/ProtocolSpec.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,10 @@ default List<CodeBlock> registerModeledExceptions(IntermediateModel model, PoetE
9090
default String populateHttpStatusCode(ShapeModel shapeModel, IntermediateModel model) {
9191
Integer statusCode = shapeModel.getHttpStatusCode();
9292

93-
if (statusCode == null && model.getMetadata().getProtocol() == Protocol.AWS_JSON) {
93+
Protocol protocol = model.getMetadata().getProtocol();
94+
95+
if (statusCode == null
96+
&& (protocol == Protocol.AWS_JSON || protocol == Protocol.CBOR)) {
9497
if (shapeModel.isFault()) {
9598
statusCode = 500;
9699
} else {

codegen/src/test/java/software/amazon/awssdk/codegen/poet/ClientTestModels.java

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ public static IntermediateModel awsJsonServiceModels() {
4747
return new IntermediateModelBuilder(models).build();
4848
}
4949

50+
public static IntermediateModel cborServiceModels() {
51+
File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/json/service-2.json").getFile());
52+
File customizationModel = new File(ClientTestModels.class.getResource("client/c2j/cbor/customization.config").getFile());
53+
File paginatorsModel = new File(ClientTestModels.class.getResource("client/c2j/json/paginators.json").getFile());
54+
C2jModels models = C2jModels.builder()
55+
.serviceModel(getServiceModel(serviceModel))
56+
.customizationConfig(getCustomizationConfig(customizationModel))
57+
.paginatorsModel(getPaginatorsModel(paginatorsModel))
58+
.build();
59+
60+
return new IntermediateModelBuilder(models).build();
61+
}
62+
5063
public static IntermediateModel awsQueryCompatibleJsonServiceModels() {
5164
File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/query-to-json-errorcode/service-2.json").getFile());
5265
File customizationModel = new File(ClientTestModels.class.getResource("client/c2j/query-to-json-errorcode/customization.config").getFile());

codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/AsyncClientClassTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import static software.amazon.awssdk.codegen.poet.ClientTestModels.awsJsonServiceModels;
2020
import static software.amazon.awssdk.codegen.poet.ClientTestModels.awsQueryCompatibleJsonServiceModels;
2121
import static software.amazon.awssdk.codegen.poet.ClientTestModels.batchManagerModels;
22+
import static software.amazon.awssdk.codegen.poet.ClientTestModels.cborServiceModels;
2223
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customContentTypeModels;
2324
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customPackageModels;
2425
import static software.amazon.awssdk.codegen.poet.ClientTestModels.endpointDiscoveryModels;
@@ -61,6 +62,15 @@ public void asyncClientClassAwsJson() {
6162
assertThat(sraAsyncClientClass, generatesTo("sra/test-aws-json-async-client-class.java"));
6263
}
6364

65+
@Test
66+
public void asyncClientClassCbor() {
67+
AsyncClientClass asyncClientClass = createAsyncClientClass(cborServiceModels(), false);
68+
assertThat(asyncClientClass, generatesTo("test-cbor-async-client-class.java"));
69+
70+
AsyncClientClass sraAsyncClientClass = createAsyncClientClass(cborServiceModels(), true);
71+
assertThat(sraAsyncClientClass, generatesTo("sra/test-cbor-async-client-class.java"));
72+
}
73+
6474
@Test
6575
public void asyncClientClassAwsQueryCompatibleJson() {
6676
AsyncClientClass asyncClientClass = createAsyncClientClass(awsQueryCompatibleJsonServiceModels());

codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/SyncClientClassTest.java

+7
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import static org.hamcrest.MatcherAssert.assertThat;
1919
import static software.amazon.awssdk.codegen.poet.ClientTestModels.awsQueryCompatibleJsonServiceModels;
20+
import static software.amazon.awssdk.codegen.poet.ClientTestModels.cborServiceModels;
2021
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customContentTypeModels;
2122
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customPackageModels;
2223
import static software.amazon.awssdk.codegen.poet.ClientTestModels.endpointDiscoveryModels;
@@ -89,6 +90,12 @@ public void syncClientClassRpcV2() {
8990
assertThat(syncClientCustomServiceMetaData, generatesTo("test-rpcv2-sync.java"));
9091
}
9192

93+
@Test
94+
public void syncClientClassCbor() {
95+
ClassSpec syncClientCustomServiceMetaData = createSyncClientClass(cborServiceModels(), true);
96+
assertThat(syncClientCustomServiceMetaData, generatesTo("test-cbor-client-class.java"));
97+
}
98+
9299
private SyncClientClass createSyncClientClass(IntermediateModel model) {
93100
return new SyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/", "resources/"));
94101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"authPolicyActions" : {
3+
"skip" : true
4+
},
5+
"presignersFqcn": "software.amazon.awssdk.services.acm.presign.AcmClientPresigners",
6+
"serviceSpecificHttpConfig": "software.amazon.MyServiceHttpConfig",
7+
"serviceConfig": {
8+
"className": "ServiceConfiguration",
9+
"hasDualstackProperty": true,
10+
"hasFipsProperty": true
11+
},
12+
"customRetryPolicy": "software.amazon.MyServiceRetryPolicy",
13+
"customRetryStrategy": "software.amazon.MyServiceRetryStrategy",
14+
"verifiedSimpleMethods" : ["paginatedOperationWithResultKey"],
15+
"excludedSimpleMethods" : [
16+
"eventStreamOperation"
17+
],
18+
"utilitiesMethod": {
19+
"returnType": "software.amazon.awssdk.services.json.JsonUtilities",
20+
"createMethodParams": ["param1", "param2", "param3"]
21+
},
22+
"useLegacyEventGenerationScheme": {
23+
"EventStream": ["EventOne", "event-two", "eventThree"]
24+
},
25+
"customServiceMetadata": {
26+
"protocol": "cbor"
27+
}
28+
}

0 commit comments

Comments
 (0)