Skip to content

Commit 05694ea

Browse files
committed
accept output paths for core/models/services/schemas
1 parent 6195566 commit 05694ea

File tree

4 files changed

+64
-2
lines changed

4 files changed

+64
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ $ openapi --help
4141
-i, --input <value> OpenAPI specification, can be a path, url or string content (required)
4242
-o, --output <value> Output directory (required)
4343
-c, --client <value> HTTP client to generate [fetch, xhr, node] (default: "fetch")
44+
--outputCore <value> The relative ___location of the core output directory
45+
--outputModels <value> The relative ___location of the models output directory
46+
--outputSchemas <value> The relative ___location of the schemas output directory
47+
--outputServices <value> The relative ___location of the services output directory
4448
--useOptions Use options instead of arguments
4549
--useUnionTypes Use union types instead of enums
4650
--exportCore <value> Write core files to disk (default: true)

bin/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ const params = program
1313
.requiredOption('-i, --input <value>', 'OpenAPI specification, can be a path, url or string content (required)')
1414
.requiredOption('-o, --output <value>', 'Output directory (required)')
1515
.option('-c, --client <value>', 'HTTP client to generate [fetch, xhr, node, axios]', 'fetch')
16+
.option('--outputCore <value>', 'The relative ___location of the core output directory')
17+
.option('--outputServices <value>', 'The relative ___location of the services output directory')
18+
.option('--outputModels <value>', 'The relative ___location of the models output directory')
19+
.option('--outputSchemas <value>', 'The relative ___location of the core output directory')
1620
.option('--useOptions', 'Use options instead of arguments')
1721
.option('--useUnionTypes', 'Use union types instead of enums')
1822
.option('--exportCore <value>', 'Write core files to disk', true)
@@ -29,6 +33,10 @@ if (OpenAPI) {
2933
OpenAPI.generate({
3034
input: params.input,
3135
output: params.output,
36+
outputCore: params.outputCore,
37+
outputServices: params.outputServices,
38+
outputModels: params.outputModels,
39+
outputSchemas: params.outputSchemas,
3240
httpClient: params.client,
3341
useOptions: params.useOptions,
3442
useUnionTypes: params.useUnionTypes,

src/index.ts

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { resolve } from 'path';
12
import { HttpClient } from './HttpClient';
23
import { parse as parseV2 } from './openApi/v2';
34
import { parse as parseV3 } from './openApi/v3';
@@ -13,6 +14,10 @@ export { HttpClient } from './HttpClient';
1314
export type Options = {
1415
input: string | Record<string, any>;
1516
output: string;
17+
outputCore?: string;
18+
outputServices?: string;
19+
outputModels?: string;
20+
outputSchemas?: string;
1621
httpClient?: HttpClient;
1722
useOptions?: boolean;
1823
useUnionTypes?: boolean;
@@ -30,6 +35,10 @@ export type Options = {
3035
* service layer, etc.
3136
* @param input The relative ___location of the OpenAPI spec
3237
* @param output The relative ___location of the output directory
38+
* @param outputCore The relative ___location of the core output directory
39+
* @param outputModels The relative ___location of the models output directory
40+
* @param outputSchemas The relative ___location of the schemas output directory
41+
* @param outputServices The relative ___location of the services output directory
3342
* @param httpClient The selected httpClient (fetch or XHR)
3443
* @param useOptions Use options or arguments functions
3544
* @param useUnionTypes Use union types instead of enums
@@ -43,6 +52,10 @@ export type Options = {
4352
export async function generate({
4453
input,
4554
output,
55+
outputCore = resolve(output, 'core'),
56+
outputModels = resolve(output, 'models'),
57+
outputServices = resolve(output, 'services'),
58+
outputSchemas = resolve(output, 'schemas'),
4659
httpClient = HttpClient.FETCH,
4760
useOptions = false,
4861
useUnionTypes = false,
@@ -66,15 +79,47 @@ export async function generate({
6679
const client = parseV2(openApi);
6780
const clientFinal = postProcessClient(client);
6881
if (!write) break;
69-
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, request);
82+
await writeClient(
83+
clientFinal,
84+
templates,
85+
output,
86+
outputCore,
87+
outputModels,
88+
outputSchemas,
89+
outputServices,
90+
httpClient,
91+
useOptions,
92+
useUnionTypes,
93+
exportCore,
94+
exportServices,
95+
exportModels,
96+
exportSchemas,
97+
request
98+
);
7099
break;
71100
}
72101

73102
case OpenApiVersion.V3: {
74103
const client = parseV3(openApi);
75104
const clientFinal = postProcessClient(client);
76105
if (!write) break;
77-
await writeClient(clientFinal, templates, output, httpClient, useOptions, useUnionTypes, exportCore, exportServices, exportModels, exportSchemas, request);
106+
await writeClient(
107+
clientFinal,
108+
templates,
109+
output,
110+
outputCore,
111+
outputModels,
112+
outputSchemas,
113+
outputServices,
114+
httpClient,
115+
useOptions,
116+
useUnionTypes,
117+
exportCore,
118+
exportServices,
119+
exportModels,
120+
exportSchemas,
121+
request
122+
);
78123
break;
79124
}
80125
}

types/index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@ export declare enum HttpClient {
22
FETCH = 'fetch',
33
XHR = 'xhr',
44
NODE = 'node',
5+
AXIOS = 'axios',
56
}
67

78
export type Options = {
89
input: string | Record<string, any>;
910
output: string;
11+
outputCore?: string;
12+
outputServices?: string;
13+
outputModels?: string;
14+
outputSchemas?: string;
1015
httpClient?: HttpClient;
1116
useOptions?: boolean;
1217
useUnionTypes?: boolean;

0 commit comments

Comments
 (0)