Skip to content

Commit 8d8b922

Browse files
authored
test(protocols): add schema protocol tests (#7117)
1 parent f7533ee commit 8d8b922

File tree

508 files changed

+129465
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

508 files changed

+129465
-39
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ test-types:
2929
test-protocols: bundles
3030
yarn g:vitest run -c vitest.config.protocols.integ.ts
3131

32+
test-schema: bundles
33+
yarn g:vitest run -c vitest.config.protocols-schema.integ.ts
34+
3235
test-integration: bundles
3336
rm -rf ./clients/client-sso/node_modules/\@smithy # todo(yarn) incompatible redundant nesting.
3437
yarn g:vitest run -c vitest.config.integ.ts

codegen/protocol-test-codegen/smithy-build.json

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,181 @@
263263
"private": true
264264
}
265265
}
266+
},
267+
"aws-protocoltests-ec2-schema": {
268+
"transforms": [
269+
{
270+
"name": "includeServices",
271+
"args": {
272+
"services": ["aws.protocoltests.ec2#AwsEc2"]
273+
}
274+
}
275+
],
276+
"plugins": {
277+
"typescript-codegen": {
278+
"package": "@aws-sdk/aws-protocoltests-ec2-schema",
279+
"generateSchemas": true,
280+
"packageVersion": "1.0.0-alpha.1",
281+
"packageJson": {
282+
"author": {
283+
"name": "AWS SDK for JavaScript Team",
284+
"url": "https://aws.amazon.com/javascript/"
285+
},
286+
"license": "Apache-2.0"
287+
},
288+
"private": true
289+
}
290+
}
291+
},
292+
"aws-protocoltests-json-schema": {
293+
"transforms": [
294+
{
295+
"name": "includeServices",
296+
"args": {
297+
"services": ["aws.protocoltests.json#JsonProtocol"]
298+
}
299+
}
300+
],
301+
"plugins": {
302+
"typescript-codegen": {
303+
"package": "@aws-sdk/aws-protocoltests-json-schema",
304+
"generateSchemas": true,
305+
"packageVersion": "1.0.0-alpha.1",
306+
"packageJson": {
307+
"author": {
308+
"name": "AWS SDK for JavaScript Team",
309+
"url": "https://aws.amazon.com/javascript/"
310+
},
311+
"license": "Apache-2.0"
312+
},
313+
"private": true
314+
}
315+
}
316+
},
317+
"aws-protocoltests-json-10-schema": {
318+
"transforms": [
319+
{
320+
"name": "includeServices",
321+
"args": {
322+
"services": ["aws.protocoltests.json10#JsonRpc10"]
323+
}
324+
}
325+
],
326+
"plugins": {
327+
"typescript-codegen": {
328+
"package": "@aws-sdk/aws-protocoltests-json-10-schema",
329+
"generateSchemas": true,
330+
"packageVersion": "1.0.0-alpha.1",
331+
"packageJson": {
332+
"author": {
333+
"name": "AWS SDK for JavaScript Team",
334+
"url": "https://aws.amazon.com/javascript/"
335+
},
336+
"license": "Apache-2.0"
337+
},
338+
"private": true
339+
}
340+
}
341+
},
342+
"aws-protocoltests-query-schema": {
343+
"transforms": [
344+
{
345+
"name": "includeServices",
346+
"args": {
347+
"services": ["aws.protocoltests.query#AwsQuery"]
348+
}
349+
}
350+
],
351+
"plugins": {
352+
"typescript-codegen": {
353+
"package": "@aws-sdk/aws-protocoltests-query-schema",
354+
"generateSchemas": true,
355+
"packageVersion": "1.0.0-alpha.1",
356+
"packageJson": {
357+
"author": {
358+
"name": "AWS SDK for JavaScript Team",
359+
"url": "https://aws.amazon.com/javascript/"
360+
},
361+
"license": "Apache-2.0"
362+
},
363+
"private": true
364+
}
365+
}
366+
},
367+
"aws-protocoltests-restjson-schema": {
368+
"transforms": [
369+
{
370+
"name": "includeServices",
371+
"args": {
372+
"services": ["aws.protocoltests.restjson#RestJson"]
373+
}
374+
}
375+
],
376+
"plugins": {
377+
"typescript-codegen": {
378+
"package": "@aws-sdk/aws-protocoltests-restjson-schema",
379+
"generateSchemas": true,
380+
"packageVersion": "1.0.0-alpha.1",
381+
"packageJson": {
382+
"author": {
383+
"name": "AWS SDK for JavaScript Team",
384+
"url": "https://aws.amazon.com/javascript/"
385+
},
386+
"license": "Apache-2.0"
387+
},
388+
"private": true
389+
}
390+
}
391+
},
392+
"aws-protocoltests-restxml-schema": {
393+
"transforms": [
394+
{
395+
"name": "includeServices",
396+
"args": {
397+
"services": ["aws.protocoltests.restxml#RestXml"]
398+
}
399+
}
400+
],
401+
"plugins": {
402+
"typescript-codegen": {
403+
"package": "@aws-sdk/aws-protocoltests-restxml-schema",
404+
"generateSchemas": true,
405+
"packageVersion": "1.0.0-alpha.1",
406+
"packageJson": {
407+
"author": {
408+
"name": "AWS SDK for JavaScript Team",
409+
"url": "https://aws.amazon.com/javascript/"
410+
},
411+
"license": "Apache-2.0"
412+
},
413+
"private": true
414+
}
415+
}
416+
},
417+
"aws-smithy-rpcv2-cbor-schema": {
418+
"transforms": [
419+
{
420+
"name": "includeServices",
421+
"args": {
422+
"services": ["smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"]
423+
}
424+
}
425+
],
426+
"plugins": {
427+
"typescript-codegen": {
428+
"package": "@aws-sdk/aws-protocoltests-smithy-rpcv2-cbor-schema",
429+
"generateSchemas": true,
430+
"packageVersion": "1.0.0-alpha.1",
431+
"packageJson": {
432+
"author": {
433+
"name": "AWS SDK for JavaScript Team",
434+
"url": "https://aws.amazon.com/javascript/"
435+
},
436+
"license": "Apache-2.0"
437+
},
438+
"private": true
439+
}
440+
}
266441
}
267442
}
268443
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package software.amazon.smithy.aws.typescript.codegen;
7+
8+
import java.util.Collections;
9+
import java.util.Map;
10+
import java.util.Objects;
11+
import java.util.function.Consumer;
12+
import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait;
13+
import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait;
14+
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait;
15+
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait;
16+
import software.amazon.smithy.aws.traits.protocols.RestJson1Trait;
17+
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait;
18+
import software.amazon.smithy.codegen.core.SymbolProvider;
19+
import software.amazon.smithy.model.Model;
20+
import software.amazon.smithy.model.traits.XmlNamespaceTrait;
21+
import software.amazon.smithy.typescript.codegen.LanguageTarget;
22+
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
23+
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
24+
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
25+
import software.amazon.smithy.typescript.codegen.schema.SchemaGenerationAllowlist;
26+
import software.amazon.smithy.utils.MapUtils;
27+
import software.amazon.smithy.utils.SmithyInternalApi;
28+
29+
30+
/**
31+
* Adds a protocol implementation to the runtime config.
32+
*/
33+
@SmithyInternalApi
34+
public final class AddProtocolConfig implements TypeScriptIntegration {
35+
36+
public AddProtocolConfig() {
37+
SchemaGenerationAllowlist.allow("com.amazonaws.s3#AmazonS3");
38+
SchemaGenerationAllowlist.allow("com.amazonaws.dynamodb#DynamoDB_20120810");
39+
SchemaGenerationAllowlist.allow("com.amazonaws.lambda#AWSGirApiService");
40+
41+
// protocol tests
42+
SchemaGenerationAllowlist.allow("aws.protocoltests.json10#JsonRpc10");
43+
SchemaGenerationAllowlist.allow("aws.protocoltests.json#JsonProtocol");
44+
SchemaGenerationAllowlist.allow("aws.protocoltests.restjson#RestJson");
45+
SchemaGenerationAllowlist.allow("aws.protocoltests.restxml#RestXml");
46+
SchemaGenerationAllowlist.allow("aws.protocoltests.query#AwsQuery");
47+
SchemaGenerationAllowlist.allow("aws.protocoltests.ec2#AwsEc2");
48+
}
49+
50+
@Override
51+
public void addConfigInterfaceFields(
52+
TypeScriptSettings settings,
53+
Model model,
54+
SymbolProvider symbolProvider,
55+
TypeScriptWriter writer
56+
) {
57+
// the {{ protocol?: Protocol }} type field is provided
58+
// by the smithy client config interface.
59+
}
60+
61+
@Override
62+
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
63+
TypeScriptSettings settings,
64+
Model model,
65+
SymbolProvider symbolProvider,
66+
LanguageTarget target
67+
) {
68+
if (!SchemaGenerationAllowlist.allows(settings.getService(), settings)) {
69+
return Collections.emptyMap();
70+
}
71+
String namespace = settings.getService().getNamespace();
72+
String xmlns = settings.getService(model)
73+
.getTrait(XmlNamespaceTrait.class)
74+
.map(XmlNamespaceTrait::getUri)
75+
.orElse("");
76+
77+
switch (target) {
78+
case SHARED:
79+
if (Objects.equals(settings.getProtocol(), RestXmlTrait.ID)) {
80+
return MapUtils.of(
81+
"protocol", writer -> {
82+
writer.addImportSubmodule(
83+
"AwsRestXmlProtocol", null,
84+
AwsDependency.AWS_SDK_CORE, "/protocols");
85+
writer.write("""
86+
new AwsRestXmlProtocol({
87+
defaultNamespace: $S, xmlNamespace: $S,
88+
})""",
89+
namespace,
90+
xmlns
91+
);
92+
}
93+
);
94+
} else if (Objects.equals(settings.getProtocol(), AwsQueryTrait.ID)) {
95+
return MapUtils.of(
96+
"protocol", writer -> {
97+
writer.addImportSubmodule(
98+
"AwsQueryProtocol", null,
99+
AwsDependency.AWS_SDK_CORE, "/protocols");
100+
writer.write(
101+
"""
102+
new AwsQueryProtocol({
103+
defaultNamespace: $S,
104+
xmlNamespace: $S,
105+
version: $S
106+
})""",
107+
namespace,
108+
xmlns,
109+
settings.getService(model).getVersion()
110+
);
111+
}
112+
);
113+
} else if (Objects.equals(settings.getProtocol(), Ec2QueryTrait.ID)) {
114+
return MapUtils.of(
115+
"protocol", writer -> {
116+
writer.addImportSubmodule(
117+
"AwsEc2QueryProtocol", null,
118+
AwsDependency.AWS_SDK_CORE, "/protocols");
119+
writer.write(
120+
"""
121+
new AwsEc2QueryProtocol({
122+
defaultNamespace: $S,
123+
xmlNamespace: $S,
124+
version: $S
125+
})""",
126+
namespace,
127+
xmlns,
128+
settings.getService(model).getVersion()
129+
);
130+
}
131+
);
132+
} else if (Objects.equals(settings.getProtocol(), RestJson1Trait.ID)) {
133+
return MapUtils.of(
134+
"protocol", writer -> {
135+
writer.addImportSubmodule(
136+
"AwsRestJsonProtocol", null,
137+
AwsDependency.AWS_SDK_CORE, "/protocols");
138+
writer.write("new AwsRestJsonProtocol({ defaultNamespace: $S })", namespace);
139+
}
140+
);
141+
} else if (Objects.equals(settings.getProtocol(), AwsJson1_0Trait.ID)) {
142+
return MapUtils.of(
143+
"protocol", writer -> {
144+
writer.addImportSubmodule(
145+
"AwsJson1_0Protocol", null,
146+
AwsDependency.AWS_SDK_CORE, "/protocols");
147+
writer.write("new AwsJson1_0Protocol({ defaultNamespace: $S })", namespace);
148+
}
149+
);
150+
} else if (Objects.equals(settings.getProtocol(), AwsJson1_1Trait.ID)) {
151+
return MapUtils.of(
152+
"protocol", writer -> {
153+
writer.addImportSubmodule(
154+
"AwsJson1_1Protocol", null,
155+
AwsDependency.AWS_SDK_CORE, "/protocols");
156+
writer.write("new AwsJson1_1Protocol({ defaultNamespace: $S })", namespace);
157+
}
158+
);
159+
}
160+
case BROWSER:
161+
case NODE:
162+
default:
163+
return Collections.emptyMap();
164+
}
165+
}
166+
}

