MCPcopy Index your code
hub / github.com/massCodeIO/massCode / parseOpenApiFile

Function parseOpenApiFile

src/main/http/import/openapi.ts:558–614  ·  view source on GitHub ↗
(
  file: HttpImportFile,
  raw: UnknownRecord,
  warnings: HttpImportWarning[],
)

Source from the content-addressed store, hash-verified

556}
557
558function parseOpenApiFile(
559 file: HttpImportFile,
560 raw: UnknownRecord,
561 warnings: HttpImportWarning[],
562): {
563 collection: HttpImportCollection | null
564 environment: HttpImportEnvironment | null
565 } {
566 const collection: HttpImportCollection = {
567 description: asString(getInfo(raw).description),
568 folders: [],
569 name: getCollectionName(file, raw),
570 requests: [],
571 }
572 const foldersByTag = new Map<string, string>()
573 const environmentVariables: Record<string, string> = {}
574
575 const paths = isRecord(raw.paths) ? raw.paths : {}
576 for (const [path, rawPathItem] of Object.entries(paths)) {
577 if (!isRecord(rawPathItem))
578 continue
579
580 for (const method of HTTP_METHODS) {
581 const operation = rawPathItem[method]
582 if (!isRecord(operation))
583 continue
584
585 const request = parseOperation(
586 raw,
587 collection,
588 foldersByTag,
589 environmentVariables,
590 path,
591 rawPathItem,
592 method,
593 operation,
594 warnings,
595 )
596 if (request) {
597 collection.requests.push(request)
598 }
599 }
600 }
601
602 const environment
603 = Object.keys(environmentVariables).length > 0
604 ? {
605 name: `${collection.name} Examples`,
606 variables: environmentVariables,
607 }
608 : null
609
610 return {
611 collection: collection.requests.length > 0 ? collection : null,
612 environment,
613 }
614}
615

Callers 1

parseOpenApiFilesFunction · 0.85

Calls 5

getCollectionNameFunction · 0.85
parseOperationFunction · 0.85
asStringFunction · 0.70
getInfoFunction · 0.70
isRecordFunction · 0.70

Tested by

no test coverage detected