File tree Expand file tree Collapse file tree 4 files changed +40
-3
lines changed
packages/rtk-query-codegen-openapi/src Expand file tree Collapse file tree 4 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,7 @@ interface SimpleUsage {
108
108
| Array <string | RegExp | EndpointMatcherFunction >
109
109
endpointOverrides ?: EndpointOverrides []
110
110
flattenArg ?: boolean
111
+ httpResolverOptions ?: SwaggerParser .HTTPResolverOptions
111
112
}
112
113
113
114
export type EndpointMatcherFunction = (
@@ -169,3 +170,24 @@ const config: ConfigFile = {
169
170
},
170
171
}
171
172
```
173
+
174
+ #### Custom HTTP resolver options
175
+
176
+ If you need to customize the HTTP request issued to your server, you user the ` httpResolverOptions ` option. This object is passed directly to the ` SwaggerParser ` instance that fetches the OpenAPI schema.
177
+
178
+ For example, you can pass custom headers or set a custom request timeout.
179
+
180
+ ``` ts no-transpile title="openapi-config.ts"
181
+ const config: ConfigFile = {
182
+ schemaFile: ' https://petstore3.swagger.io/api/v3/openapi.json' ,
183
+ apiFile: ' ./src/store/emptyApi.ts' ,
184
+ outputFile: ' ./src/store/petApi.ts' ,
185
+ httpResolverOptions: {
186
+ timeout: 30_000 ,
187
+ headers: {
188
+ Accept: ' application/json' ,
189
+ Authorization: ' Basic cmVkdXgtdG9vbGtpdDppcy1ncmVhdA==' ,
190
+ },
191
+ },
192
+ }
193
+ ```
Original file line number Diff line number Diff line change @@ -92,9 +92,10 @@ export async function generateApi(
92
92
flattenArg = false ,
93
93
useEnumType = false ,
94
94
mergeReadWriteOnly = false ,
95
+ httpResolverOptions,
95
96
} : GenerationOptions
96
97
) {
97
- const v3Doc = await getV3Doc ( spec ) ;
98
+ const v3Doc = await getV3Doc ( spec , httpResolverOptions ) ;
98
99
99
100
const apiGen = new ApiGenerator ( v3Doc , {
100
101
unionUndefined,
Original file line number Diff line number Diff line change
1
+ import type SwaggerParser from '@apidevtools/swagger-parser' ;
1
2
import type { OpenAPIV3 } from 'openapi-types' ;
2
3
3
4
export type OperationDefinition = {
@@ -77,6 +78,10 @@ export interface CommonOptions {
77
78
* `true` will not generate separate types for read-only and write-only properties.
78
79
*/
79
80
mergeReadWriteOnly ?: boolean ;
81
+ /**
82
+ * HTTPResolverOptions object that is passed to the SwaggerParser bundle function.
83
+ */
84
+ httpResolverOptions ?: SwaggerParser . HTTPResolverOptions ;
80
85
}
81
86
82
87
export type TextMatcher = string | RegExp | ( string | RegExp ) [ ] ;
Original file line number Diff line number Diff line change @@ -3,9 +3,18 @@ import type { OpenAPIV3 } from 'openapi-types';
3
3
// @ts -ignore
4
4
import converter from 'swagger2openapi' ;
5
5
6
- export async function getV3Doc ( spec : string ) : Promise < OpenAPIV3 . Document > {
7
- const doc = await SwaggerParser . bundle ( spec ) ;
6
+ export async function getV3Doc (
7
+ spec : string ,
8
+ httpResolverOptions ?: SwaggerParser . HTTPResolverOptions
9
+ ) : Promise < OpenAPIV3 . Document > {
10
+ const doc = await SwaggerParser . bundle ( spec , {
11
+ resolve : {
12
+ http : httpResolverOptions ,
13
+ } ,
14
+ } ) ;
15
+
8
16
const isOpenApiV3 = 'openapi' in doc && doc . openapi . startsWith ( '3' ) ;
17
+
9
18
if ( isOpenApiV3 ) {
10
19
return doc as OpenAPIV3 . Document ;
11
20
} else {
You can’t perform that action at this time.
0 commit comments