Skip to content

Commit d37c139

Browse files
kstichdagnir
andauthored
Fix RPC v2 URI resolution (#6081)
This commit removes the possiblity to customize the HTTP URI for the Smithy RPC v2 CBOR protocol by setting a non-`/` value in the `http` property. It also fixes some typos in the contributing document. Co-authored-by: Dongie Agnir <261310+dagnir@users.noreply.github.com>
1 parent ac754ba commit d37c139

File tree

7 files changed

+163
-68
lines changed

7 files changed

+163
-68
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2",
4+
"contributor": "kstich",
5+
"description": "Fix Smithy RPC v2 CBOR URI resolution allowing custom URIs."
6+
}

CONTRIBUTING.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ __Jump To:__
1111
* [Additional Resources](#additional-resources)
1212

1313
## Bug Reports
14-
Bug reports are accepted through the [this][bug-report] page.
14+
Bug reports are accepted through [this][bug-report] page.
1515

1616
The following labels are used to track bug related issues: [Bug][label-bug],
1717
[Documentation Issue][label-doc-issue].
@@ -38,7 +38,7 @@ please ensure that your bug report has the following:
3838

3939
* A short, descriptive title. Ideally, other community members should be able
4040
to get a good idea of the issue just from reading the title.
41-
* A succint, detailed description of the problem you're experiencing. This
41+
* A succinct, detailed description of the problem you're experiencing. This
4242
should include:
4343
* Expected behavior of the SDK and the actual behavior exhibited.
4444
* Any details of your application environment that may be relevant. At
@@ -51,7 +51,7 @@ please ensure that your bug report has the following:
5151
stacktraces.
5252

5353
## Feature Requests
54-
Feature requests are submitted through the [this][feature-request] page.
54+
Feature requests are submitted through [this][feature-request] page.
5555

5656
As with Bug Reports, please do a search of the open requests first before
5757
submitting a new one to avoid duplicates. If you find an existing one, give it
@@ -71,7 +71,7 @@ Open an [issue][issues] with the following:
7171

7272
* A short, descriptive title. Ideally, other community members should be able
7373
to get a good idea of the feature just from reading the title.
74-
* A detailed description of the the proposed feature. Include justification for
74+
* A detailed description of the proposed feature. Include justification for
7575
why it should be added to the SDK, and possibly example code to illustrate
7676
how it should work.
7777
* [Markdown][markdown] formatting as appropriate to make the request easier to
@@ -136,11 +136,11 @@ interfaces](https://github.com/reactive-streams/reactive-streams-jvm), the
136136
change must also contain verification tests using the [Reactive Streams
137137
Technology Compatibility
138138
Kit](https://github.com/reactive-streams/reactive-streams-jvm/tree/master/tck)
139-
to ensure specificiation compliance.
139+
to ensure specification compliance.
140140

141141
### Getting Your Pull Request Merged
142142
All Pull Requests must be approved by at least one member of the SDK team
143-
before it can be merged in. The members only have limited bandwitdth to review
143+
before it can be merged in. The members only have limited bandwidth to review
144144
Pull Requests so it's not unusual for a Pull Request to go unreviewed for a few
145145
days, especially if it's a large or complex one. If, after a week, your Pull
146146
Request has not had any engagement from the SDK team, feel free to ping a

codegen/src/main/java/software/amazon/awssdk/codegen/customization/processors/SmithyRpcV2CborProtocolProcessor.java

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,11 @@
2020
import software.amazon.awssdk.codegen.model.service.Http;
2121
import software.amazon.awssdk.codegen.model.service.Operation;
2222
import software.amazon.awssdk.codegen.model.service.ServiceModel;
23-
import software.amazon.awssdk.utils.StringUtils;
2423

2524
/**
2625
* This processor only runs for services using the <code>smithy-rpc-v2-cbor</code> protocol.
2726
*
28-
* Adds a request URI that conform to the Smithy RPCv2 protocol to each operation in the model, if there's no URI already
29-
* defined.
27+
* Sets a request URI that conforms to the Smithy RPC v2 protocol to each operation in the model.
3028
*/
3129
public class SmithyRpcV2CborProtocolProcessor implements CodegenCustomizationProcessor {
3230
@Override
@@ -38,13 +36,11 @@ public void preprocess(ServiceModel serviceModel) {
3836
}
3937

4038
private void setRequestUri(ServiceModel service, String name, Operation op) {
41-
Http http = op.getHttp();
42-
String requestUri = http.getRequestUri();
43-
if (StringUtils.isNotBlank(requestUri) && !"/".equals(requestUri)) {
44-
return;
45-
}
4639
String uri = String.format("/service/%s/operation/%s", service.getMetadata().getTargetPrefix(), op.getName());
47-
op.getHttp().setRequestUri(uri);
40+
if (op.getHttp() == null) {
41+
op.setHttp(new Http().withMethod("POST").withResponseCode("200"));
42+
}
43+
op.getHttp().withRequestUri(uri);
4844
}
4945

5046
@Override

codegen/src/main/java/software/amazon/awssdk/codegen/model/service/Http.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,9 @@ public String getResponseCode() {
5656
public void setResponseCode(String responseCode) {
5757
this.responseCode = responseCode;
5858
}
59+
60+
public Http withResponseCode(String responseCode) {
61+
this.responseCode = responseCode;
62+
return this;
63+
}
5964
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.customization.processors;
17+
18+
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
19+
20+
import java.io.File;
21+
import java.io.IOException;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.Test;
24+
import software.amazon.awssdk.codegen.C2jModels;
25+
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
26+
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
27+
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
28+
import software.amazon.awssdk.codegen.model.service.ServiceModel;
29+
import software.amazon.awssdk.codegen.utils.ModelLoaderUtils;
30+
31+
public class SmithyRpcV2CborProtocolProcessorTest {
32+
33+
private static CustomizationConfig config;
34+
private static ServiceModel serviceModel;
35+
36+
@BeforeAll
37+
public static void setUp() throws IOException {
38+
File serviceModelFile = new File(SmithyRpcV2CborProtocolProcessorTest.class.getResource("rpcv2-service-2.json").getFile());
39+
serviceModel = ModelLoaderUtils.loadModel(ServiceModel.class, serviceModelFile);
40+
File customizationConfigFile = new File(SmithyRpcV2CborProtocolProcessorTest.class.getResource("customization.config").getFile());
41+
serviceModel = ModelLoaderUtils.loadModel(ServiceModel.class, serviceModelFile);
42+
config = ModelLoaderUtils.loadModel(CustomizationConfig.class, customizationConfigFile);
43+
}
44+
45+
@Test
46+
public void specificRpcV2Uri_isSetInTheModel() {
47+
assertThat(serviceModel.getOperation("Slash").getHttp().getRequestUri()).isEqualTo("/");
48+
assertThat(serviceModel.getOperation("Custom").getHttp().getRequestUri()).isEqualTo("/Foo");
49+
assertThat(serviceModel.getOperation("None").getHttp()).isNull();
50+
IntermediateModel intermediateModel = new IntermediateModelBuilder(C2jModels.builder()
51+
.serviceModel(serviceModel)
52+
.customizationConfig(config)
53+
.build())
54+
.build();
55+
56+
assertThat(serviceModel.getOperation("Slash").getHttp().getRequestUri())
57+
.isEqualTo("/service/RpcV2Protocol/operation/Slash");
58+
assertThat(serviceModel.getOperation("Custom").getHttp().getRequestUri())
59+
.isEqualTo("/service/RpcV2Protocol/operation/Custom");
60+
assertThat(serviceModel.getOperation("None").getHttp().getRequestUri())
61+
.isEqualTo("/service/RpcV2Protocol/operation/None");
62+
}
63+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
"version":"2.0",
3+
"metadata":{
4+
"apiVersion":"2023-03-10",
5+
"auth":["aws.auth#sigv4"],
6+
"endpointPrefix":"smithyrpcv2protocol",
7+
"protocol":"smithy-rpc-v2-cbor",
8+
"protocols":["smithy-rpc-v2-cbor"],
9+
"serviceFullName":"RpcV2 Protocol Service",
10+
"serviceId":"SmithyRpcV2Protocol",
11+
"signatureVersion":"v4",
12+
"signingName":"execute-api",
13+
"targetPrefix":"RpcV2Protocol",
14+
"uid":"smithy-rpcv2protocol-2023-03-10"
15+
},
16+
"operations":{
17+
"Slash":{
18+
"name":"Slash",
19+
"http":{
20+
"method":"POST",
21+
"requestUri":"/"
22+
},
23+
"input":{"shape":"AllTypesStructure"}
24+
},
25+
"Custom":{
26+
"name":"Custom",
27+
"http":{
28+
"method":"POST",
29+
"requestUri":"/Foo"
30+
},
31+
"output":{"shape":"AllTypesStructure"}
32+
},
33+
"None":{
34+
"name":"None",
35+
"output":{"shape":"AllTypesStructure"}
36+
}
37+
},
38+
"shapes": {
39+
"AllTypesStructure": {
40+
"type": "structure",
41+
"members": {
42+
"TimeStampMember": {
43+
"shape": "Timestamp"
44+
},
45+
"ListOfTimestamps": {
46+
"shape": "ListOfTimestamps"
47+
},
48+
"Timestamp": {
49+
"shape": "Timestamp"
50+
},
51+
"StructWithTimestamp": {
52+
"shape": "StructWithTimestamp"
53+
}
54+
}
55+
},
56+
"ListOfTimestamps": {
57+
"type": "list",
58+
"member": {
59+
"shape": "Timestamp"
60+
}
61+
},
62+
"StructWithTimestamp": {
63+
"type": "structure",
64+
"members": {
65+
"Timestamp": {
66+
"shape": "Timestamp"
67+
}
68+
}
69+
},
70+
"Timestamp": {
71+
"type": "string"
72+
},
73+
"String" : {
74+
"type" : "string"
75+
}
76+
}
77+
}

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/c2j/rpcv2/service-2.json

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,19 @@
1616
"operations":{
1717
"EmptyInputOutput":{
1818
"name":"EmptyInputOutput",
19-
"http":{
20-
"method":"POST",
21-
"requestUri":"/"
22-
},
2319
"input":{"shape":"EmptyStructure"},
2420
"output":{"shape":"EmptyStructure"}
2521
},
2622
"Float16":{
2723
"name":"Float16",
28-
"http":{
29-
"method":"POST",
30-
"requestUri":"/"
31-
},
3224
"output":{"shape":"Float16Output"}
3325
},
3426
"FractionalSeconds":{
3527
"name":"FractionalSeconds",
36-
"http":{
37-
"method":"POST",
38-
"requestUri":"/"
39-
},
4028
"output":{"shape":"FractionalSecondsOutput"}
4129
},
4230
"GreetingWithErrors":{
4331
"name":"GreetingWithErrors",
44-
"http":{
45-
"method":"POST",
46-
"requestUri":"/"
47-
},
4832
"output":{"shape":"GreetingWithErrorsOutput"},
4933
"errors":[
5034
{"shape":"ComplexError"},
@@ -53,18 +37,10 @@
5337
"idempotent":true
5438
},
5539
"NoInputOutput":{
56-
"name":"NoInputOutput",
57-
"http":{
58-
"method":"POST",
59-
"requestUri":"/"
60-
}
40+
"name":"NoInputOutput"
6141
},
6242
"OperationWithDefaults":{
6343
"name":"OperationWithDefaults",
64-
"http":{
65-
"method":"POST",
66-
"requestUri":"/"
67-
},
6844
"input":{"shape":"OperationWithDefaultsInput"},
6945
"output":{"shape":"OperationWithDefaultsOutput"},
7046
"errors":[
@@ -73,28 +49,16 @@
7349
},
7450
"OptionalInputOutput":{
7551
"name":"OptionalInputOutput",
76-
"http":{
77-
"method":"POST",
78-
"requestUri":"/"
79-
},
8052
"input":{"shape":"SimpleStructure"},
8153
"output":{"shape":"SimpleStructure"}
8254
},
8355
"RecursiveShapes":{
8456
"name":"RecursiveShapes",
85-
"http":{
86-
"method":"POST",
87-
"requestUri":"/"
88-
},
8957
"input":{"shape":"RecursiveShapesInputOutput"},
9058
"output":{"shape":"RecursiveShapesInputOutput"}
9159
},
9260
"RpcV2CborDenseMaps":{
9361
"name":"RpcV2CborDenseMaps",
94-
"http":{
95-
"method":"POST",
96-
"requestUri":"/"
97-
},
9862
"input":{"shape":"RpcV2CborDenseMapsInputOutput"},
9963
"output":{"shape":"RpcV2CborDenseMapsInputOutput"},
10064
"errors":[
@@ -103,10 +67,6 @@
10367
},
10468
"RpcV2CborLists":{
10569
"name":"RpcV2CborLists",
106-
"http":{
107-
"method":"POST",
108-
"requestUri":"/"
109-
},
11070
"input":{"shape":"RpcV2CborListInputOutput"},
11171
"output":{"shape":"RpcV2CborListInputOutput"},
11272
"errors":[
@@ -116,10 +76,6 @@
11676
},
11777
"RpcV2CborSparseMaps":{
11878
"name":"RpcV2CborSparseMaps",
119-
"http":{
120-
"method":"POST",
121-
"requestUri":"/"
122-
},
12379
"input":{"shape":"RpcV2CborSparseMapsInputOutput"},
12480
"output":{"shape":"RpcV2CborSparseMapsInputOutput"},
12581
"errors":[
@@ -128,19 +84,11 @@
12884
},
12985
"SimpleScalarProperties":{
13086
"name":"SimpleScalarProperties",
131-
"http":{
132-
"method":"POST",
133-
"requestUri":"/"
134-
},
13587
"input":{"shape":"SimpleScalarStructure"},
13688
"output":{"shape":"SimpleScalarStructure"}
13789
},
13890
"SparseNullsOperation":{
13991
"name":"SparseNullsOperation",
140-
"http":{
141-
"method":"POST",
142-
"requestUri":"/"
143-
},
14492
"input":{"shape":"SparseNullsOperationInputOutput"},
14593
"output":{"shape":"SparseNullsOperationInputOutput"}
14694
}

0 commit comments

Comments
 (0)