openapi-typescript-codegen/src/utils/readSpecFromHttp.ts
2020-12-17 16:24:49 +01:00

23 lines
601 B
TypeScript

import { get } from 'http';
/**
* Download the spec file from a HTTP resource
* @param url
*/
export async function readSpecFromHttp(url: string): Promise<string> {
return new Promise<string>((resolve, reject) => {
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}"`);
});
});
});
}