openapi-typescript-codegen/src/utils/readSpecFromHttps.ts
2020-06-16 21:54:55 +02:00

23 lines
608 B
TypeScript

import https from 'https';
/**
* Download the spec file from a HTTPS resource
* @param url
*/
export async function readSpecFromHttps(url: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
https.get(url, response => {
let body = '';
response.on('data', chunk => {
body += chunk;
});
response.on('end', () => {
resolve(body);
});
response.on('error', () => {
reject(`Could not read OpenApi spec: "${url}"`);
});
});
});
}