Skip to content

Adding codegen updates and configuration options #4085

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

Merged
Merged
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
Expand Up @@ -165,6 +165,7 @@ public Map<String, OperationModel> constructOperations() {
operationModel.setEndpointTrait(op.getEndpoint());
operationModel.setHttpChecksumRequired(op.isHttpChecksumRequired());
operationModel.setHttpChecksum(op.getHttpChecksum());
operationModel.setRequestCompression(op.getRequestCompression());
operationModel.setStaticContextParams(op.getStaticContextParams());

Input input = op.getInput();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.compression;

import java.util.List;
import software.amazon.awssdk.annotations.SdkInternalApi;

/**
* Class to map the RequestCompression trait of an operation.
*/
@SdkInternalApi
public class RequestCompression {

private List<String> encodings;

public List<String> getEncodings() {
return encodings;
}

public void setEncodings(List<String> encodings) {
this.encodings = encodings;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.codegen.checksum.HttpChecksum;
import software.amazon.awssdk.codegen.compression.RequestCompression;
import software.amazon.awssdk.codegen.docs.ClientType;
import software.amazon.awssdk.codegen.docs.DocConfiguration;
import software.amazon.awssdk.codegen.docs.OperationDocs;
Expand Down Expand Up @@ -71,6 +72,8 @@ public class OperationModel extends DocumentationModel {

private HttpChecksum httpChecksum;

private RequestCompression requestCompression;

@JsonIgnore
private Map<String, StaticContextParam> staticContextParams;

Expand Down Expand Up @@ -309,6 +312,14 @@ public void setHttpChecksum(HttpChecksum httpChecksum) {
this.httpChecksum = httpChecksum;
}

public RequestCompression getRequestCompression() {
return requestCompression;
}

public void setRequestCompression(RequestCompression requestCompression) {
this.requestCompression = requestCompression;
}

public Map<String, StaticContextParam> getStaticContextParams() {
return staticContextParams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.List;
import java.util.Map;
import software.amazon.awssdk.codegen.checksum.HttpChecksum;
import software.amazon.awssdk.codegen.compression.RequestCompression;
import software.amazon.awssdk.codegen.model.intermediate.EndpointDiscovery;

public class Operation {
Expand Down Expand Up @@ -52,6 +53,8 @@ public class Operation {

private HttpChecksum httpChecksum;

private RequestCompression requestCompression;

private Map<String, StaticContextParam> staticContextParams;

public String getName() {
Expand Down Expand Up @@ -189,6 +192,14 @@ public void setHttpChecksum(HttpChecksum httpChecksum) {
this.httpChecksum = httpChecksum;
}

public RequestCompression getRequestCompression() {
return requestCompression;
}

public void setRequestCompression(RequestCompression requestCompression) {
this.requestCompression = requestCompression;
}

public Map<String, StaticContextParam> getStaticContextParams() {
return staticContextParams;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait;
import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait;
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
import software.amazon.awssdk.core.SdkPojoBuilder;
Expand Down Expand Up @@ -187,7 +188,8 @@ public CodeBlock executionHandler(OperationModel opModel) {
.add(".withMetricCollector(apiCallMetricCollector)")
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
.add(HttpChecksumTrait.create(opModel))
.add(NoneAuthTypeRequestTrait.create(opModel));
.add(NoneAuthTypeRequestTrait.create(opModel))
.add(RequestCompressionTrait.create(opModel));

if (opModel.hasStreamingInput()) {
codeBlock.add(".withRequestBody(requestBody)")
Expand Down Expand Up @@ -257,6 +259,7 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
.add(HttpChecksumTrait.create(opModel))
.add(NoneAuthTypeRequestTrait.create(opModel))
.add(RequestCompressionTrait.create(opModel))
.add(".withInput($L)$L);",
opModel.getInput().getVariableName(), asyncResponseTransformerVariable(isStreaming, isRestJson, opModel));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait;
import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait;
import software.amazon.awssdk.core.async.AsyncResponseTransformer;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.http.HttpResponseHandler;
Expand Down Expand Up @@ -116,7 +117,8 @@ public CodeBlock executionHandler(OperationModel opModel) {
.add(".withMetricCollector(apiCallMetricCollector)")
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
.add(HttpChecksumTrait.create(opModel))
.add(NoneAuthTypeRequestTrait.create(opModel));
.add(NoneAuthTypeRequestTrait.create(opModel))
.add(RequestCompressionTrait.create(opModel));


if (opModel.hasStreamingInput()) {
Expand Down Expand Up @@ -151,7 +153,8 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
.add(".withMetricCollector(apiCallMetricCollector)\n")
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
.add(HttpChecksumTrait.create(opModel))
.add(NoneAuthTypeRequestTrait.create(opModel));
.add(NoneAuthTypeRequestTrait.create(opModel))
.add(RequestCompressionTrait.create(opModel));


builder.add(hostPrefixExpression(opModel) + asyncRequestBody + ".withInput($L)$L);",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumRequiredTrait;
import software.amazon.awssdk.codegen.poet.client.traits.HttpChecksumTrait;
import software.amazon.awssdk.codegen.poet.client.traits.NoneAuthTypeRequestTrait;
import software.amazon.awssdk.codegen.poet.client.traits.RequestCompressionTrait;
import software.amazon.awssdk.codegen.poet.eventstream.EventStreamUtils;
import software.amazon.awssdk.codegen.poet.model.EventStreamSpecHelper;
import software.amazon.awssdk.core.SdkPojoBuilder;
Expand Down Expand Up @@ -135,7 +136,8 @@ public CodeBlock executionHandler(OperationModel opModel) {
.add(".withInput($L)", opModel.getInput().getVariableName())
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
.add(HttpChecksumTrait.create(opModel))
.add(NoneAuthTypeRequestTrait.create(opModel));
.add(NoneAuthTypeRequestTrait.create(opModel))
.add(RequestCompressionTrait.create(opModel));


s3ArnableFields(opModel, model).ifPresent(codeBlock::add);
Expand Down Expand Up @@ -213,7 +215,8 @@ public CodeBlock asyncExecutionHandler(IntermediateModel intermediateModel, Oper
.add(asyncRequestBody(opModel))
.add(HttpChecksumRequiredTrait.putHttpChecksumAttribute(opModel))
.add(HttpChecksumTrait.create(opModel))
.add(NoneAuthTypeRequestTrait.create(opModel));
.add(NoneAuthTypeRequestTrait.create(opModel))
.add(RequestCompressionTrait.create(opModel));

s3ArnableFields(opModel, model).ifPresent(builder::add);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License").
* You may not use this file except in compliance with the License.
* A copy of the License is located at
*
* http://aws.amazon.com/apache2.0
*
* or in the "license" file accompanying this file. This file is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
* express or implied. See the License for the specific language governing
* permissions and limitations under the License.
*/

package software.amazon.awssdk.codegen.poet.client.traits;

import com.squareup.javapoet.CodeBlock;
import java.util.List;
import java.util.stream.Collectors;
import software.amazon.awssdk.codegen.model.intermediate.OperationModel;
import software.amazon.awssdk.core.client.config.SdkClientOption;
import software.amazon.awssdk.core.client.handler.ClientExecutionParams;
import software.amazon.awssdk.core.interceptor.SdkExecutionAttribute;
import software.amazon.awssdk.core.interceptor.SdkInternalExecutionAttribute;
import software.amazon.awssdk.core.interceptor.trait.RequestCompression;

/**
* The logic for handling the "requestCompression" trait within the code generator.
*/
public class RequestCompressionTrait {

private RequestCompressionTrait() {
}

/**
* Generate a ".putExecutionAttribute(...)" code-block for the provided operation model. This should be used within the
* context of initializing {@link ClientExecutionParams}. If request compression is not required by the operation, this will
* return an empty code-block.
*/
public static CodeBlock create(OperationModel operationModel) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add some tests to show generated code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added request compression operation to the query service-2.json, updated generated test files

if (operationModel.getRequestCompression() == null) {
return CodeBlock.of("");
}

List<String> encodings = operationModel.getRequestCompression().getEncodings();

return CodeBlock.builder()
.add(CodeBlock.of(".putExecutionAttribute($T.REQUEST_COMPRESSION, "
+ "$T.builder().encodings($L).isStreaming($L).build())",
SdkInternalExecutionAttribute.class, RequestCompression.class,
encodings.stream().collect(Collectors.joining("\", \"", "\"", "\"")),
operationModel.hasStreamingInput()))
.add(CodeBlock.of(".putExecutionAttribute($T.REQUEST_COMPRESSION_CONFIGURATION,"
+ "clientConfiguration.option($T.REQUEST_COMPRESSION_CONFIGURATION))",
SdkExecutionAttribute.class, SdkClientOption.class))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
},
"authtype": "none"
},
"OperationWithRequestCompression": {
"name": "APostOperation",
"http": {
"method": "POST",
"requestUri": "/"
},
"requestCompression": {
"encodings": ["gzip"]
}
},
"APostOperation": {
"name": "APostOperation",
"http": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@
},
"authtype": "none"
},
"OperationWithRequestCompression": {
"name": "APostOperation",
"http": {
"method": "POST",
"requestUri": "/"
},
"requestCompression": {
"encodings": ["gzip"]
}
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test. I think we should add tests for other protocols as well since it seems the codegen code for different protocols is in different files.

"APostOperation": {
"name": "APostOperation",
"http": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@
},
"httpChecksumRequired": true
},
"OperationWithRequestCompression": {
"name": "APostOperation",
"http": {
"method": "POST",
"requestUri": "/"
},
"requestCompression": {
"encodings": ["gzip"]
}
},
"APostOperation": {
"name": "APostOperation",
"http": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
},
"authtype": "none"
},
"OperationWithRequestCompression": {
"name": "APostOperation",
"http": {
"method": "POST",
"requestUri": "/"
},
"requestCompression": {
"encodings": ["gzip"]
}
},
"APostOperation": {
"name": "APostOperation",
"http": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import software.amazon.awssdk.services.json.model.InputEventStreamTwo;
import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest;
import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse;
import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionRequest;
import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionResponse;
import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest;
import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse;
import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest;
Expand Down Expand Up @@ -302,6 +304,32 @@ public CompletableFuture<OperationWithChecksumRequiredResponse> operationWithChe
return delegate.operationWithChecksumRequired(operationWithChecksumRequiredRequest);
}

/**
* Invokes the OperationWithRequestCompression operation asynchronously.
*
* @param operationWithRequestCompressionRequest
* @return A Java Future containing the result of the OperationWithRequestCompression operation returned by the
* service.<br/>
* The CompletableFuture returned by this method can be completed exceptionally with the following
* exceptions.
* <ul>
* <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client).
* Can be used for catch all scenarios.</li>
* <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get
* credentials, etc.</li>
* <li>JsonException Base class for all service exceptions. Unknown exceptions will be thrown as an instance
* of this type.</li>
* </ul>
* @sample JsonAsyncClient.OperationWithRequestCompression
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/OperationWithRequestCompression"
* target="_top">AWS API Documentation</a>
*/
@Override
public CompletableFuture<OperationWithRequestCompressionResponse> operationWithRequestCompression(
OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) {
return delegate.operationWithRequestCompression(operationWithRequestCompressionRequest);
}

/**
* Some paginated operation with result_key in paginators.json file
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import software.amazon.awssdk.services.json.model.JsonException;
import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredRequest;
import software.amazon.awssdk.services.json.model.OperationWithChecksumRequiredResponse;
import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionRequest;
import software.amazon.awssdk.services.json.model.OperationWithRequestCompressionResponse;
import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyRequest;
import software.amazon.awssdk.services.json.model.PaginatedOperationWithResultKeyResponse;
import software.amazon.awssdk.services.json.model.PaginatedOperationWithoutResultKeyRequest;
Expand Down Expand Up @@ -201,6 +203,29 @@ public OperationWithChecksumRequiredResponse operationWithChecksumRequired(
return delegate.operationWithChecksumRequired(operationWithChecksumRequiredRequest);
}

/**
* Invokes the OperationWithRequestCompression operation.
*
* @param operationWithRequestCompressionRequest
* @return Result of the OperationWithRequestCompression operation returned by the service.
* @throws SdkException
* Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for
* catch all scenarios.
* @throws SdkClientException
* If any client side error occurs such as an IO related failure, failure to get credentials, etc.
* @throws JsonException
* Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type.
* @sample JsonClient.OperationWithRequestCompression
* @see <a href="https://docs.aws.amazon.com/goto/WebAPI/json-service-2010-05-08/OperationWithRequestCompression"
* target="_top">AWS API Documentation</a>
*/
@Override
public OperationWithRequestCompressionResponse operationWithRequestCompression(
OperationWithRequestCompressionRequest operationWithRequestCompressionRequest) throws AwsServiceException,
SdkClientException, JsonException {
return delegate.operationWithRequestCompression(operationWithRequestCompressionRequest);
}

/**
* Some paginated operation with result_key in paginators.json file
*
Expand Down
Loading