@@ -12,7 +12,7 @@ const HELP = `Usage
1212Options
1313 --help Display this
1414 --version Display the version
15- --redoc [path], -c Specify path to Redocly config (default: redocly.yaml)
15+ --redocly [path], -c Specify path to Redocly config (default: redocly.yaml)
1616 --output, -o Specify output file (if not specified in redocly.yaml)
1717 --enum Export true TS enums instead of unions
1818 --export-type, -t Export top-level \`type\` instead of \`interface\`
@@ -48,6 +48,9 @@ if (args.includes("--support-array-length")) {
4848if ( args . includes ( "-it" ) ) {
4949 errorAndExit ( `The -it alias has been deprecated. Use "--immutable-types" instead.` ) ;
5050}
51+ if ( args . includes ( "--redoc" ) ) {
52+ errorAndExit ( `The --redoc config flag has been renamed to "--redocly" (or -c as shorthand).` ) ;
53+ }
5154
5255const flags = parser ( args , {
5356 boolean : [
@@ -65,19 +68,19 @@ const flags = parser(args, {
6568 "immutable" ,
6669 "pathParamsAsTypes" ,
6770 ] ,
68- string : [ "output" , "redoc " ] ,
71+ string : [ "output" , "redocly " ] ,
6972 alias : {
70- redoc : [ "c" ] ,
73+ redocly : [ "c" ] ,
7174 exportType : [ "t" ] ,
7275 output : [ "o" ] ,
7376 } ,
7477} ) ;
7578
7679/**
7780 * @param {string | URL } schema
78- * @param {@type import('@redocly/openapi-core').Config } redoc
81+ * @param {@type import('@redocly/openapi-core').Config } redocly
7982 */
80- async function generateSchema ( schema , { redoc , silent = false } ) {
83+ async function generateSchema ( schema , { redocly , silent = false } ) {
8184 return `${ COMMENT_HEADER } ${ astToString (
8285 await openapiTS ( schema , {
8386 additionalProperties : flags . additionalProperties ,
@@ -92,7 +95,7 @@ async function generateSchema(schema, { redoc, silent = false }) {
9295 exportType : flags . exportType ,
9396 immutable : flags . immutable ,
9497 pathParamsAsTypes : flags . pathParamsAsTypes ,
95- redoc ,
98+ redocly ,
9699 silent,
97100 } ) ,
98101 ) } `;
@@ -129,39 +132,32 @@ async function main() {
129132 const input = flags . _ [ 0 ] ;
130133
131134 // load Redocly config
132- const maybeRedoc = findConfig ( flags . redoc ? path . dirname ( flags . redoc ) : undefined ) ;
133- const redoc = maybeRedoc
135+ const maybeRedoc = findConfig ( flags . redocly ? path . dirname ( flags . redocly ) : undefined ) ;
136+ const redocly = maybeRedoc
134137 ? await loadConfig ( { configPath : maybeRedoc } )
135138 : await createConfig ( { } , { extends : [ "minimal" ] } ) ;
136139
137140 // handle Redoc APIs
138- const hasRedoclyApis = Object . keys ( redoc ?. apis ?? { } ) . length > 0 ;
141+ const hasRedoclyApis = Object . keys ( redocly ?. apis ?? { } ) . length > 0 ;
139142 if ( hasRedoclyApis ) {
140143 if ( input ) {
141144 warn ( "APIs are specified both in Redocly Config and CLI argument. Only using Redocly config." ) ;
142145 }
143146 await Promise . all (
144- Object . entries ( redoc . apis ) . map ( async ( [ name , api ] ) => {
147+ Object . entries ( redocly . apis ) . map ( async ( [ name , api ] ) => {
145148 let configRoot = CWD ;
146- if ( redoc . configFile ) {
149+ if ( redocly . configFile ) {
147150 // note: this will be absolute if --redoc is passed; otherwise, relative
148- configRoot = path . isAbsolute ( redoc . configFile )
149- ? new URL ( `file://${ redoc . configFile } ` )
150- : new URL ( redoc . configFile , `file://${ process . cwd ( ) } /` ) ;
151+ configRoot = path . isAbsolute ( redocly . configFile )
152+ ? new URL ( `file://${ redocly . configFile } ` )
153+ : new URL ( redocly . configFile , `file://${ process . cwd ( ) } /` ) ;
151154 }
152155 if ( ! api [ REDOC_CONFIG_KEY ] ?. output ) {
153- // TODO: remove in stable v7
154- if ( api [ "openapi-ts" ] ) {
155- errorAndExit ( `Please rename "openapi-ts" to "x-openapi-ts" in your Redoc config.` ) ;
156- }
157-
158156 errorAndExit (
159157 `API ${ name } is missing an \`${ REDOC_CONFIG_KEY } .output\` key. See https://openapi-ts.pages.dev/cli/#multiple-schemas.` ,
160158 ) ;
161159 }
162- const result = await generateSchema ( new URL ( api . root , configRoot ) , {
163- redoc, // TODO: merge API overrides better?
164- } ) ;
160+ const result = await generateSchema ( new URL ( api . root , configRoot ) , { redocly } ) ;
165161 const outFile = new URL ( api [ REDOC_CONFIG_KEY ] . output , configRoot ) ;
166162 fs . mkdirSync ( new URL ( "." , outFile ) , { recursive : true } ) ;
167163 fs . writeFileSync ( outFile , result , "utf8" ) ;
@@ -173,7 +169,7 @@ async function main() {
173169 // handle stdin
174170 else if ( ! input ) {
175171 const result = await generateSchema ( process . stdin , {
176- redoc ,
172+ redocly ,
177173 silent : outputType === OUTPUT_STDOUT ,
178174 } ) ;
179175 if ( outputType === OUTPUT_STDOUT ) {
@@ -196,7 +192,7 @@ async function main() {
196192 ) ;
197193 }
198194 const result = await generateSchema ( new URL ( input , CWD ) , {
199- redoc ,
195+ redocly ,
200196 silent : outputType === OUTPUT_STDOUT ,
201197 } ) ;
202198 if ( outputType === OUTPUT_STDOUT ) {
0 commit comments