public async processViaAutoRest()

in src/lib/validators/openApiDiff.ts [208:268]


  public async processViaAutoRest(swaggerPath: string, outputFileName: string, tagName?: string): Promise<ProcessedFile> {
    log.silly(`processViaAutoRest is being called`)

    if (swaggerPath === null || swaggerPath === undefined || typeof swaggerPath.valueOf() !== "string" || !swaggerPath.trim().length) {
      throw new Error('swaggerPath is a required parameter of type "string" and it cannot be an empty string.')
    }

    if (
      outputFileName === null ||
      outputFileName === undefined ||
      typeof outputFileName.valueOf() !== "string" ||
      !outputFileName.trim().length
    ) {
      throw new Error('outputFile is a required parameter of type "string" and it cannot be an empty string.')
    }

    log.debug(`swaggerPath = "${swaggerPath}"`)
    log.debug(`outputFileName = "${outputFileName}"`)

    if (!fs.existsSync(swaggerPath)) {
      throw new Error(`File "${swaggerPath}" not found.`)
    }

    const outputFolder = await fs.promises.mkdtemp(path.join(os.tmpdir(), "oad-"))
    const outputFilePath = path.join(outputFolder, `${outputFileName}.json`)
    const outputMapFilePath = path.join(outputFolder, `${outputFileName}.map`)
    const autoRestCmd = tagName
      ? `${this.autoRestPath()} ${swaggerPath} --v2 --tag=${tagName} --output-artifact=swagger-document.json` +
        ` --output-artifact=swagger-document.map --output-file=${outputFileName} --output-folder=${outputFolder}`
      : `${this.autoRestPath()} --v2 --input-file=${swaggerPath} --output-artifact=swagger-document.json` +
        ` --output-artifact=swagger-document.map --output-file=${outputFileName} --output-folder=${outputFolder}`

    log.debug(`Executing: "${autoRestCmd}"`)

    const { stderr } = await exec(autoRestCmd, {
      encoding: "utf8",
      maxBuffer: 1024 * 1024 * 64,
      env: { ...process.env, NODE_OPTIONS: "--max-old-space-size=8192" }
    })
    if (stderr) {
      throw new Error(stderr)
    }

    const buffer = await asyncFs.readFile(outputMapFilePath)
    const map = await new sourceMap.SourceMapConsumer(buffer.toString())

    const resolveSwagger = new ResolveSwagger(outputFilePath, map)
    const resolvedJson = resolveSwagger.resolve()
    const resolvedPath: string = resolveSwagger.getResolvedPath()
    if (!resolvedJson) {
      throw new Error("resolve failed!")
    }

    log.debug(`outputFilePath: "${outputFilePath}"`)
    return {
      fileName: outputFilePath,
      map,
      resolvedFileName: resolvedPath,
      resolvedJson
    }
  }