Skip to content

Commit

Permalink
Apply AWS_JSON status code mapping to CBOR (#5670)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
dagnir authored Oct 22, 2024
1 parent 65af9c5 commit d0d4eae
Show file tree
Hide file tree
Showing 17 changed files with 4,463 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .changes/next-release/bugfix-AmazonKinesis-05d556d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "Amazon Kinesis",
"contributor": "",
"description": "Fix an issue where errors that should be `400` are incorrectly classified as `500`."
}
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ default List<CodeBlock> registerModeledExceptions(IntermediateModel model, PoetE
default String populateHttpStatusCode(ShapeModel shapeModel, IntermediateModel model) {
Integer statusCode = shapeModel.getHttpStatusCode();

if (statusCode == null && model.getMetadata().getProtocol() == Protocol.AWS_JSON) {
Protocol protocol = model.getMetadata().getProtocol();

if (statusCode == null
&& (protocol == Protocol.AWS_JSON || protocol == Protocol.CBOR)) {
if (shapeModel.isFault()) {
statusCode = 500;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ public static IntermediateModel awsJsonServiceModels() {
return new IntermediateModelBuilder(models).build();
}

public static IntermediateModel cborServiceModels() {
File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/json/service-2.json").getFile());
File customizationModel = new File(ClientTestModels.class.getResource("client/c2j/cbor/customization.config").getFile());
File paginatorsModel = new File(ClientTestModels.class.getResource("client/c2j/json/paginators.json").getFile());
C2jModels models = C2jModels.builder()
.serviceModel(getServiceModel(serviceModel))
.customizationConfig(getCustomizationConfig(customizationModel))
.paginatorsModel(getPaginatorsModel(paginatorsModel))
.build();

return new IntermediateModelBuilder(models).build();
}

public static IntermediateModel awsQueryCompatibleJsonServiceModels() {
File serviceModel = new File(ClientTestModels.class.getResource("client/c2j/query-to-json-errorcode/service-2.json").getFile());
File customizationModel = new File(ClientTestModels.class.getResource("client/c2j/query-to-json-errorcode/customization.config").getFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static software.amazon.awssdk.codegen.poet.ClientTestModels.awsJsonServiceModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.awsQueryCompatibleJsonServiceModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.batchManagerModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.cborServiceModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customContentTypeModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customPackageModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.endpointDiscoveryModels;
Expand Down Expand Up @@ -61,6 +62,15 @@ public void asyncClientClassAwsJson() {
assertThat(sraAsyncClientClass, generatesTo("sra/test-aws-json-async-client-class.java"));
}

@Test
public void asyncClientClassCbor() {
AsyncClientClass asyncClientClass = createAsyncClientClass(cborServiceModels(), false);
assertThat(asyncClientClass, generatesTo("test-cbor-async-client-class.java"));

AsyncClientClass sraAsyncClientClass = createAsyncClientClass(cborServiceModels(), true);
assertThat(sraAsyncClientClass, generatesTo("sra/test-cbor-async-client-class.java"));
}

@Test
public void asyncClientClassAwsQueryCompatibleJson() {
AsyncClientClass asyncClientClass = createAsyncClientClass(awsQueryCompatibleJsonServiceModels());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import static org.hamcrest.MatcherAssert.assertThat;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.awsQueryCompatibleJsonServiceModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.cborServiceModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customContentTypeModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.customPackageModels;
import static software.amazon.awssdk.codegen.poet.ClientTestModels.endpointDiscoveryModels;
Expand Down Expand Up @@ -89,6 +90,12 @@ public void syncClientClassRpcV2() {
assertThat(syncClientCustomServiceMetaData, generatesTo("test-rpcv2-sync.java"));
}

@Test
public void syncClientClassCbor() {
ClassSpec syncClientCustomServiceMetaData = createSyncClientClass(cborServiceModels(), true);
assertThat(syncClientCustomServiceMetaData, generatesTo("test-cbor-client-class.java"));
}

private SyncClientClass createSyncClientClass(IntermediateModel model) {
return new SyncClientClass(GeneratorTaskParams.create(model, "sources/", "tests/", "resources/"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"authPolicyActions" : {
"skip" : true
},
"presignersFqcn": "software.amazon.awssdk.services.acm.presign.AcmClientPresigners",
"serviceSpecificHttpConfig": "software.amazon.MyServiceHttpConfig",
"serviceConfig": {
"className": "ServiceConfiguration",
"hasDualstackProperty": true,
"hasFipsProperty": true
},
"customRetryPolicy": "software.amazon.MyServiceRetryPolicy",
"customRetryStrategy": "software.amazon.MyServiceRetryStrategy",
"verifiedSimpleMethods" : ["paginatedOperationWithResultKey"],
"excludedSimpleMethods" : [
"eventStreamOperation"
],
"utilitiesMethod": {
"returnType": "software.amazon.awssdk.services.json.JsonUtilities",
"createMethodParams": ["param1", "param2", "param3"]
},
"useLegacyEventGenerationScheme": {
"EventStream": ["EventOne", "event-two", "eventThree"]
},
"customServiceMetadata": {
"protocol": "cbor"
}
}
Loading

0 comments on commit d0d4eae

Please sign in to comment.