Skip to content

Commit 8a9f648

Browse files
committed
test(protocols): add schema protocol tests
1 parent f7533ee commit 8a9f648

File tree

508 files changed

+129458
-34
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

+129458
-34
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
}
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
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+
13+
import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait;
14+
import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait;
15+
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait;
16+
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait;
17+
import software.amazon.smithy.aws.traits.protocols.RestJson1Trait;
18+
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait;
19+
import software.amazon.smithy.codegen.core.SymbolProvider;
20+
import software.amazon.smithy.model.Model;
21+
import software.amazon.smithy.model.traits.XmlNamespaceTrait;
22+
import software.amazon.smithy.typescript.codegen.LanguageTarget;
23+
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
24+
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
25+
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
26+
import software.amazon.smithy.typescript.codegen.schema.SchemaGenerationAllowlist;
27+
import software.amazon.smithy.utils.MapUtils;
28+
import software.amazon.smithy.utils.SmithyInternalApi;
29+
30+
31+
/**
32+
* Adds a protocol implementation to the runtime config.
33+
*/
34+
@SmithyInternalApi
35+
public final class AddProtocolConfig implements TypeScriptIntegration {
36+
37+
public AddProtocolConfig() {
38+
SchemaGenerationAllowlist.allow("com.amazonaws.s3#AmazonS3");
39+
SchemaGenerationAllowlist.allow("com.amazonaws.dynamodb#DynamoDB_20120810");
40+
SchemaGenerationAllowlist.allow("com.amazonaws.lambda#AWSGirApiService");
41+
42+
// protocol tests
43+
SchemaGenerationAllowlist.allow("aws.protocoltests.json10#JsonRpc10");
44+
SchemaGenerationAllowlist.allow("aws.protocoltests.json#JsonProtocol");
45+
SchemaGenerationAllowlist.allow("aws.protocoltests.restjson#RestJson");
46+
SchemaGenerationAllowlist.allow("aws.protocoltests.restxml#RestXml");
47+
SchemaGenerationAllowlist.allow("aws.protocoltests.query#AwsQuery");
48+
SchemaGenerationAllowlist.allow("aws.protocoltests.ec2#AwsEc2");
49+
}
50+
51+
@Override
52+
public void addConfigInterfaceFields(
53+
TypeScriptSettings settings,
54+
Model model,
55+
SymbolProvider symbolProvider,
56+
TypeScriptWriter writer
57+
) {
58+
// the {{ protocol?: Protocol }} type field is provided
59+
// by the smithy client config interface.
60+
}
61+
62+
@Override
63+
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
64+
TypeScriptSettings settings,
65+
Model model,
66+
SymbolProvider symbolProvider,
67+
LanguageTarget target
68+
) {
69+
if (!SchemaGenerationAllowlist.allows(settings.getService(), settings)) {
70+
return Collections.emptyMap();
71+
}
72+
String namespace = settings.getService().getNamespace();
73+
String xmlns = settings.getService(model)
74+
.getTrait(XmlNamespaceTrait.class)
75+
.map(XmlNamespaceTrait::getUri)
76+
.orElse("");
77+
78+
switch (target) {
79+
case SHARED:
80+
if (Objects.equals(settings.getProtocol(), RestXmlTrait.ID)) {
81+
return MapUtils.of(
82+
"protocol", writer -> {
83+
writer.addImportSubmodule(
84+
"AwsRestXmlProtocol", null,
85+
AwsDependency.AWS_SDK_CORE, "/protocols");
86+
writer.write("""
87+
new AwsRestXmlProtocol({
88+
defaultNamespace: $S, xmlNamespace: $S,
89+
})""",
90+
namespace,
91+
xmlns
92+
);
93+
}
94+
);
95+
} else if (Objects.equals(settings.getProtocol(), AwsQueryTrait.ID)) {
96+
return MapUtils.of(
97+
"protocol", writer -> {
98+
writer.addImportSubmodule(
99+
"AwsQueryProtocol", null,
100+
AwsDependency.AWS_SDK_CORE, "/protocols");
101+
writer.write(
102+
"""
103+
new AwsQueryProtocol({
104+
defaultNamespace: $S,
105+
xmlNamespace: $S,
106+
version: $S
107+
})""",
108+
namespace,
109+
xmlns,
110+
settings.getService(model).getVersion()
111+
);
112+
}
113+
);
114+
} else if (Objects.equals(settings.getProtocol(), Ec2QueryTrait.ID)) {
115+
return MapUtils.of(
116+
"protocol", writer -> {
117+
writer.addImportSubmodule(
118+
"AwsEc2QueryProtocol", null,
119+
AwsDependency.AWS_SDK_CORE, "/protocols");
120+
writer.write(
121+
"""
122+
new AwsEc2QueryProtocol({
123+
defaultNamespace: $S,
124+
xmlNamespace: $S,
125+
version: $S
126+
})""",
127+
namespace,
128+
xmlns,
129+
settings.getService(model).getVersion()
130+
);
131+
}
132+
);
133+
} else if (Objects.equals(settings.getProtocol(), RestJson1Trait.ID)) {
134+
return MapUtils.of(
135+
"protocol", writer -> {
136+
writer.addImportSubmodule(
137+
"AwsRestJsonProtocol", null,
138+
AwsDependency.AWS_SDK_CORE, "/protocols");
139+
writer.write("new AwsRestJsonProtocol({ defaultNamespace: $S })", namespace);
140+
}
141+
);
142+
} else if (Objects.equals(settings.getProtocol(), AwsJson1_0Trait.ID)) {
143+
return MapUtils.of(
144+
"protocol", writer -> {
145+
writer.addImportSubmodule(
146+
"AwsJson1_0Protocol", null,
147+
AwsDependency.AWS_SDK_CORE, "/protocols");
148+
writer.write("new AwsJson1_0Protocol({ defaultNamespace: $S })", namespace);
149+
}
150+
);
151+
} else if (Objects.equals(settings.getProtocol(), AwsJson1_1Trait.ID)) {
152+
return MapUtils.of(
153+
"protocol", writer -> {
154+
writer.addImportSubmodule(
155+
"AwsJson1_1Protocol", null,
156+
AwsDependency.AWS_SDK_CORE, "/protocols");
157+
writer.write("new AwsJson1_1Protocol({ defaultNamespace: $S })", namespace);
158+
}
159+
);
160+
}
161+
case BROWSER:
162+
case NODE:
163+
default:
164+
return Collections.emptyMap();
165+
}
166+
}
167+
}

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)