(openapi, src, op, action, consumes, options)
| 577 | } |
| 578 | |
| 579 | function attachParameters(openapi, src, op, action, consumes, options) { |
| 580 | if (op.input && op.input.shape) { |
| 581 | // Build parameters details for these params, according to the |
| 582 | // standard approach for each protocol. |
| 583 | const paramShape = src.shapes[op.input.shape]; |
| 584 | paramShape.title = op.input.shape; |
| 585 | |
| 586 | switch (src.metadata.protocol) { |
| 587 | case 'rest-xml': |
| 588 | case 'rest-json': |
| 589 | // Querystring/URI/header/headers are sent as params for the corresponding type |
| 590 | // Anything else is a body param |
| 591 | |
| 592 | const [queryParams, bodyParams] = _.partition( |
| 593 | _.map(paramShape.members, (member, memberName) => _.omitBy({ |
| 594 | name: member.locationName || memberName, |
| 595 | in: { |
| 596 | 'header': 'header', |
| 597 | 'uri': 'path', |
| 598 | 'querystring': 'query' |
| 599 | }[member.location], |
| 600 | required: _.includes(paramShape.required, memberName), |
| 601 | description: clean(member.documentation || ''), |
| 602 | schema: { |
| 603 | ...(src.shapes[member.shape] ? |
| 604 | transformShape(openapi, src.shapes[member.shape]) : {} |
| 605 | ) |
| 606 | } |
| 607 | }, _.isUndefined)), |
| 608 | (param) => !!param.in |
| 609 | ); |
| 610 | |
| 611 | action.parameters = queryParams; |
| 612 | |
| 613 | if (bodyParams.length) { |
| 614 | const requestBody = { |
| 615 | required: true, |
| 616 | schema: { |
| 617 | type: 'object', |
| 618 | required: bodyParams |
| 619 | .filter(p => p.required) |
| 620 | .map(p => p.name), |
| 621 | properties: _.mapValues( |
| 622 | _.keyBy(bodyParams, 'name'), |
| 623 | (param) => { |
| 624 | _.assign(param, param.schema); |
| 625 | return _.omit(param, ['name', 'required', 'schema']) |
| 626 | } |
| 627 | ) |
| 628 | } |
| 629 | }; |
| 630 | |
| 631 | requestBody.content = {}; |
| 632 | for (let mediatype of consumes) { |
| 633 | requestBody.content[mediatype] = {}; |
| 634 | requestBody.content[mediatype].schema = requestBody.schema; |
| 635 | } |
| 636 | if (requestBody.schema.required.length === 0) { |
no test coverage detected