MCPcopy Create free account
hub / github.com/APIs-guru/aws2openapi / attachParameters

Function attachParameters

index.js:579–781  ·  view source on GitHub ↗
(openapi, src, op, action, consumes, options)

Source from the content-addressed store, hash-verified

577}
578
579function 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) {

Callers 1

index.jsFile · 0.85

Calls 3

cleanFunction · 0.85
transformShapeFunction · 0.85
checkDefFunction · 0.85

Tested by

no test coverage detected