codegen/smithy-aws-typescript-codegen/src/main/java/software/amazon/smithy/aws/typescript/codegen/AwsEc2.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package software.amazon.smithy.aws.typescript.codegen;
1717

1818
import java.util.Set;
19+
import software.amazon.smithy.aws.traits.protocols.Ec2QueryNameTrait;
1920
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait;
2021
import software.amazon.smithy.codegen.core.SymbolReference;
2122
import software.amazon.smithy.model.shapes.OperationShape;
@@ -24,8 +25,10 @@
2425
import software.amazon.smithy.model.shapes.ShapeId;
2526
import software.amazon.smithy.model.shapes.StructureShape;
2627
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
28+
import software.amazon.smithy.model.traits.Trait;
2729
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
2830
import software.amazon.smithy.typescript.codegen.integration.HttpRpcProtocolGenerator;
31+
import software.amazon.smithy.typescript.codegen.schema.SchemaTraitExtension;
2932
import software.amazon.smithy.typescript.codegen.util.StringStore;
3033
import software.amazon.smithy.utils.SmithyInternalApi;
3134

@@ -47,6 +50,19 @@
4750
*/
4851
@SmithyInternalApi
4952
final class AwsEc2 extends HttpRpcProtocolGenerator {
53+
static {
54+
SchemaTraitExtension.INSTANCE.add(
55+
Ec2QueryNameTrait.ID,
56+
(Trait trait) -> {
57+
if (trait instanceof Ec2QueryNameTrait ec2QueryName) {
58+
return """
59+
`%s`
60+
""".formatted(ec2QueryName.getValue());
61+
}
62+
return "";
63+
}
64+
);
65+
}
5066

5167
AwsEc2() {
5268
super(true);

0 commit comments

Comments
 (0)