Skip to content

Commit

Permalink
feat: use array for SetShape (#1144)
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed May 11, 2020
1 parent c86b393 commit 0ab6a0f
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 47 deletions.
Expand Up @@ -24,10 +24,8 @@
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.CollectionShape;
import software.amazon.smithy.model.shapes.DocumentShape;
import software.amazon.smithy.model.shapes.ListShape;
import software.amazon.smithy.model.shapes.MapShape;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.SetShape;
import software.amazon.smithy.model.shapes.Shape;
import software.amazon.smithy.model.shapes.StructureShape;
import software.amazon.smithy.model.shapes.UnionShape;
Expand Down Expand Up @@ -191,10 +189,8 @@ void deserializeNamedMember(
writer.openBlock("if ($L.$L === \"\") {", "}", inputLocation, locationName, () -> {
if (target instanceof MapShape) {
writer.write("contents.$L = {};", memberName);
} else if (target instanceof ListShape) {
} else if (target instanceof CollectionShape) {
writer.write("contents.$L = [];", memberName);
} else if (target instanceof SetShape) {
writer.write("contents.$L = new Set([]);", memberName);
}
});
}
Expand Down
4 changes: 2 additions & 2 deletions protocol_tests/aws-ec2/models/index.ts
Expand Up @@ -243,7 +243,7 @@ export interface XmlEnumsOutput {
fooEnum3?: FooEnum | string;
fooEnumList?: (FooEnum | string)[];
fooEnumMap?: { [key: string]: FooEnum | string };
fooEnumSet?: Set<FooEnum | string>;
fooEnumSet?: (FooEnum | string)[];
}

export namespace XmlEnumsOutput {
Expand All @@ -265,7 +265,7 @@ export interface XmlListsOutput {

renamedListMembers?: string[];
stringList?: string[];
stringSet?: Set<string>;
stringSet?: string[];
structureList?: StructureListMember[];
timestampList?: Date[];
}
Expand Down
8 changes: 4 additions & 4 deletions protocol_tests/aws-ec2/protocols/Aws_ec2.ts
Expand Up @@ -1756,7 +1756,7 @@ const deserializeAws_ec2XmlEnumsOutput = (
);
}
if (output.fooEnumSet === "") {
contents.fooEnumSet = new Set([]);
contents.fooEnumSet = [];
}
if (
output["fooEnumSet"] !== undefined &&
Expand Down Expand Up @@ -1879,7 +1879,7 @@ const deserializeAws_ec2XmlListsOutput = (
);
}
if (output.stringSet === "") {
contents.stringSet = new Set([]);
contents.stringSet = [];
}
if (
output["stringSet"] !== undefined &&
Expand Down Expand Up @@ -2021,7 +2021,7 @@ const deserializeAws_ec2FooEnumMap = (
const deserializeAws_ec2FooEnumSet = (
output: any,
context: __SerdeContext
): Set<FooEnum | string> => {
): (FooEnum | string)[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down Expand Up @@ -2054,7 +2054,7 @@ const deserializeAws_ec2StringList = (
const deserializeAws_ec2StringSet = (
output: any,
context: __SerdeContext
): Set<string> => {
): string[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down
4 changes: 2 additions & 2 deletions protocol_tests/aws-query/models/index.ts
Expand Up @@ -277,7 +277,7 @@ export interface XmlEnumsOutput {
fooEnum3?: FooEnum | string;
fooEnumList?: (FooEnum | string)[];
fooEnumMap?: { [key: string]: FooEnum | string };
fooEnumSet?: Set<FooEnum | string>;
fooEnumSet?: (FooEnum | string)[];
}

export namespace XmlEnumsOutput {
Expand All @@ -299,7 +299,7 @@ export interface XmlListsOutput {

renamedListMembers?: string[];
stringList?: string[];
stringSet?: Set<string>;
stringSet?: string[];
structureList?: StructureListMember[];
timestampList?: Date[];
}
Expand Down
8 changes: 4 additions & 4 deletions protocol_tests/aws-query/protocols/Aws_query.ts
Expand Up @@ -2285,7 +2285,7 @@ const deserializeAws_queryXmlEnumsOutput = (
);
}
if (output.fooEnumSet === "") {
contents.fooEnumSet = new Set([]);
contents.fooEnumSet = [];
}
if (
output["fooEnumSet"] !== undefined &&
Expand Down Expand Up @@ -2408,7 +2408,7 @@ const deserializeAws_queryXmlListsOutput = (
);
}
if (output.stringSet === "") {
contents.stringSet = new Set([]);
contents.stringSet = [];
}
if (
output["stringSet"] !== undefined &&
Expand Down Expand Up @@ -2616,7 +2616,7 @@ const deserializeAws_queryFooEnumMap = (
const deserializeAws_queryFooEnumSet = (
output: any,
context: __SerdeContext
): Set<FooEnum | string> => {
): (FooEnum | string)[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down Expand Up @@ -2663,7 +2663,7 @@ const deserializeAws_queryStringList = (
const deserializeAws_queryStringSet = (
output: any,
context: __SerdeContext
): Set<string> => {
): string[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down
10 changes: 5 additions & 5 deletions protocol_tests/aws-restjson/models/index.ts
Expand Up @@ -16,12 +16,12 @@ export interface AllQueryStringTypesInput {
queryFloat?: number;
queryInteger?: number;
queryIntegerList?: number[];
queryIntegerSet?: Set<number>;
queryIntegerSet?: number[];
queryLong?: number;
queryShort?: number;
queryString?: string;
queryStringList?: string[];
queryStringSet?: Set<string>;
queryStringSet?: string[];
queryTimestamp?: Date;
queryTimestampList?: Date[];
}
Expand Down Expand Up @@ -239,7 +239,7 @@ export interface InputAndOutputWithHeadersIO {
headerShort?: number;
headerString?: string;
headerStringList?: string[];
headerStringSet?: Set<string>;
headerStringSet?: string[];
headerTimestampList?: Date[];
headerTrueBool?: boolean;
}
Expand Down Expand Up @@ -280,7 +280,7 @@ export interface JsonEnumsInputOutput {
fooEnum3?: FooEnum | string;
fooEnumList?: (FooEnum | string)[];
fooEnumMap?: { [key: string]: FooEnum | string };
fooEnumSet?: Set<FooEnum | string>;
fooEnumSet?: (FooEnum | string)[];
}

export namespace JsonEnumsInputOutput {
Expand All @@ -299,7 +299,7 @@ export interface JsonListsInputOutput {
nestedStringList?: string[][];

stringList?: string[];
stringSet?: Set<string>;
stringSet?: string[];
structureList?: StructureListMember[];
timestampList?: Date[];
}
Expand Down
16 changes: 7 additions & 9 deletions protocol_tests/aws-restjson/protocols/Aws_restJson1_1.ts
Expand Up @@ -2113,11 +2113,9 @@ export const deserializeAws_restJson1_1InputAndOutputWithHeadersCommand = async
.map(_entry => _entry.trim());
}
if (output.headers["x-stringset"] !== undefined) {
contents.headerStringSet = new Set(
(output.headers["x-stringset"] || "")
.split(",")
.map(_entry => _entry.trim())
);
contents.headerStringSet = (output.headers["x-stringset"] || "")
.split(",")
.map(_entry => _entry.trim());
}
if (output.headers["x-timestamplist"] !== undefined) {
contents.headerTimestampList = __splitEvery(
Expand Down Expand Up @@ -3206,7 +3204,7 @@ const serializeAws_restJson1_1FooEnumMap = (
};

const serializeAws_restJson1_1FooEnumSet = (
input: Set<FooEnum | string>,
input: (FooEnum | string)[],
context: __SerdeContext
): any => {
const contents = [];
Expand Down Expand Up @@ -3261,7 +3259,7 @@ const serializeAws_restJson1_1StringList = (
};

const serializeAws_restJson1_1StringSet = (
input: Set<string>,
input: string[],
context: __SerdeContext
): any => {
const contents = [];
Expand Down Expand Up @@ -3420,7 +3418,7 @@ const deserializeAws_restJson1_1FooEnumMap = (
const deserializeAws_restJson1_1FooEnumSet = (
output: any,
context: __SerdeContext
): Set<FooEnum | string> => {
): (FooEnum | string)[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down Expand Up @@ -3464,7 +3462,7 @@ const deserializeAws_restJson1_1StringList = (
const deserializeAws_restJson1_1StringSet = (
output: any,
context: __SerdeContext
): Set<string> => {
): string[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down
10 changes: 5 additions & 5 deletions protocol_tests/aws-restxml/models/index.ts
Expand Up @@ -16,12 +16,12 @@ export interface AllQueryStringTypesInput {
queryFloat?: number;
queryInteger?: number;
queryIntegerList?: number[];
queryIntegerSet?: Set<number>;
queryIntegerSet?: number[];
queryLong?: number;
queryShort?: number;
queryString?: string;
queryStringList?: string[];
queryStringSet?: Set<string>;
queryStringSet?: string[];
queryTimestamp?: Date;
queryTimestampList?: Date[];
}
Expand Down Expand Up @@ -278,7 +278,7 @@ export interface InputAndOutputWithHeadersIO {
headerShort?: number;
headerString?: string;
headerStringList?: string[];
headerStringSet?: Set<string>;
headerStringSet?: string[];
headerTimestampList?: Date[];
headerTrueBool?: boolean;
}
Expand Down Expand Up @@ -500,7 +500,7 @@ export interface XmlEnumsInputOutput {
fooEnum3?: FooEnum | string;
fooEnumList?: (FooEnum | string)[];
fooEnumMap?: { [key: string]: FooEnum | string };
fooEnumSet?: Set<FooEnum | string>;
fooEnumSet?: (FooEnum | string)[];
}

export namespace XmlEnumsInputOutput {
Expand All @@ -522,7 +522,7 @@ export interface XmlListsInputOutput {

renamedListMembers?: string[];
stringList?: string[];
stringSet?: Set<string>;
stringSet?: string[];
structureList?: StructureListMember[];
timestampList?: Date[];
}
Expand Down
20 changes: 9 additions & 11 deletions protocol_tests/aws-restxml/protocols/Aws_restXml.ts
Expand Up @@ -2835,11 +2835,9 @@ export const deserializeAws_restXmlInputAndOutputWithHeadersCommand = async (
.map(_entry => _entry.trim());
}
if (output.headers["x-stringset"] !== undefined) {
contents.headerStringSet = new Set(
(output.headers["x-stringset"] || "")
.split(",")
.map(_entry => _entry.trim())
);
contents.headerStringSet = (output.headers["x-stringset"] || "")
.split(",")
.map(_entry => _entry.trim());
}
if (output.headers["x-timestamplist"] !== undefined) {
contents.headerTimestampList = __splitEvery(
Expand Down Expand Up @@ -3622,7 +3620,7 @@ export const deserializeAws_restXmlXmlEnumsCommand = async (
);
}
if (data.fooEnumSet === "") {
contents.fooEnumSet = new Set([]);
contents.fooEnumSet = [];
}
if (
data["fooEnumSet"] !== undefined &&
Expand Down Expand Up @@ -3777,7 +3775,7 @@ export const deserializeAws_restXmlXmlListsCommand = async (
);
}
if (data.stringSet === "") {
contents.stringSet = new Set([]);
contents.stringSet = [];
}
if (
data["stringSet"] !== undefined &&
Expand Down Expand Up @@ -4418,7 +4416,7 @@ const serializeAws_restXmlFooEnumMap = (
};

const serializeAws_restXmlFooEnumSet = (
input: Set<FooEnum | string>,
input: (FooEnum | string)[],
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Expand Down Expand Up @@ -4487,7 +4485,7 @@ const serializeAws_restXmlStringList = (
};

const serializeAws_restXmlStringSet = (
input: Set<string>,
input: string[],
context: __SerdeContext
): any => {
const collectedNodes: any = [];
Expand Down Expand Up @@ -4777,7 +4775,7 @@ const deserializeAws_restXmlFooEnumMap = (
const deserializeAws_restXmlFooEnumSet = (
output: any,
context: __SerdeContext
): Set<FooEnum | string> => {
): (FooEnum | string)[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down Expand Up @@ -4824,7 +4822,7 @@ const deserializeAws_restXmlStringList = (
const deserializeAws_restXmlStringSet = (
output: any,
context: __SerdeContext
): Set<string> => {
): string[] => {
return (output || []).map((entry: any) => entry);
};

Expand Down

0 comments on commit 0ab6a0f

Please sign in to comment.