Skip to content

Commit

Permalink
addressed review comments v1
Browse files Browse the repository at this point in the history
  • Loading branch information
joviegas committed Apr 30, 2024
1 parent c60dc43 commit f898582
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import software.amazon.awssdk.codegen.model.intermediate.ShapeModel;
import software.amazon.awssdk.codegen.model.rules.endpoints.EndpointTestSuiteModel;
import software.amazon.awssdk.codegen.model.service.AuthType;
import software.amazon.awssdk.codegen.model.service.CustomOperationContextParam;
import software.amazon.awssdk.codegen.model.service.EndpointRuleSetModel;
import software.amazon.awssdk.codegen.model.service.Operation;
import software.amazon.awssdk.codegen.model.service.Paginators;
Expand Down Expand Up @@ -168,25 +169,29 @@ public IntermediateModel build() {

namingStrategy.validateCustomerVisibleNaming(trimmedModel);
customizeEndpointParameters(fullModel, endpointRuleSet);
customizeOperationContextParams(fullModel, trimmedModel);
customizeOperationContextParams(trimmedModel, fullModel.getCustomizationConfig().getCustomOperationContextParams());
return trimmedModel;
}

private static void customizeOperationContextParams(IntermediateModel fullModel, IntermediateModel trimmedModel) {
if (!CollectionUtils.isNullOrEmpty(fullModel.getCustomizationConfig().getOperationContextParams())) {
fullModel.getCustomizationConfig().getOperationContextParams().forEach((operationName, operationContextParamMap) -> {
OperationModel operation = trimmedModel.getOperation(operationName);
if (operation == null) {
throw new IllegalStateException(
"Could not find operation " + operationName + " to customize Operation Context Params.");
}
if (operation.getOperationContextParams() != null) {
throw new IllegalStateException(
"Cannot customize operation " + operationName + " which already has OperationContextParams.");
}
operation.setOperationContextParams(operationContextParamMap);
});
private static void customizeOperationContextParams(IntermediateModel trimmedModel,
List<CustomOperationContextParam> customOperationContextParams) {

if (CollectionUtils.isNullOrEmpty(customOperationContextParams)) {
return;
}
customOperationContextParams.forEach(customOperationContextParam -> {
String operationName = customOperationContextParam.getOperationName();
OperationModel operation = trimmedModel.getOperation(operationName);
if (operation == null) {
throw new IllegalStateException(
"Could not find operation " + operationName + " to customize Operation Context Params.");
}
if (operation.getOperationContextParams() != null) {
throw new IllegalStateException(
"Cannot customize operation " + operationName + " which already has OperationContextParams.");
}
operation.setOperationContextParams(customOperationContextParam.getOperationContextParamsMap());
});
}

private void customizeEndpointParameters(IntermediateModel fullModel, EndpointRuleSetModel endpointRuleSet) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.Map;
import software.amazon.awssdk.codegen.model.rules.endpoints.ParameterModel;
import software.amazon.awssdk.codegen.model.service.ClientContextParam;
import software.amazon.awssdk.codegen.model.service.OperationContextParam;
import software.amazon.awssdk.codegen.model.service.CustomOperationContextParam;
import software.amazon.awssdk.core.retry.RetryMode;
import software.amazon.awssdk.core.traits.PayloadTrait;
import software.amazon.awssdk.utils.AttributeMap;
Expand Down Expand Up @@ -325,7 +325,8 @@ public class CustomizationConfig {
* This should be removed once the service updates its models
*/
private Map<String, ParameterModel> endpointParameters;
private Map<String, Map<String, OperationContextParam>> operationContextParams;

private List<CustomOperationContextParam> customOperationContextParams;

private CustomizationConfig() {
}
Expand Down Expand Up @@ -861,11 +862,11 @@ public void setEndpointParameters(Map<String, ParameterModel> endpointParameters
this.endpointParameters = endpointParameters;
}

public Map<String, Map<String, OperationContextParam>> getOperationContextParams() {
return operationContextParams;
public List<CustomOperationContextParam> getCustomOperationContextParams() {
return customOperationContextParams;
}

public void setOperationContextParams(Map<String, Map<String, OperationContextParam>> operationContextParams) {
this.operationContextParams = operationContextParams;
public void setCustomOperationContextParams(List<CustomOperationContextParam> customOperationContextParams) {
this.customOperationContextParams = customOperationContextParams;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.model.service;


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

@SdkInternalApi
public class CustomOperationContextParam {
Map<String, OperationContextParam> operationContextParamsMap;

String operationName;

public Map<String, OperationContextParam> getOperationContextParamsMap() {
return operationContextParamsMap;
}

public void setOperationContextParamsMap(Map<String, OperationContextParam> operationContextParamsMap) {
this.operationContextParamsMap = operationContextParamsMap;
}

public String getOperationName() {
return operationName;
}

public void setOperationName(String operationName) {
this.operationName = operationName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void endpointParametersWithIncorrectNameOperationContextInCustomizationCo
assertThatIllegalStateException()
.isThrownBy(() -> new EndpointParametersClassSpec(
ClientTestModels.queryServiceModelWithSpecialCustomization("customization-with-incorrectName-operationcontextparams.config")))
.withMessageContaining("Could not find operation randomOperatoinName to customize Operation Context Params.");
.withMessageContaining("Could not find operation RandomOperationName to customize Operation Context Params.");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"operationContextParams":
"customOperationContextParams": [
{
"OperationWithOperationContextParam": {
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
"operationName": "OperationWithOperationContextParam",
"operationContextParamsMap": {
"customEndpointArray": {
"value": "ListMember.StringList[*].LeafString"
}
}
}
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
{
"operationContextParams":
"customOperationContextParams": [
{
"randomOperatoinName": {
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
"operationName": "RandomOperationName",
"operationContextParamsMap": {
"customEndpointArray": {
"value": "ListMember.StringList[*].LeafString"
}
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,14 @@
"type": "StringArray"
}
},
"operationContextParams": {
"OperationWithCustomizedOperationContextParam": {
"customEndpointArray":{"value":"ListMember.StringList[*].LeafString"}
"customOperationContextParams": [
{
"operationName": "OperationWithCustomizedOperationContextParam",
"operationContextParamsMap": {
"customEndpointArray": {
"value": "ListMember.StringList[*].LeafString"
}
}
}
,
"CustomEndpointArray": {
"required": false,
"documentation": "Parameter from the customization config",
"type": "StringArray"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,9 +291,14 @@
"type": "StringArray"
}
},
"operationContextParams": {
"DeleteObjects": {
"deleteObjectKeys":{"value":"Delete.Objects[*].key"}
"customOperationContextParams": [
{
"operationName": "DeleteObjects",
"operationContextParamsMap": {
"DeleteObjectKeys": {
"value": "Delete.Objects[*].key"
}
}
}
}
]
}

0 comments on commit f898582

Please sign in to comment.