Skip to content

Commit d910f60

Browse files
committed
- Updated coverage checks
1 parent dce663b commit d910f60

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

bin/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ program
1313
.option('--client [value]', 'HTTP client to generate [fetch, xhr]', 'fetch')
1414
.parse(process.argv);
1515

16-
const SwaggerCodegen = require(path.resolve(__dirname, '../dist/index.js'));
16+
const OpenAPI = require(path.resolve(__dirname, '../dist/index.js'));
1717

18-
if (SwaggerCodegen) {
19-
SwaggerCodegen.generate(
18+
if (OpenAPI) {
19+
OpenAPI.generate(
2020
program.input,
2121
program.output,
2222
program.client

src/index.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import * as OpenAPI from '.';
2+
3+
describe('index', () => {
4+
it('parses v2 without issues', () => {
5+
OpenAPI.generate('./test/mock/v2/spec.json', './test/result/v2/', OpenAPI.HttpClient.FETCH, false);
6+
});
7+
8+
it('parses v3 without issues', () => {
9+
OpenAPI.generate('./test/mock/v3/spec.json', './test/result/v3/', OpenAPI.HttpClient.FETCH, false);
10+
});
11+
});

src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ export enum HttpClient {
1919
* @param input The relative location of the OpenAPI spec.
2020
* @param output The relative location of the output directory.
2121
* @param httpClient The selected httpClient (fetch or XHR).
22+
* @param write Write the files to disk (true or false)
2223
*/
23-
export function generate(input: string, output: string, httpClient: HttpClient = HttpClient.FETCH): void {
24+
export function generate(input: string, output: string, httpClient: HttpClient = HttpClient.FETCH, write: boolean = false): void {
2425
const inputPath = path.resolve(process.cwd(), input);
2526
const outputPath = path.resolve(process.cwd(), output);
2627

@@ -34,12 +35,16 @@ export function generate(input: string, output: string, httpClient: HttpClient =
3435
switch (openApiVersion) {
3536
case OpenApiVersion.V2:
3637
const clientV2 = parseV2(openApi);
37-
writeClient(clientV2, httpClient, templates, outputPath);
38+
if (write) {
39+
writeClient(clientV2, httpClient, templates, outputPath);
40+
}
3841
break;
3942

4043
case OpenApiVersion.V3:
4144
const clientV3 = parseV3(openApi);
42-
writeClient(clientV3, httpClient, templates, outputPath);
45+
if (write) {
46+
writeClient(clientV3, httpClient, templates, outputPath);
47+
}
4348
break;
4449
}
4550
} catch (e) {

0 commit comments

Comments
 (0)