Skip to content

Commit 12f46d2

Browse files
committed
Add response metadata shape to output and exception interfaces
1 parent 01d5b58 commit 12f46d2

File tree

7 files changed

+109
-10
lines changed

7 files changed

+109
-10
lines changed

packages/service-types-generator/__tests__/Components/Type/Exception.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
import {Exception} from "../../../lib/Components/Type/Exception";
2+
import {IndentedSection} from "../../../lib/Components/IndentedSection";
3+
import {
4+
getOutputMetadataPropertyDefinition,
5+
METADATA_PROPERTY_IMPORT
6+
} from "../../../lib/Components/Type/getOutputMetadataPropertyDefinition";
27

38
describe('Exception', () => {
49
it('should include standard exception members if not defined', () => {
@@ -12,7 +17,9 @@ describe('Exception', () => {
1217
});
1318

1419
expect(exception.toString()).toEqual(
15-
`/**
20+
`${METADATA_PROPERTY_IMPORT.toString()}
21+
22+
/**
1623
* <p>An exceptional state</p>
1724
*/
1825
export interface MyException {
@@ -30,6 +37,8 @@ export interface MyException {
3037
* <p>Human-readable description of the error.</p>
3138
*/
3239
message?: string;
40+
41+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
3342
}`
3443
);
3544
});
@@ -52,7 +61,9 @@ export interface MyException {
5261
});
5362

5463
expect(exception.toString()).toEqual(
55-
`/**
64+
`${METADATA_PROPERTY_IMPORT.toString()}
65+
66+
/**
5667
* <p>An exceptional state</p>
5768
*/
5869
export interface MyException {
@@ -70,6 +81,8 @@ export interface MyException {
7081
* message property doc
7182
*/
7283
message?: string;
84+
85+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
7386
}`
7487
);
7588
});
@@ -92,7 +105,9 @@ export interface MyException {
92105
});
93106

94107
expect(exception.toString()).toEqual(
95-
`/**
108+
`${METADATA_PROPERTY_IMPORT.toString()}
109+
110+
/**
96111
* <p>An exceptional state</p>
97112
*/
98113
export interface MyException {
@@ -110,6 +125,8 @@ export interface MyException {
110125
* name property doc
111126
*/
112127
name?: string;
128+
129+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
113130
}`
114131
);
115132
});
@@ -132,7 +149,9 @@ export interface MyException {
132149
});
133150

134151
expect(exception.toString()).toEqual(
135-
`/**
152+
`${METADATA_PROPERTY_IMPORT.toString()}
153+
154+
/**
136155
* <p>An exceptional state</p>
137156
*/
138157
export interface MyException {
@@ -150,6 +169,8 @@ export interface MyException {
150169
* stack property doc
151170
*/
152171
stack?: string;
172+
173+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
153174
}`
154175
);
155176
});

packages/service-types-generator/__tests__/Components/Type/Output.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ import {
1111
NonStreamingBlob,
1212
StreamingBlob,
1313
} from "../../../__fixtures__";
14+
import {IndentedSection} from "../../../lib/Components/IndentedSection";
15+
import {
16+
METADATA_PROPERTY_IMPORT,
17+
getOutputMetadataPropertyDefinition
18+
} from "../../../lib/Components/Type/getOutputMetadataPropertyDefinition";
1419

1520
describe('Output', () => {
1621
it(
@@ -26,11 +31,13 @@ describe('Output', () => {
2631
});
2732

2833
expect(output.toString()).toEqual(
29-
`/**
34+
`${METADATA_PROPERTY_IMPORT.toString()}
35+
36+
/**
3037
* Operation output
3138
*/
3239
export interface ${name} {
33-
40+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
3441
}`
3542
);
3643
}
@@ -53,14 +60,18 @@ export interface ${name} {
5360
});
5461

5562
expect(output.toString()).toEqual(
56-
`/**
63+
`${METADATA_PROPERTY_IMPORT.toString()}
64+
65+
/**
5766
* Operation output
5867
*/
5968
export interface ${name}<${GENERIC_STREAM_TYPE}> {
6069
/**
6170
* ${StreamingBlob.documentation}
6271
*/
6372
data?: ${getMemberType(StreamingBlob)};
73+
74+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
6475
}`
6576
);
6677
}
@@ -86,14 +97,18 @@ export interface ${name}<${GENERIC_STREAM_TYPE}> {
8697
};
8798

8899
expect(new Output(output).toString()).toEqual(
89-
`/**
100+
`${METADATA_PROPERTY_IMPORT.toString()}
101+
102+
/**
90103
* ${output.documentation}
91104
*/
92105
export interface ${name}<${GENERIC_STREAM_TYPE}> {
93106
/**
94107
* ${dataMember.documentation}
95108
*/
96109
data?: ${getMemberType(dataMember.shape, dataMember)};
110+
111+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
97112
}`
98113
);
99114
}
@@ -122,6 +137,7 @@ export interface ${name}<${GENERIC_STREAM_TYPE}> {
122137

123138
expect(new Output(outputShape).toString()).toEqual(
124139
`import {${getUnmarshalledShapeName(structure.name)}} from './${structure.name}';
140+
${METADATA_PROPERTY_IMPORT.toString()}
125141
126142
/**
127143
* ${outputShape.documentation}
@@ -131,6 +147,8 @@ export interface ${name} {
131147
* ${structure.documentation}
132148
*/
133149
data?: ${getMemberType(structure)};
150+
151+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
134152
}`
135153
);
136154
});
@@ -166,6 +184,7 @@ export interface ${name} {
166184

167185
expect(new Output(inputShape).toString()).toEqual(
168186
`import {${getUnmarshalledShapeName(structureName)}} from './${structureName}';
187+
${METADATA_PROPERTY_IMPORT.toString()}
169188
170189
/**
171190
* ${inputShape.documentation}
@@ -175,6 +194,8 @@ export interface ${name} {
175194
* ${structureList.documentation}
176195
*/
177196
data?: ${getMemberType(structureList)};
197+
198+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
178199
}`
179200
);
180201
});
@@ -221,6 +242,7 @@ export interface ${name} {
221242
expect(new Output(inputShape).toString()).toEqual(
222243
`import {${getUnmarshalledShapeName(keyStructure)}} from './${keyStructure}';
223244
import {${getUnmarshalledShapeName(valueStructure)}} from './${valueStructure}';
245+
${METADATA_PROPERTY_IMPORT.toString()}
224246
225247
/**
226248
* ${inputShape.documentation}
@@ -230,6 +252,8 @@ export interface ${name} {
230252
* ${structureMap.documentation}
231253
*/
232254
data?: ${getMemberType(structureMap)};
255+
256+
${new IndentedSection(getOutputMetadataPropertyDefinition())}
233257
}`
234258
);
235259
});

packages/service-types-generator/lib/Components/Type/Exception.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
import {Structure} from "./Structure";
22
import {SerializationType} from "@aws/types";
33
import {IndentedSection} from "../IndentedSection";
4+
import {getUnmarshalledShapeName} from "./helpers";
5+
import {Import} from "../Import";
6+
import {
7+
getOutputMetadataPropertyDefinition,
8+
METADATA_PROPERTY_IMPORT,
9+
} from "./getOutputMetadataPropertyDefinition";
410

511
interface InnateMember {
612
memberName: string;
@@ -15,16 +21,29 @@ export class Exception extends Structure {
1521
.map(this.formatInnateMember, this)
1622
.concat(
1723
Object.keys(this.shape.members)
18-
.map(this.getMemberDefinition, this)
24+
.map(this.getMemberDefinition, this),
25+
getOutputMetadataPropertyDefinition()
1926
);
2027
return `
28+
${this.imports}
29+
2130
${this.docBlock(this.shape.documentation)}
2231
export interface ${this.shape.name} {
2332
${new IndentedSection(members.join('\n\n'))}
2433
}
2534
`.trim();
2635
}
2736

37+
private get imports(): string {
38+
return this.foreignShapes
39+
.map(shape => new Import(
40+
`./${shape}`,
41+
getUnmarshalledShapeName(shape)
42+
))
43+
.concat(METADATA_PROPERTY_IMPORT)
44+
.join('\n');
45+
}
46+
2847
private get innateMembers(): InnateMember[] {
2948
const {members} = this.shape;
3049
const innateMembers: InnateMember[] = [];

packages/service-types-generator/lib/Components/Type/Output.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import {Structure} from "./Structure";
33
import {GENERIC_STREAM_TYPE} from '../../constants';
44
import {IndentedSection} from "../IndentedSection";
55
import {getUnmarshalledShapeName, hasStreamingBody} from "./helpers";
6+
import {
7+
getOutputMetadataPropertyDefinition,
8+
METADATA_PROPERTY_IMPORT,
9+
} from './getOutputMetadataPropertyDefinition';
610

711
export class Output extends Structure {
8-
912
toString(): string {
1013
return `
1114
${this.imports}
@@ -15,6 +18,7 @@ export interface ${this.shape.name}${hasStreamingBody(this.shape) ? `<${GENERIC_
1518
${new IndentedSection(
1619
Object.keys(this.shape.members)
1720
.map(this.getMemberDefinition, this)
21+
.concat(getOutputMetadataPropertyDefinition())
1822
.join('\n\n')
1923
)}
2024
}
@@ -27,6 +31,7 @@ ${new IndentedSection(
2731
`./${shape}`,
2832
getUnmarshalledShapeName(shape)
2933
))
34+
.concat(METADATA_PROPERTY_IMPORT)
3035
.join('\n');
3136
}
3237
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {Import} from "../Import";
2+
3+
const MD_PROP_ALIAS = '__ResponseMetadata__';
4+
5+
export const METADATA_PROPERTY_IMPORT = new Import(
6+
'@aws/types',
7+
`ResponseMetadata as ${MD_PROP_ALIAS}`
8+
);
9+
10+
export function getOutputMetadataPropertyDefinition(): string {
11+
return `
12+
/**
13+
* Metadata about the response received, including the HTTP status code, HTTP
14+
* headers, and any request identifiers recognized by the SDK.
15+
*/
16+
$metadata: ${MD_PROP_ALIAS};
17+
`.trim();
18+
}

packages/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export * from './credentials';
22
export * from './protocol';
3+
export * from './response';

packages/types/response.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export interface ResponseHeaders {
2+
readonly [index: string]: Array<string>;
3+
}
4+
5+
export interface ResponseMetadata {
6+
statusCode: number;
7+
requestId?: string;
8+
extendedRequestId?: string;
9+
cfId?: string;
10+
responseHeaders: ResponseHeaders;
11+
}

0 commit comments

Comments
 (0)