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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions codegen/sdk-codegen/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ tasks.register("generate-smithy-build") {
val useLegacyAuthServices = setOf<String>(
// e.g. "S3" - use this as exclusion list if needed.
)
val useSchemaSerde = setOf<String>(
// "CloudWatch Logs"
)
val projectionContents = Node.objectNodeBuilder()
.withMember("imports", Node.fromStrings("${models.getAbsolutePath()}${File.separator}${file.name}"))
.withMember("plugins", Node.objectNode()
Expand All @@ -121,6 +124,8 @@ tasks.register("generate-smithy-build") {
+ clientName + " Client for Node.js, Browser and React Native")
.withMember("useLegacyAuth",
useLegacyAuthServices.contains(serviceTrait.sdkId))
.withMember("generateSchemas",
useSchemaSerde.contains(serviceTrait.sdkId))
.build()))
.build()
projectionsBuilder.withMember(sdkId + "." + version.toLowerCase(), projectionContents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public AddProtocolConfig() {
SchemaGenerationAllowlist.allow("com.amazonaws.s3#AmazonS3");
SchemaGenerationAllowlist.allow("com.amazonaws.dynamodb#DynamoDB_20120810");
SchemaGenerationAllowlist.allow("com.amazonaws.lambda#AWSGirApiService");
SchemaGenerationAllowlist.allow("com.amazonaws.cloudwatchlogs#Logs_20140328");

// protocol tests
SchemaGenerationAllowlist.allow("aws.protocoltests.json10#JsonRpc10");
Expand Down Expand Up @@ -69,6 +70,7 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
return Collections.emptyMap();
}
String namespace = settings.getService().getNamespace();
String rpcTarget = settings.getService().getName();
String xmlns = settings.getService(model)
.getTrait(XmlNamespaceTrait.class)
.map(XmlNamespaceTrait::getUri)
Expand Down Expand Up @@ -144,7 +146,11 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
writer.addImportSubmodule(
"AwsJson1_0Protocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write("new AwsJson1_0Protocol({ defaultNamespace: $S })", namespace);
writer.write(
"new AwsJson1_0Protocol({ defaultNamespace: $S, serviceTarget: $S })",
namespace,
rpcTarget
);
}
);
} else if (Objects.equals(settings.getProtocol(), AwsJson1_1Trait.ID)) {
Expand All @@ -153,7 +159,11 @@ public Map<String, Consumer<TypeScriptWriter>> getRuntimeConfigWriters(
writer.addImportSubmodule(
"AwsJson1_1Protocol", null,
AwsDependency.AWS_SDK_CORE, "/protocols");
writer.write("new AwsJson1_1Protocol({ defaultNamespace: $S })", namespace);
writer.write(
"new AwsJson1_1Protocol({ defaultNamespace: $S, serviceTarget: $S })",
namespace,
rpcTarget
);
}
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe(AwsJson1_0Protocol.name, () => {
it("serializes blobs and timestamps", () => {
const protocol = new AwsJson1_0Protocol({
defaultNamespace: "namespace",
serviceTarget: "JsonRpc10",
});
protocol.setSerdeContext(serdeContext);
const codec = protocol.getPayloadCodec();
Expand All @@ -55,6 +56,7 @@ describe(AwsJson1_0Protocol.name, () => {
it("deserializes blobs and timestamps", async () => {
const protocol = new AwsJson1_0Protocol({
defaultNamespace: "namespace",
serviceTarget: "JsonRpc10",
});
protocol.setSerdeContext(serdeContext);
const codec = protocol.getPayloadCodec();
Expand All @@ -73,6 +75,7 @@ describe(AwsJson1_0Protocol.name, () => {
it("ignores JSON name and HTTP bindings", async () => {
const protocol = new AwsJson1_0Protocol({
defaultNamespace: "namespace",
serviceTarget: "JsonRpc10",
});
protocol.setSerdeContext(serdeContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
*/
export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
public constructor({ defaultNamespace }: { defaultNamespace: string }) {
public constructor({ defaultNamespace, serviceTarget }: { defaultNamespace: string; serviceTarget: string }) {
super({
defaultNamespace,
serviceTarget,
});
}

Expand All @@ -18,4 +19,11 @@ export class AwsJson1_0Protocol extends AwsJsonRpcProtocol {
protected getJsonRpcVersion() {
return "1.0" as const;
}

/**
* @override
*/
protected getDefaultContentType(): string {
return "application/x-amz-json-1.0";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import { HttpResponse } from "@smithy/protocol-http";
import { describe, expect, test as it } from "vitest";

import { context, deleteObjects } from "../test-schema.spec";
import { AwsJson1_0Protocol } from "./AwsJson1_0Protocol";
import { AwsJson1_1Protocol } from "./AwsJson1_1Protocol";

/**
* These tests are cursory since most coverage is provided by protocol tests.
*/
describe(AwsJson1_0Protocol, () => {
describe(AwsJson1_1Protocol, () => {
it("is 1.0", async () => {
const protocol = new AwsJson1_0Protocol({
const protocol = new AwsJson1_1Protocol({
defaultNamespace: "",
serviceTarget: "JsonRpc11",
});
expect(protocol.getShapeId()).toEqual("aws.protocols#awsJson1_0");
expect(protocol.getShapeId()).toEqual("aws.protocols#awsJson1_1");
});

it("serializes a request", async () => {
const protocol = new AwsJson1_0Protocol({
const protocol = new AwsJson1_1Protocol({
defaultNamespace: "",
serviceTarget: "JsonRpc11",
});
const httpRequest = await protocol.serializeRequest(
deleteObjects,
Expand Down Expand Up @@ -59,8 +61,9 @@ describe(AwsJson1_0Protocol, () => {
headers: {},
});

const protocol = new AwsJson1_0Protocol({
const protocol = new AwsJson1_1Protocol({
defaultNamespace: "",
serviceTarget: "JsonRpc11",
});

const output = await protocol.deserializeResponse(deleteObjects, context, httpResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { AwsJsonRpcProtocol } from "./AwsJsonRpcProtocol";
* @see https://smithy.io/2.0/aws/protocols/aws-json-1_1-protocol.html#differences-between-awsjson1-0-and-awsjson1-1
*/
export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
public constructor({ defaultNamespace }: { defaultNamespace: string }) {
public constructor({ defaultNamespace, serviceTarget }: { defaultNamespace: string; serviceTarget: string }) {
super({
defaultNamespace,
serviceTarget,
});
}

Expand All @@ -18,4 +19,11 @@ export class AwsJson1_1Protocol extends AwsJsonRpcProtocol {
protected getJsonRpcVersion() {
return "1.1" as const;
}

/**
* @override
*/
protected getDefaultContentType(): string {
return "application/x-amz-json-1.1";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ describe(AwsJsonRpcProtocol.name, () => {
it("has expected codec settings", async () => {
const protocol = new (class extends AwsJsonRpcProtocol {
constructor() {
super({ defaultNamespace: "" });
super({ defaultNamespace: "", serviceTarget: "" });
}

getShapeId(): string {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ import { loadRestJsonErrorCode } from "./parseJsonBody";
export abstract class AwsJsonRpcProtocol extends RpcProtocol {
protected serializer: ShapeSerializer<string | Uint8Array>;
protected deserializer: ShapeDeserializer<string | Uint8Array>;
protected serviceTarget: string;
private codec: JsonCodec;

protected constructor({ defaultNamespace }: { defaultNamespace: string }) {
protected constructor({ defaultNamespace, serviceTarget }: { defaultNamespace: string; serviceTarget: string }) {
super({
defaultNamespace,
});
this.serviceTarget = serviceTarget;
this.codec = new JsonCodec({
timestampFormat: {
useTrait: true,
Expand All @@ -50,9 +52,7 @@ export abstract class AwsJsonRpcProtocol extends RpcProtocol {
}
Object.assign(request.headers, {
"content-type": `application/x-amz-json-${this.getJsonRpcVersion()}`,
"x-amz-target":
(this.getJsonRpcVersion() === "1.0" ? `JsonRpc10.` : `JsonProtocol.`) +
NormalizedSchema.of(operationSchema).getName(),
"x-amz-target": `${this.serviceTarget}.${NormalizedSchema.of(operationSchema).getName()}`,
});
if (deref(operationSchema.input) === "unit" || !request.body) {
request.body = "{}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {
} else if (httpPayloadMember.isBlobSchema()) {
request.headers["content-type"] = "application/octet-stream";
} else {
request.headers["content-type"] = "application/json";
request.headers["content-type"] = this.getDefaultContentType();
}
} else if (!inputSchema.isUnitSchema()) {
const hasBody = Object.values(members).find((m) => {
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
});
if (hasBody) {
request.headers["content-type"] = "application/json";
request.headers["content-type"] = this.getDefaultContentType();
}
}
}
Expand Down Expand Up @@ -157,4 +157,11 @@ export class AwsRestJsonProtocol extends HttpBindingProtocol {

throw exception;
}

/**
* @override
*/
protected getDefaultContentType(): string {
return "application/json";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,4 +212,11 @@ export class AwsQueryProtocol extends RpcProtocol {
const errorData = this.loadQueryError(data);
return errorData?.message ?? errorData?.Message ?? data.message ?? data.Message ?? "Unknown";
}

/**
* @override
*/
protected getDefaultContentType(): string {
return "application/x-www-form-urlencoded";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,20 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {
} else if (httpPayloadMember.isBlobSchema()) {
request.headers["content-type"] = "application/octet-stream";
} else {
request.headers["content-type"] = "application/xml";
request.headers["content-type"] = this.getDefaultContentType();
}
} else if (!ns.isUnitSchema()) {
const hasBody = Object.values(members).find((m) => {
const { httpQuery, httpQueryParams, httpHeader, httpLabel, httpPrefixHeaders } = m.getMergedTraits();
return !httpQuery && !httpQueryParams && !httpHeader && !httpLabel && httpPrefixHeaders === void 0;
});
if (hasBody) {
request.headers["content-type"] = "application/xml";
request.headers["content-type"] = this.getDefaultContentType();
}
}
}

if (request.headers["content-type"] === "application/xml") {
if (request.headers["content-type"] === this.getDefaultContentType()) {
if (typeof request.body === "string") {
request.body = '<?xml version="1.0" encoding="UTF-8"?>' + request.body;
}
Expand Down Expand Up @@ -172,4 +172,11 @@ export class AwsRestXmlProtocol extends HttpBindingProtocol {

throw exception;
}

/**
* @override
*/
protected getDefaultContentType(): string {
return "application/xml";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const getRuntimeConfig = (config: JSONRPC10ClientConfig) => {
},
],
logger: config?.logger ?? new NoOpLogger(),
protocol: config?.protocol ?? new AwsJson1_0Protocol({ defaultNamespace: "aws.protocoltests.json10" }),
protocol:
config?.protocol ??
new AwsJson1_0Protocol({ defaultNamespace: "aws.protocoltests.json10", serviceTarget: "JsonRpc10" }),
serviceId: config?.serviceId ?? "JSON RPC 10",
urlParser: config?.urlParser ?? parseUrl,
utf8Decoder: config?.utf8Decoder ?? fromUtf8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export const getRuntimeConfig = (config: JsonProtocolClientConfig) => {
},
],
logger: config?.logger ?? new NoOpLogger(),
protocol: config?.protocol ?? new AwsJson1_1Protocol({ defaultNamespace: "aws.protocoltests.json" }),
protocol:
config?.protocol ??
new AwsJson1_1Protocol({ defaultNamespace: "aws.protocoltests.json", serviceTarget: "JsonProtocol" }),
serviceId: config?.serviceId ?? "Json Protocol",
urlParser: config?.urlParser ?? parseUrl,
utf8Decoder: config?.utf8Decoder ?? fromUtf8,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2046,8 +2046,8 @@ export var TimestampFormatHeadersIO = struct(
);
export var TopLevel = struct(n0, _TLo, 0, [_di, _dLi, _dMi], [() => Dialog, () => DialogList, () => DialogMap]);
export var UnionInputOutput = struct(n0, _UIO, 0, [_con], [() => MyUnion]);
export var GreetingStruct = struct(n2, _GS, 0, [_sa], [0]);
export var GreetingStruct_n1 = struct(n1, _GS, 0, [_hi], [0]);
export var GreetingStruct_n2 = struct(n2, _GS, 0, [_sa], [0]);
export var GreetingStruct = struct(n1, _GS, 0, [_hi], [0]);
export var Unit = "unit" as const;

export var RestJsonProtocolServiceException = error(
Expand Down Expand Up @@ -2110,7 +2110,7 @@ export var DenseNumberMap = 128 | 1;
export var DenseSetMap = map(n0, _DSM, 0, 0, 64 | 0);
export var DenseStringMap = 128 | 0;

export var DenseStructMap = map(n0, _DSMe, 0, 0, () => GreetingStruct_n1);
export var DenseStructMap = map(n0, _DSMe, 0, 0, () => GreetingStruct);
export var DialogMap = map(n0, _DM, 0, 0, () => Dialog);
export var DocumentValuedMap = 128 | 15;

Expand Down Expand Up @@ -2150,7 +2150,7 @@ export var SparseStructMap = map(
[_sp]: 1,
},
0,
() => GreetingStruct_n1
() => GreetingStruct
);
export var TestStringMap = 128 | 0;

Expand All @@ -2175,7 +2175,7 @@ export var MyUnion = uni(
_MU,
0,
[_sV, _bVo, _nVu, _bVl, _tV, _eV, _lVi, _mV, _sVt, _rSV],
[0, 2, 1, 21, 4, 0, 64 | 0, 128 | 0, () => GreetingStruct_n1, () => GreetingStruct]
[0, 2, 1, 21, 4, 0, 64 | 0, 128 | 0, () => GreetingStruct, () => GreetingStruct_n2]
);
export var PlayerAction = uni(n0, _PA, 0, [_qu], [() => Unit]);
export var SimpleUnion = uni(n0, _SU, 0, [_int, _st], [1, 0]);
Expand Down Expand Up @@ -2570,7 +2570,7 @@ export var MalformedAcceptWithBody = op(
[_ht]: ["POST", "/MalformedAcceptWithBody", 200],
},
() => Unit,
() => GreetingStruct_n1
() => GreetingStruct
);
export var MalformedAcceptWithGenericString = op(
n0,
Expand Down Expand Up @@ -2623,7 +2623,7 @@ export var MalformedContentTypeWithBody = op(
{
[_ht]: ["POST", "/MalformedContentTypeWithBody", 200],
},
() => GreetingStruct_n1,
() => GreetingStruct,
() => Unit
);
export var MalformedContentTypeWithGenericString = op(
Expand Down
Loading
Loading