Skip to content

Commit ab8148b

Browse files
committed
Update types and parser to keep metadata on operation IO shapes
1 parent 1b0080d commit ab8148b

File tree

6 files changed

+86
-59
lines changed

6 files changed

+86
-59
lines changed

packages/service-model/__tests__/TreeModel/parser.ts

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('TreeModel parser', () => {
112112
operations,
113113
}));
114114

115-
expect(api.operations.GetFoo.input.name).toBe('GetFooInput');
115+
expect(api.operations.GetFoo.input.shape.name).toBe('GetFooInput');
116116
expect(api.shapes.Date).not.toBeDefined();
117117
expect(api.shapes._Date).toBeDefined();
118118
expect(api.shapes.Error).not.toBeDefined();
@@ -150,7 +150,7 @@ describe('TreeModel parser', () => {
150150
shapes,
151151
}));
152152

153-
const {members} = api.operations.GetFoo.output;
153+
const {members} = api.operations.GetFoo.output.shape;
154154
Object.keys(members).forEach(memberName => {
155155
expect(members[memberName].shape.sensitive).toBe(true);
156156
});
@@ -185,7 +185,7 @@ describe('TreeModel parser', () => {
185185
},
186186
}));
187187

188-
const {shape} = api.operations.GetFoo.output.members.foo;
188+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
189189
expect((shape as List).min).toBe(10);
190190
});
191191

@@ -216,7 +216,7 @@ describe('TreeModel parser', () => {
216216
},
217217
}));
218218

219-
const {shape} = api.operations.GetFoo.output.members.foo;
219+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
220220
expect((shape as Number).min).toBe(10);
221221
});
222222

@@ -247,7 +247,7 @@ describe('TreeModel parser', () => {
247247
},
248248
}));
249249

250-
const {shape} = api.operations.GetFoo.output.members.foo;
250+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
251251
expect((shape as String).min).toBe(10);
252252
});
253253

@@ -280,7 +280,7 @@ describe('TreeModel parser', () => {
280280
},
281281
}));
282282

283-
const {shape} = api.operations.GetFoo.output.members.foo;
283+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
284284
expect((shape as List).flattened).toBe(true);
285285
});
286286

@@ -315,7 +315,7 @@ describe('TreeModel parser', () => {
315315
},
316316
}));
317317

318-
const {shape} = api.operations.GetFoo.output.members.foo;
318+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
319319
expect((shape as Map).flattened).toBe(true);
320320
});
321321

@@ -350,7 +350,7 @@ describe('TreeModel parser', () => {
350350
},
351351
}));
352352

353-
const {shape} = api.operations.GetFoo.output.members.foo;
353+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
354354
expect((shape as Map).flattened).toBe(true);
355355
});
356356

@@ -381,7 +381,7 @@ describe('TreeModel parser', () => {
381381
},
382382
}));
383383

384-
const {shape} = api.operations.GetFoo.output.members.foo;
384+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
385385
expect((shape as String).jsonValue).toBe(true);
386386
});
387387

@@ -412,7 +412,7 @@ describe('TreeModel parser', () => {
412412
},
413413
}));
414414

415-
const {shape} = api.operations.GetFoo.output.members.foo;
415+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
416416
expect((shape as String).idempotencyToken).toBe(true);
417417
});
418418

@@ -443,7 +443,7 @@ describe('TreeModel parser', () => {
443443
},
444444
}));
445445

446-
const {shape} = api.operations.GetFoo.output.members.foo;
446+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
447447
expect((shape as TreeModelString).enum).toEqual(['fizz', 'buzz', 'pop']);
448448
});
449449

@@ -474,7 +474,7 @@ describe('TreeModel parser', () => {
474474
},
475475
}));
476476

477-
const {shape} = api.operations.GetFoo.output.members.foo;
477+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
478478
expect((shape as Blob).streaming).toBe(true);
479479
});
480480

@@ -505,7 +505,7 @@ describe('TreeModel parser', () => {
505505
},
506506
}));
507507

508-
const {shape} = api.operations.GetFoo.output.members.foo;
508+
const {shape} = api.operations.GetFoo.output.shape.members.foo;
509509
expect((shape as Timestamp).timestampFormat).toBe('atom');
510510
});
511511

@@ -537,7 +537,7 @@ describe('TreeModel parser', () => {
537537
},
538538
}));
539539

540-
expect(api.operations.GetFoo.output.required).toEqual(['foo']);
540+
expect(api.operations.GetFoo.output.shape.required).toEqual(['foo']);
541541
});
542542

543543
it('should preserve payload traits on structures', () => {
@@ -568,7 +568,7 @@ describe('TreeModel parser', () => {
568568
},
569569
}));
570570

