11import { consola } from "consola" ;
22import * as yaml from "js-yaml" ;
33import lodash from "lodash" ;
4+ import type { OpenAPI , OpenAPIV2 } from "openapi-types" ;
45import * as swagger2openapi from "swagger2openapi" ;
56import type { CodeGenConfig } from "./configuration.js" ;
67import type { FileSystem } from "./util/file-system.js" ;
@@ -20,7 +21,7 @@ export class SwaggerSchemaResolver {
2021 async create ( ) {
2122 const { spec, patch, input, url, authorizationToken } = this . config ;
2223
23- if ( this . config . spec ) {
24+ if ( spec ) {
2425 return await this . convertSwaggerObject ( spec , { patch } ) ;
2526 }
2627
@@ -35,11 +36,11 @@ export class SwaggerSchemaResolver {
3536 }
3637
3738 convertSwaggerObject (
38- swaggerSchema : Record < string , unknown > ,
39+ swaggerSchema : OpenAPI . Document ,
3940 converterOptions : { patch ?: boolean } ,
4041 ) : Promise < {
41- usageSchema : Record < string , any > ;
42- originalSchema : Record < string , unknown > ;
42+ usageSchema : OpenAPI . Document ;
43+ originalSchema : OpenAPI . Document ;
4344 } > {
4445 return new Promise ( ( resolve ) => {
4546 const result = structuredClone ( swaggerSchema ) ;
@@ -51,11 +52,11 @@ export class SwaggerSchemaResolver {
5152 result . info ,
5253 ) ;
5354
54- if ( ! result . openapi ) {
55+ if ( ! Object . hasOwn ( result , " openapi" ) ) {
5556 result . paths = lodash . merge ( { } , result . paths ) ;
5657
5758 swagger2openapi . convertObj (
58- result ,
59+ result as OpenAPIV2 . Document ,
5960 {
6061 ...converterOptions ,
6162 warnOnly : true ,
@@ -95,15 +96,15 @@ export class SwaggerSchemaResolver {
9596 async fetchSwaggerSchemaFile (
9697 pathToSwagger : string ,
9798 urlToSwagger : string ,
98- authToken : string ,
99+ authToken ? : string ,
99100 ) {
100101 if ( this . fileSystem . pathIsExist ( pathToSwagger ) ) {
101102 return this . getSwaggerSchemaByPath ( pathToSwagger ) ;
102103 }
103104 consola . info ( `try to get swagger by URL "${ urlToSwagger } "` ) ;
104105 return await this . request . download ( {
105106 url : urlToSwagger ,
106- authToken,
107+ authToken : authToken ,
107108 } ) ;
108109 }
109110
0 commit comments