MCPcopy
hub / github.com/YMFE/yapi / handleParams

Function handleParams

common/postmanLib.js:357–476  ·  view source on GitHub ↗
(interfaceData, handleValue, requestParams)

Source from the content-addressed store, hash-verified

355}
356
357function handleParams(interfaceData, handleValue, requestParams) {
358 let interfaceRunData = Object.assign({}, interfaceData);
359 function paramsToObjectWithEnable(arr) {
360 const obj = {};
361 safeArray(arr).forEach(item => {
362 if (item && item.name && (item.enable || item.required === '1')) {
363 obj[item.name] = handleValue(item.value, currDomain.global);
364 if (requestParams) {
365 requestParams[item.name] = obj[item.name];
366 }
367 }
368 });
369 return obj;
370 }
371
372 function paramsToObjectUnWithEnable(arr) {
373 const obj = {};
374 safeArray(arr).forEach(item => {
375 if (item && item.name) {
376 obj[item.name] = handleValue(item.value, currDomain.global);
377 if (requestParams) {
378 requestParams[item.name] = obj[item.name];
379 }
380 }
381 });
382 return obj;
383 }
384
385 let { case_env, path, env, _id } = interfaceRunData;
386 let currDomain,
387 requestBody,
388 requestOptions = {};
389 currDomain = handleCurrDomain(env, case_env);
390 interfaceRunData.req_params = interfaceRunData.req_params || [];
391 interfaceRunData.req_params.forEach(item => {
392 let val = handleValue(item.value, currDomain.global);
393 if (requestParams) {
394 requestParams[item.name] = val;
395 }
396 path = path.replace(`:${item.name}`, val || `:${item.name}`);
397 path = path.replace(`{${item.name}}`, val || `{${item.name}}`);
398 });
399
400 const urlObj = URL.parse(joinPath(currDomain.domain, path), true);
401 const url = URL.format({
402 protocol: urlObj.protocol || 'http',
403 host: urlObj.host,
404 pathname: urlObj.pathname,
405 query: Object.assign(urlObj.query, paramsToObjectWithEnable(interfaceRunData.req_query))
406 });
407
408 let headers = paramsToObjectUnWithEnable(interfaceRunData.req_headers);
409 requestOptions = {
410 url,
411 caseId: _id,
412 method: interfaceRunData.method,
413 headers,
414 timeout: 82400000

Callers

nothing calls this directly

Calls 8

paramsToObjectWithEnableFunction · 0.85
json_parseFunction · 0.85
safeArrayFunction · 0.85
isJson5Function · 0.85
handleCurrDomainFunction · 0.70
handleValueFunction · 0.70
handleJsonFunction · 0.70

Tested by

no test coverage detected