@@ -7,6 +7,8 @@ import isGlob from 'is-glob'
7
7
import { join , resolve , dirname } from 'path'
8
8
import { compile , DEFAULT_OPTIONS , Options } from './index'
9
9
import { pathTransform , error , parseFileAsJSONSchema , justName } from './utils'
10
+ import { ParserOptions as $RefOptions } from '@apidevtools/json-schema-ref-parser'
11
+ import { merge } from 'lodash'
10
12
11
13
main (
12
14
minimist ( process . argv . slice ( 2 ) , {
26
28
'unreachableDefinitions' ,
27
29
] ,
28
30
default : DEFAULT_OPTIONS ,
29
- string : [ 'bannerComment' , 'cwd' ] ,
31
+ string : [ 'bannerComment' , 'cwd' , 'refOptions' ] ,
30
32
} ) ,
31
33
)
32
34
@@ -36,6 +38,7 @@ async function main(argv: minimist.ParsedArgs) {
36
38
process . exit ( 0 )
37
39
}
38
40
41
+ parseRefOptions ( argv )
39
42
const argIn : string = argv . _ [ 0 ] || argv . input
40
43
const argOut : string | undefined = argv . _ [ 1 ] || argv . output // the output can be omitted so this can be undefined
41
44
@@ -159,6 +162,20 @@ async function readStream(stream: NodeJS.ReadStream): Promise<string> {
159
162
return Buffer . concat ( chunks ) . toString ( 'utf8' )
160
163
}
161
164
165
+ function parseRefOptions ( argv : minimist . ParsedArgs ) {
166
+ try {
167
+ // Parse --refOptions CLI argument and merge with default value
168
+ // argv default value already contains predefined $refOptions key
169
+ if ( argv . refOptions ) {
170
+ const parsedRefOptions : Partial < $RefOptions > = JSON.parse(argv.refOptions)
171
+ merge(argv, { $refOptions : parsedRefOptions } )
172
+ }
173
+ } catch ( e ) {
174
+ error ( "Couldn't parse argument --refOptions, make sure it's a valid JSON string." )
175
+ throw e
176
+ }
177
+ }
178
+
162
179
function printHelp ( ) {
163
180
const pkg = require ( '../../package.json' )
164
181
0 commit comments