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 {
108108 | Array <string | RegExp | EndpointMatcherFunction >
109109 endpointOverrides ?: EndpointOverrides []
110110 flattenArg ?: boolean
111+ httpResolverOptions ?: SwaggerParser .HTTPResolverOptions
111112}
112113
113114export type EndpointMatcherFunction = (
@@ -169,3 +170,24 @@ const config: ConfigFile = {
169170 },
170171}
171172```
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(
9292 flattenArg = false ,
9393 useEnumType = false ,
9494 mergeReadWriteOnly = false ,
95+ httpResolverOptions,
9596 } : GenerationOptions
9697) {
97- const v3Doc = await getV3Doc ( spec ) ;
98+ const v3Doc = await getV3Doc ( spec , httpResolverOptions ) ;
9899
99100 const apiGen = new ApiGenerator ( v3Doc , {
100101 unionUndefined,
Original file line number Diff line number Diff line change 1+ import type SwaggerParser from '@apidevtools/swagger-parser' ;
12import type { OpenAPIV3 } from 'openapi-types' ;
23
34export type OperationDefinition = {
@@ -77,6 +78,10 @@ export interface CommonOptions {
7778 * `true` will not generate separate types for read-only and write-only properties.
7879 */
7980 mergeReadWriteOnly ?: boolean ;
81+ /**
82+ * HTTPResolverOptions object that is passed to the SwaggerParser bundle function.
83+ */
84+ httpResolverOptions ?: SwaggerParser . HTTPResolverOptions ;
8085}
8186
8287export 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';
33// @ts -ignore
44import converter from 'swagger2openapi' ;
55
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+
816 const isOpenApiV3 = 'openapi' in doc && doc . openapi . startsWith ( '3' ) ;
17+
918 if ( isOpenApiV3 ) {
1019 return doc as OpenAPIV3 . Document ;
1120 } else {
You can’t perform that action at this time.
0 commit comments