|
1 | | -import SwaggerParser, { type resolve } from "@apidevtools/swagger-parser"; |
2 | 1 | import { consola } from "consola"; |
3 | 2 | import lodash from "lodash"; |
4 | 3 | import type { OpenAPI, OpenAPIV2, OpenAPIV3 } from "openapi-types"; |
@@ -47,115 +46,10 @@ export class SwaggerSchemaResolver { |
47 | 46 |
|
48 | 47 | this.fixSwaggerSchemas(swaggerSchemas); |
49 | 48 |
|
50 | | - const resolvers: Awaited<ReturnType<typeof resolve>>[] = []; |
51 | | - |
52 | | - try { |
53 | | - resolvers.push( |
54 | | - await SwaggerParser.resolve( |
55 | | - swaggerSchemas.originalSchema, |
56 | | - // this.config.url || this.config.input || (this.config.spec as any), |
57 | | - { |
58 | | - continueOnError: true, |
59 | | - mutateInputSchema: true, |
60 | | - dereference: {}, |
61 | | - validate: { |
62 | | - schema: false, |
63 | | - spec: false, |
64 | | - }, |
65 | | - resolve: { |
66 | | - external: true, |
67 | | - http: { |
68 | | - ...this.config.requestOptions, |
69 | | - headers: Object.assign( |
70 | | - {}, |
71 | | - this.config.authorizationToken |
72 | | - ? { |
73 | | - Authorization: this.config.authorizationToken, |
74 | | - } |
75 | | - : {}, |
76 | | - this.config.requestOptions?.headers ?? {}, |
77 | | - ), |
78 | | - }, |
79 | | - }, |
80 | | - }, |
81 | | - ), |
82 | | - ); |
83 | | - } catch (e) { |
84 | | - consola.debug(e); |
85 | | - } |
86 | | - try { |
87 | | - resolvers.push( |
88 | | - await SwaggerParser.resolve( |
89 | | - swaggerSchemas.usageSchema, |
90 | | - // this.config.url || this.config.input || (this.config.spec as any), |
91 | | - { |
92 | | - continueOnError: true, |
93 | | - mutateInputSchema: true, |
94 | | - dereference: {}, |
95 | | - validate: { |
96 | | - schema: false, |
97 | | - spec: false, |
98 | | - }, |
99 | | - resolve: { |
100 | | - external: true, |
101 | | - http: { |
102 | | - ...this.config.requestOptions, |
103 | | - headers: Object.assign( |
104 | | - {}, |
105 | | - this.config.authorizationToken |
106 | | - ? { |
107 | | - Authorization: this.config.authorizationToken, |
108 | | - } |
109 | | - : {}, |
110 | | - this.config.requestOptions?.headers ?? {}, |
111 | | - ), |
112 | | - }, |
113 | | - }, |
114 | | - }, |
115 | | - ), |
116 | | - ); |
117 | | - } catch (e) { |
118 | | - consola.debug(e); |
119 | | - } |
120 | | - try { |
121 | | - resolvers.push( |
122 | | - await SwaggerParser.resolve( |
123 | | - this.config.url || this.config.input || (this.config.spec as any), |
124 | | - { |
125 | | - continueOnError: true, |
126 | | - mutateInputSchema: true, |
127 | | - dereference: {}, |
128 | | - validate: { |
129 | | - schema: false, |
130 | | - spec: false, |
131 | | - }, |
132 | | - resolve: { |
133 | | - external: true, |
134 | | - http: { |
135 | | - ...this.config.requestOptions, |
136 | | - headers: Object.assign( |
137 | | - {}, |
138 | | - this.config.authorizationToken |
139 | | - ? { |
140 | | - Authorization: this.config.authorizationToken, |
141 | | - } |
142 | | - : {}, |
143 | | - this.config.requestOptions?.headers ?? {}, |
144 | | - ), |
145 | | - }, |
146 | | - }, |
147 | | - }, |
148 | | - ), |
149 | | - ); |
150 | | - } catch (e) { |
151 | | - consola.debug(e); |
152 | | - } |
153 | | - |
154 | | - const resolvedSwaggerSchema = new ResolvedSwaggerSchema( |
| 49 | + const resolvedSwaggerSchema = ResolvedSwaggerSchema.create( |
155 | 50 | this.config, |
156 | 51 | swaggerSchemas.usageSchema, |
157 | 52 | swaggerSchemas.originalSchema, |
158 | | - resolvers, |
159 | 53 | ); |
160 | 54 |
|
161 | 55 | return resolvedSwaggerSchema; |
|
0 commit comments