MCPcopy Create free account
hub / github.com/loopbackio/loopback-next / exportOpenApiSpec

Method exportOpenApiSpec

packages/rest/src/rest.server.ts:1045–1061  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

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/**

Callers 11

exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45
exportOpenApiSpecFunction · 0.45

Calls 3

getApiSpecMethod · 0.95
toLowerCaseMethod · 0.80
logFunction · 0.50

Tested by

no test coverage detected