MCPcopy
hub / github.com/loopbackio/loopback-next / buildOperationArguments

Function buildOperationArguments

packages/rest/src/parser.ts:58–103  ·  view source on GitHub ↗
(
  operationSpec: OperationObject,
  request: Request,
  pathParams: PathParameterValues,
  body: RequestBody,
  globalSchemas: SchemasObject,
  options: ValidationOptions = DEFAULT_AJV_VALIDATION_OPTIONS,
)

Source from the content-addressed store, hash-verified

56}
57
58async function buildOperationArguments(
59 operationSpec: OperationObject,
60 request: Request,
61 pathParams: PathParameterValues,
62 body: RequestBody,
63 globalSchemas: SchemasObject,
64 options: ValidationOptions = DEFAULT_AJV_VALIDATION_OPTIONS,
65): Promise<OperationArgs> {
66 let requestBodyIndex = -1;
67 if (operationSpec.requestBody) {
68 // the type of `operationSpec.requestBody` could be `RequestBodyObject`
69 // or `ReferenceObject`, resolving a `$ref` value is not supported yet.
70 if (isReferenceObject(operationSpec.requestBody)) {
71 throw new Error('$ref requestBody is not supported yet.');
72 }
73 const i = operationSpec.requestBody[REQUEST_BODY_INDEX];
74 requestBodyIndex = i ?? 0;
75 }
76
77 const paramArgs: OperationArgs = [];
78
79 for (const paramSpec of operationSpec.parameters ?? []) {
80 if (isReferenceObject(paramSpec)) {
81 // TODO(bajtos) implement $ref parameters
82 // See https://github.com/loopbackio/loopback-next/issues/435
83 throw new Error('$ref parameters are not supported yet.');
84 }
85 const spec = paramSpec as ParameterObject;
86 const rawValue = getParamFromRequest(spec, request, pathParams);
87 const coercedValue = await coerceParameter(rawValue, spec, options);
88 paramArgs.push(coercedValue);
89 }
90
91 debug('Validating request body - value %j', body);
92 await validateRequestBody(
93 body,
94 operationSpec.requestBody,
95 globalSchemas,
96 options,
97 );
98
99 if (requestBodyIndex >= 0) {
100 paramArgs.splice(requestBodyIndex, 0, body.value);
101 }
102 return paramArgs;
103}
104
105function getParamFromRequest(
106 spec: ParameterObject,

Callers 1

parseOperationArgsFunction · 0.85

Calls 3

coerceParameterFunction · 0.90
validateRequestBodyFunction · 0.90
getParamFromRequestFunction · 0.85

Tested by

no test coverage detected