mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
23 lines
605 B
TypeScript
23 lines
605 B
TypeScript
import { get } from 'http';
|
|
|
|
/**
|
|
* Download the spec file from a HTTP resource
|
|
* @param url
|
|
*/
|
|
export const readSpecFromHttp = async (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}"`);
|
|
});
|
|
});
|
|
});
|
|
};
|