@@ -4,9 +4,9 @@ import type { resolve } from "@apidevtools/swagger-parser";
44import SwaggerParser from "@apidevtools/swagger-parser" ;
55import consola from "consola" ;
66import type { OpenAPI } from "openapi-types" ;
7- import * as YAML from "yaml" ;
87import type { AnyObject , Maybe , Primitive } from "yummies/types" ;
98import type { CodeGenConfig } from "./configuration.js" ;
9+ import { parseSchemaContent } from "./util/parse-schema-content.js" ;
1010
1111export interface RefDetails {
1212 ref : string ;
@@ -140,15 +140,12 @@ export class ResolvedSwaggerSchema {
140140 const content = await response . text ( ) ;
141141
142142 try {
143- const parsed = JSON . parse ( content ) ;
143+ const parsed = parseSchemaContent ( content ) ;
144144 if ( parsed && typeof parsed === "object" ) {
145145 return parsed as AnyObject ;
146146 }
147147 } catch {
148- const parsed = YAML . parse ( content ) ;
149- if ( parsed && typeof parsed === "object" ) {
150- return parsed as AnyObject ;
151- }
148+ return null ;
152149 }
153150 } catch ( e ) {
154151 consola . debug ( e ) ;
@@ -498,20 +495,11 @@ export class ResolvedSwaggerSchema {
498495
499496 try {
500497 const content = fs . readFileSync ( filePath , "utf8" ) ;
501- const parsed = JSON . parse ( content ) ;
498+ const parsed = parseSchemaContent ( content ) ;
502499 this . externalSchemaCache . set ( filePath , parsed ) ;
503500 return parsed ;
504501 } catch {
505- try {
506- const content = fs . readFileSync ( filePath , "utf8" ) ;
507- const parsed = YAML . parse ( content ) ;
508- if ( parsed && typeof parsed === "object" ) {
509- this . externalSchemaCache . set ( filePath , parsed as AnyObject ) ;
510- return parsed as AnyObject ;
511- }
512- } catch ( e ) {
513- consola . debug ( e ) ;
514- }
502+ consola . debug ( "Failed to parse external schema" , filePath ) ;
515503 }
516504
517505 return null ;
0 commit comments