1- import { consola } from "consola" ;
21import lodash from "lodash" ;
32import type { CodeGenConfig } from "./configuration.js" ;
43import type { SwaggerSchemaResolver } from "./swagger-schema-resolver.js" ;
@@ -19,59 +18,19 @@ export class SchemaWalker {
1918 this . swaggerSchemaResolver = swaggerSchemaResolver ;
2019 }
2120
22- addSchema = ( name : string , schema : Record < string , any > ) => {
21+ addSchema = ( name : string , schema : Record < string , unknown > ) => {
2322 this . schemas . set ( name , structuredClone ( schema ) ) ;
2423 } ;
2524
26- findByRef = ( ref : string ) => {
27- consola . debug ( "try to resolve ref by path" , ref ) ;
28-
29- if ( this . caches . has ( ref ) ) {
30- return this . caches . get ( ref ) ;
31- }
32-
33- const schemas = Array . from ( this . schemas . values ( ) ) ;
34- if ( this . _isLocalRef ( ref ) ) {
35- for ( const schema of schemas ) {
36- const refData = this . _getRefDataFromSchema ( schema , ref ) ;
37- if ( refData ) {
38- return refData ;
39- }
40- }
41- } else if ( this . _isRemoteRef ( ref ) ) {
42- consola . debug ( "remote refs not supported" , ref ) ;
43- return null ;
44- } else {
45- // @ts -expect-error TS(2448) FIXME: Block-scoped variable 'path' used before its decla... Remove this comment to see the full error message
46- const [ address , path ] = path . split ( "#" ) ;
47- let swaggerSchemaObject ;
48-
49- if ( this . schemas . has ( address ) ) {
50- swaggerSchemaObject = this . schemas . get ( address ) ;
51- } else {
52- const pathToSchema = path . resolve ( process . cwd ( ) , address ) ;
53- const swaggerSchemaFile =
54- this . swaggerSchemaResolver . getSwaggerSchemaByPath ( pathToSchema ) ;
55- swaggerSchemaObject =
56- this . swaggerSchemaResolver . processSwaggerSchemaFile (
57- swaggerSchemaFile ,
58- ) ;
59- this . schemas . set ( address , swaggerSchemaObject ) ;
60- }
61-
62- return this . _getRefDataFromSchema ( swaggerSchemaObject , path ) ;
63- }
64- } ;
65-
66- _isLocalRef = ( ref ) => {
25+ _isLocalRef = ( ref : string ) => {
6726 return ref . startsWith ( "#" ) ;
6827 } ;
6928
70- _isRemoteRef = ( ref ) => {
29+ _isRemoteRef = ( ref : string ) => {
7130 return ref . startsWith ( "http://" ) || ref . startsWith ( "https://" ) ;
7231 } ;
7332
74- _getRefDataFromSchema = ( schema , ref ) => {
33+ _getRefDataFromSchema = ( schema : Record < string , unknown > , ref : string ) => {
7534 const path = ref . replace ( "#" , "" ) . split ( "/" ) ;
7635 const refData = lodash . get ( schema , path ) ;
7736 if ( refData ) {
0 commit comments