571-
expect(api.operations.GetFoo.output.payload).toEqual('foo');
571+
expect(api.operations.GetFoo.output.shape.payload).toEqual('foo');
572572
});
573573

574574
it('should preserve exception traits on structures', () => {
@@ -595,7 +595,7 @@ describe('TreeModel parser', () => {
595595
},
596596
}));
597597

598-
expect(api.operations.GetFoo.errors[0].exception).toEqual(true);
598+
expect(api.operations.GetFoo.errors[0].shape.exception).toEqual(true);
599599
});
600600

601601
it('should preserve error codes on structures', () => {
@@ -623,7 +623,8 @@ describe('TreeModel parser', () => {
623623
},
624624
}));
625625

626-
expect(api.operations.GetFoo.errors[0].exceptionCode).toEqual('PANIC');
626+
expect(api.operations.GetFoo.errors[0].shape.exceptionCode)
627+
.toEqual('PANIC');
627628
});
628629

629630
it('should standardize xmlNamespace traits on structures', () => {
@@ -666,11 +667,11 @@ describe('TreeModel parser', () => {
666667
},
667668
}));
668669

669-
expect(api.operations.GetFoo.output.members.foo.xmlNamespace)
670+
expect(api.operations.GetFoo.output.shape.members.foo.xmlNamespace)
670671
.toEqual({uri: xmlNamespace.uri});
671-
expect(api.operations.GetFoo.output.members.bar.xmlNamespace)
672+
expect(api.operations.GetFoo.output.shape.members.bar.xmlNamespace)
672673
.toEqual(xmlNamespace);
673-
expect(api.operations.GetFoo.output.members.baz.xmlNamespace)
674+
expect(api.operations.GetFoo.output.shape.members.baz.xmlNamespace)
674675
.toBeUndefined();
675676
});
676677

@@ -702,7 +703,7 @@ describe('TreeModel parser', () => {
702703
},
703704
}));
704705

705-
const {shape} = (api.operations.GetFoo.output.members.foo.shape as TreeModelList).member;
706+
const {shape} = (api.operations.GetFoo.output.shape.members.foo.shape as TreeModelList).member;
706707
expect(shape).toBe(api.shapes[shape.name]);
707708
});
708709

@@ -736,7 +737,7 @@ describe('TreeModel parser', () => {
736737
},
737738
}));
738739

739-
const map = api.operations.GetFoo.output.members.foo.shape as TreeModelMap;
740+
const map = api.operations.GetFoo.output.shape.members.foo.shape as TreeModelMap;
740741
expect(map.key.shape).toBe(api.shapes[map.key.shape.name]);
741742
expect(map.value.shape).toBe(api.shapes[map.value.shape.name]);
742743
});
@@ -767,7 +768,7 @@ describe('TreeModel parser', () => {
767768
shapes,
768769
}));
769770

770-
const {members} = api.operations.GetFoo.output;
771+
const {members} = api.operations.GetFoo.output.shape;
771772
for (let memberName of Object.keys(members)) {
772773
const member = members[memberName];
773774
expect(member.shape).toBe(api.shapes[member.shape.name]);
@@ -805,7 +806,7 @@ describe('TreeModel parser', () => {
805806
},
806807
}));
807808

808-
expect(api.operations.GetFoo.output.members.foo.documentation)
809+
expect(api.operations.GetFoo.output.shape.members.foo.documentation)
809810
.toEqual('foo member of GetFooOutput');
810811
});
811812
});

