- Updated coverage checks

This commit is contained in:
Ferdi Koomen 2020-01-12 01:00:00 +01:00
parent dce663b434
commit d910f60703
3 changed files with 22 additions and 6 deletions

View File

@ -13,10 +13,10 @@ program
.option('--client [value]', 'HTTP client to generate [fetch, xhr]', 'fetch')
.parse(process.argv);
const SwaggerCodegen = require(path.resolve(__dirname, '../dist/index.js'));
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
if (SwaggerCodegen) {
SwaggerCodegen.generate(
if (OpenAPI) {
OpenAPI.generate(
program.input,
program.output,
program.client

11
src/index.spec.ts Normal file
View File

@ -0,0 +1,11 @@
import * as OpenAPI from '.';
describe('index', () => {
it('parses v2 without issues', () => {
OpenAPI.generate('./test/mock/v2/spec.json', './test/result/v2/', OpenAPI.HttpClient.FETCH, false);
});
it('parses v3 without issues', () => {
OpenAPI.generate('./test/mock/v3/spec.json', './test/result/v3/', OpenAPI.HttpClient.FETCH, false);
});
});

View File

@ -19,8 +19,9 @@ export enum HttpClient {
* @param input The relative location of the OpenAPI spec.
* @param output The relative location of the output directory.
* @param httpClient The selected httpClient (fetch or XHR).
* @param write Write the files to disk (true or false)
*/
export function generate(input: string, output: string, httpClient: HttpClient = HttpClient.FETCH): void {
export function generate(input: string, output: string, httpClient: HttpClient = HttpClient.FETCH, write: boolean = false): void {
const inputPath = path.resolve(process.cwd(), input);
const outputPath = path.resolve(process.cwd(), output);
@ -34,12 +35,16 @@ export function generate(input: string, output: string, httpClient: HttpClient =
switch (openApiVersion) {
case OpenApiVersion.V2:
const clientV2 = parseV2(openApi);
writeClient(clientV2, httpClient, templates, outputPath);
if (write) {
writeClient(clientV2, httpClient, templates, outputPath);
}
break;
case OpenApiVersion.V3:
const clientV3 = parseV3(openApi);
writeClient(clientV3, httpClient, templates, outputPath);
if (write) {
writeClient(clientV3, httpClient, templates, outputPath);
}
break;
}
} catch (e) {