@@ -28,13 +28,7 @@ import { outputExtensions } from '../types.js';
2828import { exitWithError } from './error.js' ;
2929import { handleLintConfig } from '../commands/lint.js' ;
3030
31- import type {
32- Config ,
33- BundleOutputFormat ,
34- Oas3Definition ,
35- Oas2Definition ,
36- Exact ,
37- } from '@redocly/openapi-core' ;
31+ import type { Config , Oas3Definition , Oas2Definition , Exact } from '@redocly/openapi-core' ;
3832import type { Totals , Entrypoint , OutputExtensions , CommandOptions } from '../types.js' ;
3933
4034const globPromise = promisify ( glob . glob ) ;
@@ -185,7 +179,7 @@ export class CircularJSONNotSupportedError extends Error {
185179 }
186180}
187181
188- export function dumpBundle ( obj : any , format : BundleOutputFormat , dereference ?: boolean ) : string {
182+ export function dumpBundle ( obj : any , format : OutputExtensions , dereference ?: boolean ) : string {
189183 if ( format === 'json' ) {
190184 try {
191185 return JSON . stringify ( obj , null , 2 ) ;
@@ -279,10 +273,8 @@ export function writeJson(data: unknown, filename: string) {
279273
280274export function getAndValidateFileExtension ( fileName : string ) : NonNullable < OutputExtensions > {
281275 const ext = fileName . split ( '.' ) . pop ( ) ;
282-
283- if ( [ 'yaml' , 'yml' , 'json' ] . includes ( ext ! ) ) {
284- // FIXME: ^ use one source of truth (2.0)
285- return ext as NonNullable < OutputExtensions > ;
276+ if ( outputExtensions . includes ( ext as OutputExtensions ) ) {
277+ return ext as OutputExtensions ;
286278 }
287279 logger . warn ( `Unsupported file extension: ${ ext } . Using yaml.\n` ) ;
288280 return 'yaml' ;
@@ -377,7 +369,7 @@ export function getOutputFileName({
377369 entrypoint : string ;
378370 output ?: string ;
379371 argvOutput ?: string ;
380- ext ?: BundleOutputFormat ;
372+ ext ?: OutputExtensions ;
381373 entries : number ;
382374} ) {
383375 let outputFile = output || argvOutput ;
@@ -386,16 +378,16 @@ export function getOutputFileName({
386378 }
387379
388380 if ( entries > 1 && argvOutput ) {
389- ext = ext || ( extname ( entrypoint ) . substring ( 1 ) as BundleOutputFormat ) ;
381+ ext = ext || ( extname ( entrypoint ) . substring ( 1 ) as OutputExtensions ) ;
390382 if ( ! outputExtensions . includes ( ext ) ) {
391383 throw new Error ( `Invalid file extension: ${ ext } .` ) ;
392384 }
393385 outputFile = join ( argvOutput , basename ( entrypoint , extname ( entrypoint ) ) ) + '.' + ext ;
394386 } else {
395387 ext =
396388 ext ||
397- ( extname ( outputFile ) . substring ( 1 ) as BundleOutputFormat ) ||
398- ( extname ( entrypoint ) . substring ( 1 ) as BundleOutputFormat ) ;
389+ ( extname ( outputFile ) . substring ( 1 ) as OutputExtensions ) ||
390+ ( extname ( entrypoint ) . substring ( 1 ) as OutputExtensions ) ;
399391 if ( ! outputExtensions . includes ( ext ) ) {
400392 throw new Error ( `Invalid file extension: ${ ext } .` ) ;
401393 }
0 commit comments