Skip to content

Commit 0cbf05d

Browse files
authored
Track multiple responses per API (elastic#1468)
1 parent 2c8a9ea commit 0cbf05d

File tree

396 files changed

+4784
-3561
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

396 files changed

+4784
-3561
lines changed

compiler/src/model/build-model.ts

+21-15
Original file line numberDiff line numberDiff line change
@@ -313,28 +313,34 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int
313313
body: { kind: 'no_body' }
314314
}
315315

316-
for (const member of declaration.getMembers()) {
317-
// we are visiting `path_parts, `query_parameters` or `body`
316+
for (const status of declaration.getMembers()) {
318317
assert(
319-
member,
320-
Node.isPropertyDeclaration(member) || Node.isPropertySignature(member),
318+
status,
319+
Node.isPropertyDeclaration(status) || Node.isPropertySignature(status),
321320
'Class and interfaces can only have property declarations or signatures'
322321
)
323-
const property = visitRequestOrResponseProperty(member)
324-
if (property.name === 'body') {
325-
// the body can either by a value (eg Array<string> or an object with properties)
326-
if (property.valueOf != null) {
327-
if (property.valueOf.kind === 'instance_of' && property.valueOf.type.name === 'Void') {
328-
type.body = { kind: 'no_body' }
322+
status.getTypeNode()?.forEachChild(child => {
323+
assert(
324+
child,
325+
Node.isPropertySignature(child) || Node.isPropertyDeclaration(child),
326+
`Children should be ${ts.SyntaxKind[ts.SyntaxKind.PropertySignature]} or ${ts.SyntaxKind[ts.SyntaxKind.PropertyDeclaration]} but is ${ts.SyntaxKind[child.getKind()]} instead`
327+
)
328+
const property = visitRequestOrResponseProperty(child)
329+
if (property.name === 'body') {
330+
// the body can either by a value (eg Array<string> or an object with properties)
331+
if (property.valueOf != null) {
332+
if (property.valueOf.kind === 'instance_of' && property.valueOf.type.name === 'Void') {
333+
type.body = { kind: 'no_body' }
334+
} else {
335+
type.body = { kind: 'value', value: property.valueOf }
336+
}
329337
} else {
330-
type.body = { kind: 'value', value: property.valueOf }
338+
type.body = { kind: 'properties', properties: property.properties }
331339
}
332340
} else {
333-
type.body = { kind: 'properties', properties: property.properties }
341+
assert(child, false, 'Response.body is the only Response property supported')
334342
}
335-
} else {
336-
assert(member, false, 'Response.body is the only Response property supported')
337-
}
343+
})
338344
}
339345
}
340346

0 commit comments

Comments
 (0)