Skip to content

feat: use array for SetShape #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 11, 2020
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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