Skip to content

Commit 6812d64

Browse files
committed
use same pagination customization for both sync and async classes
1 parent bcefbd3 commit 6812d64

File tree

8 files changed

+26
-78
lines changed

8 files changed

+26
-78
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/emitters/tasks/PaginatorsGeneratorTasks.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import software.amazon.awssdk.codegen.emitters.GeneratorTask;
2626
import software.amazon.awssdk.codegen.emitters.GeneratorTaskParams;
2727
import software.amazon.awssdk.codegen.emitters.PoetGeneratorTask;
28-
import software.amazon.awssdk.codegen.model.config.customization.PaginationSubstitution;
2928
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
3029
import software.amazon.awssdk.codegen.poet.ClassSpec;
3130
import software.amazon.awssdk.codegen.poet.paginators.AsyncResponseClassSpec;
@@ -35,8 +34,10 @@
3534

3635
public class PaginatorsGeneratorTasks extends BaseGeneratorTasks {
3736

37+
private static final String SAME_TOKEN_CUSTOMIZATION = "LastPageHasPreviousToken";
38+
3839
private final String paginatorsClassDir;
39-
private final Map<String, PaginationSubstitution> customization;
40+
private final Map<String, String> customization;
4041

4142
public PaginatorsGeneratorTasks(GeneratorTaskParams dependencies) {
4243
super(dependencies);
@@ -68,8 +69,7 @@ private GeneratorTask createSyncTask(Map.Entry<String, PaginatorDefinition> entr
6869
ClassSpec classSpec = new SyncResponseClassSpec(model, entry.getKey(), entry.getValue());
6970

7071
if (customization != null && customization.containsKey(entry.getKey())) {
71-
String sync = customization.get(entry.getKey()).getSync();
72-
if (sync != null && sync.equals("SameTokenSyncResponseClassSpec")) {
72+
if (SAME_TOKEN_CUSTOMIZATION.equals(customization.get(entry.getKey()))) {
7373
classSpec = new SameTokenSyncResponseClassSpec(model, entry.getKey(), entry.getValue());
7474
}
7575
}
@@ -81,8 +81,7 @@ private GeneratorTask createAsyncTask(Map.Entry<String, PaginatorDefinition> ent
8181
ClassSpec classSpec = new AsyncResponseClassSpec(model, entry.getKey(), entry.getValue());
8282

8383
if (customization != null && customization.containsKey(entry.getKey())) {
84-
String async = customization.get(entry.getKey()).getAsync();
85-
if (async != null && async.equals("SameTokenAsyncResponseClassSpec")) {
84+
if (SAME_TOKEN_CUSTOMIZATION.equals(customization.get(entry.getKey()))) {
8685
classSpec = new SameTokenAsyncResponseClassSpec(model, entry.getKey(), entry.getValue());
8786
}
8887
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/CustomizationConfig.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,9 @@ public class CustomizationConfig {
150150
/**
151151
* Map of paginated operations that use custom class generation.
152152
* Key - c2j operation name
153-
* Value - {@link PaginationSubstitution} object with details about the customizations for
154-
* sync and async response classes
153+
* Value - indicates the type of pagination strategy to use
155154
*/
156-
private Map<String, PaginationSubstitution> paginationCustomization;
155+
private Map<String, String> paginationCustomization;
157156

158157
private CustomizationConfig() {
159158
}
@@ -387,11 +386,11 @@ public void setCustomProtocolFactoryFqcn(String customProtocolFactoryFqcn) {
387386
this.customProtocolFactoryFqcn = customProtocolFactoryFqcn;
388387
}
389388

390-
public Map<String, PaginationSubstitution> getPaginationCustomization() {
389+
public Map<String, String> getPaginationCustomization() {
391390
return paginationCustomization;
392391
}
393392

394-
public void setPaginationCustomization(Map<String, PaginationSubstitution> paginationCustomization) {
393+
public void setPaginationCustomization(Map<String, String> paginationCustomization) {
395394
this.paginationCustomization = paginationCustomization;
396395
}
397396
}

codegen/src/main/java/software/amazon/awssdk/codegen/model/config/customization/PaginationSubstitution.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/customizations/SameTokenAsyncResponseClassSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

codegen/src/main/java/software/amazon/awssdk/codegen/poet/paginators/customizations/SameTokenSyncResponseClassSpec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright 2010-2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

codegen/src/test/java/software/amazon/awssdk/codegen/poet/paginators/PaginatedResponseClassSpecTest.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import software.amazon.awssdk.codegen.C2jModels;
2727
import software.amazon.awssdk.codegen.IntermediateModelBuilder;
2828
import software.amazon.awssdk.codegen.model.config.customization.CustomizationConfig;
29-
import software.amazon.awssdk.codegen.model.config.customization.PaginationSubstitution;
3029
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
3130
import software.amazon.awssdk.codegen.model.service.PaginatorDefinition;
3231
import software.amazon.awssdk.codegen.model.service.Paginators;
@@ -38,9 +37,10 @@
3837

3938
public class PaginatedResponseClassSpecTest {
4039

40+
private static final String SAME_TOKEN_CUSTOMIZATION = "LastPageHasPreviousToken";
4141
private static IntermediateModel intermediateModel;
4242
private static Paginators paginators;
43-
private static Map<String, PaginationSubstitution> customization;
43+
private static Map<String, String> paginationCustomization;
4444

4545
@BeforeClass
4646
public static void setUp() throws IOException {
@@ -60,7 +60,7 @@ public static void setUp() throws IOException {
6060
.build())
6161
.build();
6262

63-
customization = intermediateModel.getCustomizationConfig().getPaginationCustomization();
63+
paginationCustomization = intermediateModel.getCustomizationConfig().getPaginationCustomization();
6464
}
6565

6666
private static Paginators getPaginatorsModel(File file) {
@@ -96,17 +96,17 @@ private ClassSpec getSyncResponseSpec(Map.Entry<String, PaginatorDefinition> ent
9696
entry.getKey(),
9797
entry.getValue());
9898

99-
if (customization != null && customization.containsKey(entry.getKey())) {
100-
String sync = customization.get(entry.getKey()).getSync();
101-
switch (sync) {
102-
case "SameTokenSyncResponseClassSpec":
99+
if (paginationCustomization != null && paginationCustomization.containsKey(entry.getKey())) {
100+
String customvalue = paginationCustomization.get(entry.getKey());
101+
switch (customvalue) {
102+
case SAME_TOKEN_CUSTOMIZATION:
103103
classSpec = new SameTokenSyncResponseClassSpec(intermediateModel,
104104
entry.getKey(),
105105
entry.getValue());
106106
break;
107107

108108
default:
109-
throw new IllegalArgumentException("Unknown customization value: " + sync);
109+
throw new IllegalArgumentException("Unknown paginationCustomization value: " + customvalue);
110110
}
111111
}
112112

@@ -118,17 +118,17 @@ private ClassSpec getAsyncResponseSpec(Map.Entry<String, PaginatorDefinition> en
118118
entry.getKey(),
119119
entry.getValue());
120120

121-
if (customization != null && customization.containsKey(entry.getKey())) {
122-
String async = customization.get(entry.getKey()).getAsync();
123-
switch (async) {
124-
case "SameTokenAsyncResponseClassSpec":
121+
if (paginationCustomization != null && paginationCustomization.containsKey(entry.getKey())) {
122+
String customvalue = paginationCustomization.get(entry.getKey());
123+
switch (customvalue) {
124+
case SAME_TOKEN_CUSTOMIZATION:
125125
classSpec = new SameTokenAsyncResponseClassSpec(intermediateModel,
126126
entry.getKey(),
127127
entry.getValue());
128128
break;
129129

130130
default:
131-
throw new IllegalArgumentException("Unknown customization value: " + async);
131+
throw new IllegalArgumentException("Unknown paginationCustomization value: " + customvalue);
132132
}
133133
}
134134

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/paginators/customization.config

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
],
77
"verifiedSimpleMethods" : ["paginatedOperationWithResultKey"],
88
"paginationCustomization": {
9-
"SameTokenPaginationApi" : {
10-
"sync" : "SameTokenSyncResponseClassSpec",
11-
"async": "SameTokenAsyncResponseClassSpec"
12-
}
9+
"SameTokenPaginationApi" : "LastPageHasPreviousToken"
1310
}
1411
}

services/cloudwatchlogs/src/main/resources/codegen-resources/customization.config

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
"describeResourcePolicies"
1313
],
1414
"paginationCustomization": {
15-
"GetLogEvents" : {
16-
"sync" : "SameTokenSyncResponseClassSpec",
17-
"async": "SameTokenAsyncResponseClassSpec"
18-
}
15+
"GetLogEvents" : "LastPageHasPreviousToken"
1916
}
2017
}

0 commit comments

Comments
 (0)