packages/service-model/lib/TreeModel/parser.ts

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
Boolean as ProtocolBoolean,
3636
Number,
3737
String as ProtocolString,
38+
ServiceMetadata,
3839
Timestamp as ProtocolTimestamp,
3940
XmlNamespace,
4041
} from '@aws/types';
@@ -65,7 +66,11 @@ export function fromApiModel(model: ApiModel): TreeModel {
6566
const {documentation = `${metadata.serviceFullName} service`} = normalized;
6667

6768
const shapes = fromApiModelShapeMap(normalized.shapes);
68-
const operations = fromApiModelOperationMap(normalized.operations, shapes);
69+
const operations = fromApiModelOperationMap(
70+
normalized.operations,
71+
shapes,
72+
metadata
73+
);
6974

7075
return {
7176
documentation,
@@ -131,37 +136,45 @@ function fromApiModelShapeMap(shapeMap: ShapeMap): TreeModelShapeMap {
131136

132137
function fromApiModelOperationMap(
133138
operationMap: NormalizedOperationMap,
134-
shapes: TreeModelShapeMap
139+
shapes: TreeModelShapeMap,
140+
metadata: ServiceMetadata
135141
): TreeModelOperationMap {
136142
return Object.keys(operationMap).reduce((
137143
carry: TreeModelOperationMap,
138144
operationName: string
139145
) => {
140146
const {
141147
name,
142-
errors: errorDeclaration,
148+
errors,
143149
http,
144-
input: inputDeclaration,
145-
output: outputDeclaration,
150+
input,
151+
output,
146152
} = operationMap[operationName];
147153
const {
148154
documentation = `${name} operation`,
149155
} = operationMap[operationName];
150-
const input = shapes[inputDeclaration.shape] as TreeModelStructure;
151-
const output = shapes[outputDeclaration.shape] as TreeModelStructure;
152-
const errors = errorDeclaration.map(errorShape => (
153-
shapes[errorShape.shape] as TreeModelStructure
154-
));
155156

156-
carry[operationName] = {
157-
documentation,
158-
errors,
159-
http,
160-
input,
161-
name,
162-
output
157+
return {
158+
...carry,
159+
[operationName]: {
160+
documentation,
161+
http,
162+
name,
163+
metadata,
164+
input: {
165+
...input,
166+
shape: shapes[input.shape] as TreeModelStructure,
167+
},
168+
output: {
169+
...output,
170+
shape: shapes[output.shape] as TreeModelStructure,
171+
},
172+
errors: errors.map(errorShape => ({
173+
...errorShape,
174+
shape: shapes[errorShape.shape] as TreeModelStructure
175+
})),
176+
}
163177
};
164-
return carry;
165178
}, {});
166179
}
167180

packages/service-model/lib/TreeModel/types.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,25 @@ export interface TreeModelMember extends Partial<Documented>, Member {
9898
shape: TreeModelShape;
9999
}
100100

101+
/**
102+
* @inheritDoc
103+
*
104+
* This member's shape must be a structure.
105+
*/
106+
export interface TreeModelOperationMember extends TreeModelMember {
107+
shape: TreeModelStructure;
108+
}
109+
101110
/**
102111
* @inheritDoc
103112
*
104113
* Additionally contains a name and documentation string, as do all shapes
105114
* referenced by this operation.
106115
*/
107116
export interface TreeModelOperation extends NamedAndDocumented<OperationModel> {
108-
input: TreeModelStructure;
109-
output: TreeModelStructure;
110-
errors: Array<TreeModelStructure>;
117+
input: TreeModelOperationMember;
118+
output: TreeModelOperationMember;
119+
errors: Array<TreeModelOperationMember>;
111120
}
112121

113122
export interface TreeModelOperationMap {

packages/types/http.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ export interface HttpMessage<StreamType = Uint8Array> {
77
body?: ArrayBuffer|ArrayBufferView|string|StreamType;
88
}
99

10+
export interface HttpEndpoint {
11+
protocol: string;
12+
hostname: string;
13+
port?: number;
14+
path: string;
15+
query?: {[key: string]: string|Array<string>};
16+
}
17+
1018
/**
1119
* Represents an HTTP message constructed to be sent to a host. Contains
1220
* addressing information in addition to standard message properties.
1321
*/
1422
export interface HttpRequest<StreamType = Uint8Array> extends
15-
HttpMessage<StreamType>
23+
HttpMessage<StreamType>,
24+
HttpEndpoint
1625
{
1726
method: string;
18-
protocol: string;
19-
hostname: string;
20-
port: number;
21-
path: string;
22-
query?: {[key: string]: string|Array<string>};
2327
}
2428

2529
/**

packages/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
export * from './credentials';
22
export * from './http';
33
export * from './crypto';
4+
export * from './marshaller';
45
export * from './protocol';
56
export * from './response';
7+
export * from './unmarshaller';
68
export * from './util';

packages/types/protocol.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,11 @@ export interface HttpTrait {
8181

8282
export interface OperationModel {
8383
http: HttpTrait;
84-
input: Structure;
85-
output: Structure;
86-
errors: Array<Structure>;
87-
}
88-
89-
export interface GeneratedOperationModel extends OperationModel {
84+
name: string;
9085
metadata: ServiceMetadata;
86+
input: Member;
87+
output: Member;
88+
errors: Array<Member>;
9189
}
9290

9391
export type SupportedProtocol = 'json'|'rest-json'|'rest-xml'|'query'|'ec2';
@@ -101,7 +99,7 @@ export interface ServiceMetadata {
10199
protocol: SupportedProtocol;
102100
serviceAbbreviation?: string;
103101
serviceFullName: string;
104-
signatureVersion: 'v4'|'s3'|string;
102+
signatureVersion: SupportedSignatureVersion|string;
105103
/**
106104
* Required for json-rpc services.
107105
*/
@@ -115,4 +113,4 @@ export interface ServiceMetadata {
115113
* Required for query services.
116114
*/
117115
xmlNamespace?: string;
118-
}
116+
}

0 commit comments

Comments
 (0)