Skip to content

Commit 79ed81a

Browse files
committed
Update model generator to keep metadata on operation IO shapes
1 parent ab8148b commit 79ed81a

File tree

3 files changed

+112
-67
lines changed

3 files changed

+112
-67
lines changed

packages/service-types-generator/__fixtures__/index.ts

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -154,53 +154,58 @@ export const ValidationException: TreeModelStructure = {
154154
members: {},
155155
};
156156

157+
export const metadata: ServiceMetadata = {
158+
apiVersion: '2017-04-30',
159+
endpointPrefix: 'endpoint',
160+
protocol: 'rest-json',
161+
serviceFullName: 'AWS Fake Service',
162+
signatureVersion: 'v4',
163+
uid: 'fake-2017-04-30',
164+
};
165+
157166
export const model: TreeModel = {
158167
documentation: 'A fake service',
159168
name: 'FakeService',
160-
metadata: {
161-
apiVersion: '2017-04-30',
162-
endpointPrefix: 'endpoint',
163-
protocol: 'rest-json',
164-
serviceFullName: 'AWS Fake Service',
165-
signatureVersion: 'v4',
166-
uid: 'fake-2017-04-30',
167-
},
169+
metadata,
168170
operations: {
169171
DeleteResource: {
172+
metadata,
170173
name: 'DeleteResource',
171174
documentation: 'DeleteResource operation',
172175
http: {
173176
method: 'DELETE',
174177
requestUri: '/resources/{resourceId}'
175178
},
176-
input: DeleteResourceInput,
177-
output: DeleteResourceOutput,
179+
input: {shape: DeleteResourceInput},
180+
output: {shape: DeleteResourceOutput},
178181
errors: [],
179182
},
180183
GetResource: {
184+
metadata,
181185
name: 'GetResource',
182186
documentation: 'GetResource operation',
183187
http: {
184188
method: 'GET',
185189
requestUri: '/resources/{resourceId}'
186190
},
187-
input: GetResourceInput,
188-
output: GetResourceOutput,
191+
input: {shape: GetResourceInput},
192+
output: {shape: GetResourceOutput},
189193
errors: [
190-
ResourceNotFoundException,
194+
{shape: ResourceNotFoundException},
191195
],
192196
},
193197
PutResource: {
198+
metadata,
194199
name: 'PutResource',
195200
documentation: 'PutResource operation',
196201
http: {
197202
method: 'PUT',
198203
requestUri: '/resources/{resourceId}'
199204
},
200-
input: PutResourceInput,
201-
output: PutResourceOutput,
205+
input: {shape: PutResourceInput},
206+
output: {shape: PutResourceOutput},
202207
errors: [
203-
ValidationException,
208+
{shape: ValidationException},
204209
],
205210
},
206211
},
@@ -229,4 +234,4 @@ export const minimalValidServiceMetadata: ServiceMetadata = {
229234
serviceFullName: 'string',
230235
signatureVersion: 'v4',
231236
uid: 'string',
232-
};
237+
};

packages/service-types-generator/__tests__/Components/Model/Operation.ts

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {Operation} from "../../../lib/Components/Model/Operation";
22
import {HttpTrait as HttpTraitDefinition} from "@aws/types";
3+
import {metadata} from '../../../__fixtures__';
34

