Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ test-types:
test-protocols: bundles
yarn g:vitest run -c vitest.config.protocols.integ.ts

test-schema: bundles
yarn g:vitest run -c vitest.config.protocols-schema.integ.ts

test-integration: bundles
rm -rf ./clients/client-sso/node_modules/\@smithy # todo(yarn) incompatible redundant nesting.
yarn g:vitest run -c vitest.config.integ.ts
Expand Down
175 changes: 175 additions & 0 deletions codegen/protocol-test-codegen/smithy-build.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,181 @@
"private": true
}
}
},
"aws-protocoltests-ec2-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.ec2#AwsEc2"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-ec2-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
},
"aws-protocoltests-json-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.json#JsonProtocol"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-json-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
},
"aws-protocoltests-json-10-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.json10#JsonRpc10"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-json-10-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
},
"aws-protocoltests-query-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.query#AwsQuery"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-query-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
},
"aws-protocoltests-restjson-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.restjson#RestJson"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-restjson-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
},
"aws-protocoltests-restxml-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["aws.protocoltests.restxml#RestXml"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-restxml-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
},
"aws-smithy-rpcv2-cbor-schema": {
"transforms": [
{
"name": "includeServices",
"args": {
"services": ["smithy.protocoltests.rpcv2Cbor#RpcV2Protocol"]
}
}
],
"plugins": {
"typescript-codegen": {
"package": "@aws-sdk/aws-protocoltests-smithy-rpcv2-cbor-schema",
"generateSchemas": true,
"packageVersion": "1.0.0-alpha.1",
"packageJson": {
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0"
},
"private": true
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.aws.typescript.codegen;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.function.Consumer;
import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait;
import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait;
import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait;
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait;
import software.amazon.smithy.aws.traits.protocols.RestJson1Trait;
import software.amazon.smithy.aws.traits.protocols.RestXmlTrait;
import software.amazon.smithy.codegen.core.SymbolProvider;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.traits.XmlNamespaceTrait;
import software.amazon.smithy.typescript.codegen.LanguageTarget;
import software.amazon.smithy.typescript.codegen.TypeScriptSettings;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.integration.TypeScriptIntegration;
import software.amazon.smithy.typescript.codegen.schema.SchemaGenerationAllowlist;
import software.amazon.smithy.utils.MapUtils;
import software.amazon.smithy.utils.SmithyInternalApi;


/**
* Adds a protocol implementation to the runtime config.
*/
@SmithyInternalApi
public final class AddProtocolConfig implements TypeScriptIntegration {

public AddProtocolConfig() {
SchemaGenerationAllowlist.allow("com.amazonaws.s3#AmazonS3");
SchemaGenerationAllowlist.allow("com.amazonaws.dynamodb#DynamoDB_20120810");
SchemaGenerationAllowlist.allow("com.amazonaws.lambda#AWSGirApiService");

// protocol tests
SchemaGenerationAllowlist.allow("aws.protocoltests.json10#JsonRpc10");
SchemaGenerationAllowlist.allow("aws.protocoltests.json#JsonProtocol");
SchemaGenerationAllowlist.allow("aws.protocoltests.restjson#RestJson");
SchemaGenerationAllowlist.allow("aws.protocoltests.restxml#RestXml");
SchemaGenerationAllowlist.allow("aws.protocoltests.query#AwsQuery");
SchemaGenerationAllowlist.allow("aws.protocoltests.ec2#AwsEc2");
}

@Override
public void addConfigInterfaceFields(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
TypeScriptWriter writer
) {
// the {{ protocol?: Protocol }} type field is provided
// by the smithy client config interface.
}

@Override
public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
TypeScriptSettings settings,
Model model,
SymbolProvider symbolProvider,
LanguageTarget target
) {
if (!SchemaGenerationAllowlist.allows(settings.getService(), settings)) {
return Collections.emptyMap();
}
String namespace = settings.getService().getNamespace();
String xmlns = settings.getService(model)
.getTrait(XmlNamespaceTrait.class)
.map(XmlNamespaceTrait::getUri)
.orElse("");

switch (target) {
case SHARED:
if (Objects.equals(settings.getProtocol(), RestXmlTrait.ID)) {
return MapUtils.of(
"protocol", writer -> {
writer.addImportSubmodule(
"AwsRestXmlProtocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write("""
new AwsRestXmlProtocol({
defaultNamespace: $S, xmlNamespace: $S,
})""",
namespace,
xmlns
);
}
);
} else if (Objects.equals(settings.getProtocol(), AwsQueryTrait.ID)) {
return MapUtils.of(
"protocol", writer -> {
writer.addImportSubmodule(
"AwsQueryProtocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write(
"""
new AwsQueryProtocol({
defaultNamespace: $S,
xmlNamespace: $S,
version: $S
})""",
namespace,
xmlns,
settings.getService(model).getVersion()
);
}
);
} else if (Objects.equals(settings.getProtocol(), Ec2QueryTrait.ID)) {
return MapUtils.of(
"protocol", writer -> {
writer.addImportSubmodule(
"AwsEc2QueryProtocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write(
"""
new AwsEc2QueryProtocol({
defaultNamespace: $S,
xmlNamespace: $S,
version: $S
})""",
namespace,
xmlns,
settings.getService(model).getVersion()
);
}
);
} else if (Objects.equals(settings.getProtocol(), RestJson1Trait.ID)) {
return MapUtils.of(
"protocol", writer -> {
writer.addImportSubmodule(
"AwsRestJsonProtocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write("new AwsRestJsonProtocol({ defaultNamespace: $S })", namespace);
}
);
} else if (Objects.equals(settings.getProtocol(), AwsJson1_0Trait.ID)) {
return MapUtils.of(
"protocol", writer -> {
writer.addImportSubmodule(
"AwsJson1_0Protocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write("new AwsJson1_0Protocol({ defaultNamespace: $S })", namespace);
}
);
} else if (Objects.equals(settings.getProtocol(), AwsJson1_1Trait.ID)) {
return MapUtils.of(
"protocol", writer -> {
writer.addImportSubmodule(
"AwsJson1_1Protocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write("new AwsJson1_1Protocol({ defaultNamespace: $S })", namespace);
}
);
}
case BROWSER:
case NODE:
default:
return Collections.emptyMap();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package software.amazon.smithy.aws.typescript.codegen;

import java.util.Set;
import software.amazon.smithy.aws.traits.protocols.Ec2QueryNameTrait;
import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait;
import software.amazon.smithy.codegen.core.SymbolReference;
import software.amazon.smithy.model.shapes.OperationShape;
Expand All @@ -24,8 +25,10 @@
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.traits.TimestampFormatTrait.Format;
import software.amazon.smithy.model.traits.Trait;
import software.amazon.smithy.typescript.codegen.TypeScriptWriter;
import software.amazon.smithy.typescript.codegen.integration.HttpRpcProtocolGenerator;
import software.amazon.smithy.typescript.codegen.schema.SchemaTraitExtension;
import software.amazon.smithy.typescript.codegen.util.StringStore;
import software.amazon.smithy.utils.SmithyInternalApi;

Expand All @@ -47,6 +50,19 @@
*/
@SmithyInternalApi
final class AwsEc2 extends HttpRpcProtocolGenerator {
static {
SchemaTraitExtension.INSTANCE.add(
Ec2QueryNameTrait.ID,
(Trait trait) -> {
if (trait instanceof Ec2QueryNameTrait ec2QueryName) {
return """
`%s`
""".formatted(ec2QueryName.getValue());
}
return "";
}
);
}

AwsEc2() {
super(true);
Expand Down
Loading
Loading