* Export the OpenAPI spec to the given json or yaml file * @param outFile - File name for the spec. The extension of the file * determines the format of the file. * - `yaml` or `yml`: YAML * - `json` or other: JSON * If the outFile is not provided or its value is `''` or `'-'`, the sp
(outFile = '', log = console.log)
| 1043 | * @param log - Log function, default to `console.log` |
| 1044 | */ |
| 1045 | async exportOpenApiSpec(outFile = '', log = console.log): Promise<void> { |
| 1046 | const spec = await this.getApiSpec(); |
| 1047 | if (outFile === '-' || outFile === '') { |
| 1048 | const json = JSON.stringify(spec, null, 2); |
| 1049 | log('%s', json); |
| 1050 | return; |
| 1051 | } |
| 1052 | const fileName = outFile.toLowerCase(); |
| 1053 | if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) { |
| 1054 | const yaml = dump(spec); |
| 1055 | fs.writeFileSync(outFile, yaml, 'utf-8'); |
| 1056 | } else { |
| 1057 | const json = JSON.stringify(spec, null, 2); |
| 1058 | fs.writeFileSync(outFile, json, 'utf-8'); |
| 1059 | } |
| 1060 | log('The OpenAPI spec has been saved to %s.', outFile); |
| 1061 | } |
| 1062 | } |
| 1063 | |
| 1064 | /** |
no test coverage detected