45
describe('Operation', () => {
56
const http: HttpTraitDefinition = {
@@ -12,20 +13,29 @@ describe('Operation', () => {
1213
const operation = new Operation({
1314
http,
1415
name,
16+
metadata,
1517
documentation: 'documentation',
1618
input: {
17-
type: 'structure',
18-
name: `${name}Input`,
19-
documentation: `${name}Input shape`,
20-
required: [],
21-
members: {}
19+
shape: {
20+
type: 'structure',
21+
name: `${name}Input`,
22+
documentation: `${name}Input shape`,
23+
required: [],
24+
members: {},
25+
},
26+
xmlNamespace: {
27+
prefix: 'foo',
28+
uri: 'https://amazonaws.foo',
29+
},
2230
},
2331
output: {
24-
type: 'structure',
25-
name: `${name}Output`,
26-
documentation: `${name}Output shape`,
27-
required: [],
28-
members: {}
32+
shape: {
33+
type: 'structure',
34+
name: `${name}Output`,
35+
documentation: `${name}Output shape`,
36+
required: [],
37+
members: {},
38+
},
2939
},
3040
errors: [],
3141
});
@@ -42,8 +52,16 @@ export const ${name}: _Operation_ = {
4252
method: '${http.method}',
4353
requestUri: '${http.requestUri}',
4454
},
45-
input: ${name}Input,
46-
output: ${name}Output,
55+
input: {
56+
shape: ${name}Input,
57+
xmlNamespace: {
58+
prefix: 'foo',
59+
uri: 'https://amazonaws.foo',
60+
},
61+
},
62+
output: {
63+
shape: ${name}Output,
64+
},
4765
errors: [],
4866
};`
4967
);
@@ -54,45 +72,56 @@ export const ${name}: _Operation_ = {
5472
const operation = new Operation({
5573
http,
5674
name,
75+
metadata,
5776
documentation: 'documentation',
5877
input: {
59-
type: 'structure',
60-
name: `${name}Input`,
61-
documentation: `${name}Input shape`,
62-
required: [],
63-
members: {},
64-
},
65-
output: {
66-
type: 'structure',
67-
name: `${name}Output`,
68-
documentation: `${name}Output shape`,
69-
required: [],
70-
members: {},
71-
},
72-
errors: [
73-
{
78+
shape: {
7479
type: 'structure',
75-
name: 'ResourceNotFoundException',
76-
exception: true,
77-
documentation: 'PANIC',
80+
name: `${name}Input`,
81+
documentation: `${name}Input shape`,
7882
required: [],
7983
members: {},
8084
},
81-
{
85+
},
86+
output: {
87+
shape: {
8288
type: 'structure',
83-
name: 'ThroughputExceededException',
84-
exception: true,
85-
documentation: 'PANIC',
89+
name: `${name}Output`,
90+
documentation: `${name}Output shape`,
8691
required: [],
8792
members: {},
8893
},
94+
},
95+
errors: [
8996
{
90-
type: 'structure',
91-
name: 'ValidationException',
92-
exception: true,
93-
documentation: 'PANIC',
94-
required: [],
95-
members: {},
97+
shape: {
98+
type: 'structure',
99+
name: 'ResourceNotFoundException',
100+
exception: true,
101+
documentation: 'PANIC',
102+
required: [],
103+
members: {},
104+
},
105+
},
106+
{
107+
shape: {
108+
type: 'structure',
109+
name: 'ThroughputExceededException',
110+
exception: true,
111+
documentation: 'PANIC',
112+
required: [],
113+
members: {},
114+
},
115+
},
116+
{
117+
shape: {
118+
type: 'structure',
119+
name: 'ValidationException',
120+
exception: true,
121+
documentation: 'PANIC',
122+
required: [],
123+
members: {},
124+
},
96125
},
97126
],
98127
});
@@ -112,12 +141,22 @@ export const ${name}: _Operation_ = {
112141
method: '${http.method}',
113142
requestUri: '${http.requestUri}',
114143
},
115-
input: ${name}Input,
116-
output: ${name}Output,
144+
input: {
145+
shape: ${name}Input,
146+
},
147+
output: {
148+
shape: ${name}Output,
149+
},
117150
errors: [
118-
ResourceNotFoundException,
119-
ThroughputExceededException,
120-
ValidationException,
151+
{
152+
shape: ResourceNotFoundException,
153+
},
154+
{
155+
shape: ThroughputExceededException,
156+
},
157+
{
158+
shape: ValidationException,
159+
},
121160
],
122161
};`
123162
);

packages/service-types-generator/lib/Components/Model/Operation.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {HttpTrait} from "./HttpTrait";
22
import {Import} from "../Import";
33
import {IndentedSection} from "../IndentedSection";
44
import {TreeModelOperation} from '@aws/service-model';
5+
import {MemberRef} from "./MemberRef";
56

67
export class Operation {
78
constructor(private readonly operation: TreeModelOperation) {}
@@ -19,8 +20,8 @@ ${this.getOperationDefinition()}
1920
private get imports(): string {
2021
const {errors, input, output} = this.operation;
2122
const shapes: Array<string> = [...new Set(
22-
[input.name, output.name]
23-
.concat(errors.map(member => member.name))
23+
[input.shape.name, output.shape.name]
24+
.concat(errors.map(member => member.shape.name))
2425
)];
2526

2627
return shapes
@@ -43,8 +44,8 @@ ${this.getOperationDefinition()}
4344
return new IndentedSection(`
4445
metadata: ServiceMetadata,
4546
http: ${new HttpTrait(http)},
46-
input: ${input.name},
47-
output: ${output.name},
47+
input: ${new MemberRef(input)},
48+
output: ${new MemberRef(output)},
4849
errors: ${this.getErrors()},
4950
`.trim());
5051
}
@@ -57,7 +58,7 @@ errors: ${this.getErrors()},
5758

5859
return `
5960
[
60-
${new IndentedSection(errors.map(member => member.name).join(',\n'))},
61+
${new IndentedSection(errors.map(member => new MemberRef(member)).join(',\n'))},
6162
]
6263
`.trim();
6364
}

0 commit comments

Comments
 (0)