Skip to content

Commit 7ffe200

Browse files
authored
test(codegen): add waiter/paginator to index tests (#1790)
1 parent 716bf8e commit 7ffe200

File tree

5 files changed

+120
-1
lines changed

5 files changed

+120
-1
lines changed

private/my-local-model-schema/test/index-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ export type {
33
XYZServiceClient,
44
XYZService,
55
GetNumbersCommand,
6+
GetNumbersCommandInput,
7+
GetNumbersCommandOutput,
68
TradeEventStreamCommand,
9+
TradeEventStreamCommandInput,
10+
TradeEventStreamCommandOutput,
711
Alpha,
812
GetNumbersRequest,
913
GetNumbersResponse,

private/smithy-rpcv2-cbor-schema/test/index-types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@ export type {
33
RpcV2ProtocolClient,
44
RpcV2Protocol,
55
EmptyInputOutputCommand,
6+
EmptyInputOutputCommandInput,
7+
EmptyInputOutputCommandOutput,
68
Float16Command,
9+
Float16CommandInput,
10+
Float16CommandOutput,
711
FractionalSecondsCommand,
12+
FractionalSecondsCommandInput,
13+
FractionalSecondsCommandOutput,
814
GreetingWithErrorsCommand,
15+
GreetingWithErrorsCommandInput,
16+
GreetingWithErrorsCommandOutput,
917
NoInputOutputCommand,
18+
NoInputOutputCommandInput,
19+
NoInputOutputCommandOutput,
1020
OperationWithDefaultsCommand,
21+
OperationWithDefaultsCommandInput,
22+
OperationWithDefaultsCommandOutput,
1123
OptionalInputOutputCommand,
24+
OptionalInputOutputCommandInput,
25+
OptionalInputOutputCommandOutput,
1226
RecursiveShapesCommand,
27+
RecursiveShapesCommandInput,
28+
RecursiveShapesCommandOutput,
1329
RpcV2CborDenseMapsCommand,
30+
RpcV2CborDenseMapsCommandInput,
31+
RpcV2CborDenseMapsCommandOutput,
1432
RpcV2CborListsCommand,
33+
RpcV2CborListsCommandInput,
34+
RpcV2CborListsCommandOutput,
1535
RpcV2CborSparseMapsCommand,
36+
RpcV2CborSparseMapsCommandInput,
37+
RpcV2CborSparseMapsCommandOutput,
1638
SimpleScalarPropertiesCommand,
39+
SimpleScalarPropertiesCommandInput,
40+
SimpleScalarPropertiesCommandOutput,
1741
SparseNullsOperationCommand,
42+
SparseNullsOperationCommandInput,
43+
SparseNullsOperationCommandOutput,
1844
TestEnum,
1945
TestIntEnum,
2046
FooEnum,

private/smithy-rpcv2-cbor/test/index-types.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,44 @@ export type {
33
RpcV2ProtocolClient,
44
RpcV2Protocol,
55
EmptyInputOutputCommand,
6+
EmptyInputOutputCommandInput,
7+
EmptyInputOutputCommandOutput,
68
Float16Command,
9+
Float16CommandInput,
10+
Float16CommandOutput,
711
FractionalSecondsCommand,
12+
FractionalSecondsCommandInput,
13+
FractionalSecondsCommandOutput,
814
GreetingWithErrorsCommand,
15+
GreetingWithErrorsCommandInput,
16+
GreetingWithErrorsCommandOutput,
917
NoInputOutputCommand,
18+
NoInputOutputCommandInput,
19+
NoInputOutputCommandOutput,
1020
OperationWithDefaultsCommand,
21+
OperationWithDefaultsCommandInput,
22+
OperationWithDefaultsCommandOutput,
1123
OptionalInputOutputCommand,
24+
OptionalInputOutputCommandInput,
25+
OptionalInputOutputCommandOutput,
1226
RecursiveShapesCommand,
27+
RecursiveShapesCommandInput,
28+
RecursiveShapesCommandOutput,
1329
RpcV2CborDenseMapsCommand,
30+
RpcV2CborDenseMapsCommandInput,
31+
RpcV2CborDenseMapsCommandOutput,
1432
RpcV2CborListsCommand,
33+
RpcV2CborListsCommandInput,
34+
RpcV2CborListsCommandOutput,
1535
RpcV2CborSparseMapsCommand,
36+
RpcV2CborSparseMapsCommandInput,
37+
RpcV2CborSparseMapsCommandOutput,
1638
SimpleScalarPropertiesCommand,
39+
SimpleScalarPropertiesCommandInput,
40+
SimpleScalarPropertiesCommandOutput,
1741
SparseNullsOperationCommand,
42+
SparseNullsOperationCommandInput,
43+
SparseNullsOperationCommandOutput,
1844
TestEnum,
1945
TestIntEnum,
2046
FooEnum,

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/PackageApiValidationGenerator.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,10 @@ public void writeTypeIndexTest() {
6767
settings.getService()
6868
);
6969
for (OperationShape operation : containedOperations) {
70-
writer.write("$L,", symbolProvider.toSymbol(operation).getName());
70+
String commandName = symbolProvider.toSymbol(operation).getName();
71+
writer.write("$L,", commandName);
72+
writer.write("$LInput,", commandName);
73+
writer.write("$LOutput,", commandName);
7174
}
7275

7376
// enums
@@ -89,6 +92,15 @@ public void writeTypeIndexTest() {
8992

9093
// synthetic base exception
9194
writer.write("$L,", aggregateClientName + "ServiceException");
95+
96+
// waiters
97+
serviceClosure.getWaiterNames().forEach(waiter -> {
98+
writer.write("$L,", waiter);
99+
});
100+
// paginators
101+
serviceClosure.getPaginatorNames().forEach(paginator -> {
102+
writer.write("$L,", paginator);
103+
});
92104
}
93105
);
94106
}
@@ -164,6 +176,30 @@ public void writeRuntimeIndexTest() {
164176
writer.addRelativeImport(baseExceptionName, null, cjsIndex);
165177
writer.write("assert($L.prototype instanceof Error)", baseExceptionName);
166178

179+
// waiters & paginators
180+
TreeSet<String> waiterNames = serviceClosure.getWaiterNames();
181+
if (!waiterNames.isEmpty()) {
182+
writer.write("// waiters");
183+
}
184+
waiterNames.forEach(waiter -> {
185+
writer.addRelativeImport(waiter, null, cjsIndex);
186+
writer.write("""
187+
assert(typeof $L === "function")""",
188+
waiter
189+
);
190+
});
191+
TreeSet<String> paginatorNames = serviceClosure.getPaginatorNames();
192+
if (!paginatorNames.isEmpty()) {
193+
writer.write("// paginators");
194+
}
195+
paginatorNames.forEach(paginator -> {
196+
writer.addRelativeImport(paginator, null, cjsIndex);
197+
writer.write("""
198+
assert(typeof $L === "function")""",
199+
paginator
200+
);
201+
});
202+
167203
writer.write("console.log(`$L index test passed.`);", aggregateClientName);
168204
}
169205
}

smithy-typescript-codegen/src/main/java/software/amazon/smithy/typescript/codegen/knowledge/ServiceClosure.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,9 @@
2727
import software.amazon.smithy.model.shapes.UnionShape;
2828
import software.amazon.smithy.model.traits.EnumTrait;
2929
import software.amazon.smithy.model.traits.ErrorTrait;
30+
import software.amazon.smithy.model.traits.PaginatedTrait;
3031
import software.amazon.smithy.utils.SmithyInternalApi;
32+
import software.amazon.smithy.waiters.WaitableTrait;
3133

3234
/**
3335
* Retrieves shapes in the service operation closure.
@@ -37,6 +39,7 @@ public final class ServiceClosure implements KnowledgeIndex {
3739
private static final Map<ShapeId, ServiceClosure> BY_SERVICE = new ConcurrentHashMap<>();
3840
private final Model model;
3941

42+
private final TreeSet<OperationShape> operations = new TreeSet<>();
4043
private final TreeSet<Shape> structures = new TreeSet<>();
4144
private final TreeSet<Shape> errors = new TreeSet<>();
4245
private final TreeSet<Shape> enums = new TreeSet<>();
@@ -56,6 +59,7 @@ public static ServiceClosure of(Model model, ServiceShape service) {
5659
TopDownIndex topDown = TopDownIndex.of(model);
5760
ServiceClosure instance = new ServiceClosure(model);
5861
Set<OperationShape> containedOperations = topDown.getContainedOperations(service);
62+
instance.operations.addAll(containedOperations);
5963
instance.scan(containedOperations);
6064
instance.scanned.clear();
6165

@@ -76,6 +80,29 @@ public TreeSet<Shape> getEnums() {
7680
return enums;
7781
}
7882

83+
public TreeSet<String> getWaiterNames() {
84+
TreeSet<String> waiters = new TreeSet<>();
85+
for (OperationShape operation : operations) {
86+
operation.getTrait(WaitableTrait.class).ifPresent(trait -> {
87+
trait.getWaiters().forEach((waiterName, waiter) -> {
88+
waiters.add("waitFor" + waiterName);
89+
waiters.add("waitUntil" + waiterName);
90+
});
91+
});
92+
}
93+
return waiters;
94+
}
95+
96+
public TreeSet<String> getPaginatorNames() {
97+
TreeSet<String> paginators = new TreeSet<>();
98+
for (OperationShape operation : operations) {
99+
operation.getTrait(PaginatedTrait.class).ifPresent(trait -> {
100+
paginators.add("paginate" + operation.getId().getName());
101+
});
102+
}
103+
return paginators;
104+
}
105+
79106
private void scan(Shape shape) {
80107
scan(Collections.singletonList(shape));
81108
}

0 commit comments

Comments
 (0)