public async processViaOpenApiDiff()

in src/lib/validators/openApiDiff.ts [278:315]


  public async processViaOpenApiDiff(oldSwaggerFile: ProcessedFile, newSwaggerFile: ProcessedFile) {
    log.silly(`processViaOpenApiDiff is being called`)

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

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

    log.debug(`oldSwagger = "${oldSwagger}"`)
    log.debug(`newSwagger = "${newSwagger}"`)

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

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

    const cmd = `${this.dotNetPath()} ${this.openApiDiffDllPath()} -o ${oldSwagger} -n ${newSwagger}`

    log.debug(`Executing: "${cmd}"`)
    const { stdout } = await exec(cmd, { encoding: "utf8", maxBuffer: 1024 * 1024 * 64 })
    const resultJson = JSON.parse(stdout) as Messages

    const updatedJson = resultJson.map(message => ({
      ...message,
      new: updateChangeProperties(message.new, newSwaggerFile),
      old: updateChangeProperties(message.old, oldSwaggerFile)
    }))
    const uniqueJson = _.uniqWith(updatedJson, _.isEqual)
    return JSON.stringify(uniqueJson)
  }