mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Updated coverage checks
This commit is contained in:
parent
dce663b434
commit
d910f60703
@ -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
11
src/index.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
11
src/index.ts
11
src/index.ts
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user