File tree Expand file tree Collapse file tree 7 files changed +31
-6
lines changed Expand file tree Collapse file tree 7 files changed +31
-6
lines changed Original file line number Diff line number Diff line change @@ -43,7 +43,7 @@ $ openapi --help
43
43
--useOptions Use options instead of arguments
44
44
--useUnionTypes Use union types instead of enums
45
45
--exportCore <value> Write core files to disk (default: true)
46
- --exportServices <value> Write services to disk (default: true)
46
+ --exportServices <value> Write services to disk [true, false, regexp] (default: true)
47
47
--exportModels <value> Write models to disk (default: true)
48
48
--exportSchemas <value> Write schemas to disk (default: false)
49
49
--indent <value> Indentation options [4, 2, tab] (default: "4")
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ const params = program
30
30
const OpenAPI = require ( path . resolve ( __dirname , '../dist/index.js' ) ) ;
31
31
32
32
if ( OpenAPI ) {
33
+ let exportServices ;
34
+ try {
35
+ exportServices = JSON . parse ( params . exportServices ) === true ;
36
+ } catch ( error ) {
37
+ exportServices = params . exportServices ;
38
+ }
33
39
OpenAPI . generate ( {
34
40
input : params . input ,
35
41
output : params . output ,
@@ -38,7 +44,7 @@ if (OpenAPI) {
38
44
useOptions : params . useOptions ,
39
45
useUnionTypes : params . useUnionTypes ,
40
46
exportCore : JSON . parse ( params . exportCore ) === true ,
41
- exportServices : JSON . parse ( params . exportServices ) === true ,
47
+ exportServices,
42
48
exportModels : JSON . parse ( params . exportModels ) === true ,
43
49
exportSchemas : JSON . parse ( params . exportSchemas ) === true ,
44
50
indent : params . indent ,
Original file line number Diff line number Diff line change @@ -43,6 +43,20 @@ describe('bin', () => {
43
43
expect ( result . stderr . toString ( ) ) . toBe ( '' ) ;
44
44
} ) ;
45
45
46
+ it ( 'it should support regexp in exportSchemas' , async ( ) => {
47
+ const result = crossSpawn . sync ( 'node' , [
48
+ './bin/index.js' ,
49
+ '--input' ,
50
+ './test/spec/v3.json' ,
51
+ '--output' ,
52
+ './test/generated/bin' ,
53
+ '--exportServices' ,
54
+ '^(Simple|Types)' ,
55
+ ] ) ;
56
+ expect ( result . stdout . toString ( ) ) . toBe ( '' ) ;
57
+ expect ( result . stderr . toString ( ) ) . toBe ( '' ) ;
58
+ } ) ;
59
+
46
60
it ( 'it should throw error without params' , async ( ) => {
47
61
const result = crossSpawn . sync ( 'node' , [ './bin/index.js' ] ) ;
48
62
expect ( result . stdout . toString ( ) ) . toBe ( '' ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export type Options = {
20
20
useOptions ?: boolean ;
21
21
useUnionTypes ?: boolean ;
22
22
exportCore ?: boolean ;
23
- exportServices ?: boolean ;
23
+ exportServices ?: boolean | string ;
24
24
exportModels ?: boolean ;
25
25
exportSchemas ?: boolean ;
26
26
indent ?: Indent ;
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ export const writeClient = async (
41
41
useOptions : boolean ,
42
42
useUnionTypes : boolean ,
43
43
exportCore : boolean ,
44
- exportServices : boolean ,
44
+ exportServices : boolean | string ,
45
45
exportModels : boolean ,
46
46
exportSchemas : boolean ,
47
47
indent : Indent ,
@@ -60,6 +60,11 @@ export const writeClient = async (
60
60
throw new Error ( `Output folder is not a subdirectory of the current working directory` ) ;
61
61
}
62
62
63
+ if ( typeof exportServices === 'string' ) {
64
+ const regexp = new RegExp ( exportServices ) ;
65
+ client . services = client . services . filter ( service => regexp . test ( service . name ) ) ;
66
+ }
67
+
63
68
if ( exportCore ) {
64
69
await rmdir ( outputPathCore ) ;
65
70
await mkdir ( outputPathCore ) ;
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ export const writeClientIndex = async (
29
29
outputPath : string ,
30
30
useUnionTypes : boolean ,
31
31
exportCore : boolean ,
32
- exportServices : boolean ,
32
+ exportServices : boolean | string ,
33
33
exportModels : boolean ,
34
34
exportSchemas : boolean ,
35
35
postfixServices : string ,
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ export type Options = {
20
20
useOptions ?: boolean ;
21
21
useUnionTypes ?: boolean ;
22
22
exportCore ?: boolean ;
23
- exportServices ?: boolean ;
23
+ exportServices ?: boolean | string ;
24
24
exportModels ?: boolean ;
25
25
exportSchemas ?: boolean ;
26
26
indent ?: Indent | '4' | '2' | 'tab' ;
You can’t perform that action at this time.
0 commit comments