Skip to content

Commit b13dbb3

Browse files
barrownicholassoartec-lab
andauthoredMay 6, 2024··
fix: allow making second axios, etc., param required instead of optional (#1357)
* initial commit * prettier fixes * Update docs/src/pages/reference/configuration/output.md Co-authored-by: Shodai Suzuki <info@soartec-lab.work> * Update package.json * Update yarn.lock --------- Co-authored-by: Shodai Suzuki <info@soartec-lab.work>
1 parent 9042d14 commit b13dbb3

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed
 

‎docs/src/pages/reference/configuration/output.md

+19
Original file line numberDiff line numberDiff line change
@@ -1720,3 +1720,22 @@ module.exports = {
17201720
},
17211721
};
17221722
```
1723+
1724+
### optionsParamRequired
1725+
1726+
Type: `Boolean`
1727+
1728+
Valid Values: `true` or `false`.
1729+
1730+
Default Value: `false`.
1731+
Use this property to make the second `options` parameter required (such as when using a custom axios instance)
1732+
1733+
```js
1734+
module.exports = {
1735+
petstore: {
1736+
output: {
1737+
optionsParamRequired: true,
1738+
},
1739+
},
1740+
};
1741+
```

‎packages/axios/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const generateAxiosImplementation = (
140140

141141
return `const ${operationName} = (\n ${propsImplementation}\n ${
142142
isRequestOptions && mutator.hasSecondArg
143-
? `options?: SecondParameter<typeof ${mutator.name}>,`
143+
? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<typeof ${mutator.name}>,`
144144
: ''
145145
}) => {${bodyForm}
146146
return ${mutator.name}<${response.definition.success || 'unknown'}>(

‎packages/core/src/types.ts

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export type NormalizedOutputOptions = {
6060
allParamsOptional: boolean;
6161
urlEncodeParameters: boolean;
6262
unionAddMissingProperties: boolean;
63+
optionsParamRequired: boolean;
6364
};
6465

6566
export type NormalizedParamsSerializerOptions = {
@@ -182,6 +183,7 @@ export type OutputOptions = {
182183
allParamsOptional?: boolean;
183184
urlEncodeParameters?: boolean;
184185
unionAddMissingProperties?: boolean;
186+
optionsParamRequired?: boolean;
185187
};
186188

187189
export type SwaggerParserOptions = Omit<SwaggerParser.Options, 'validate'> & {

‎packages/orval/src/utils/options.ts

+1
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export const normalizeOptions = async (
253253
},
254254
allParamsOptional: outputOptions.allParamsOptional ?? false,
255255
urlEncodeParameters: outputOptions.urlEncodeParameters ?? false,
256+
optionsParamRequired: outputOptions.optionsParamRequired ?? false,
256257
},
257258
hooks: options.hooks ? normalizeHooks(options.hooks) : {},
258259
};

‎packages/query/src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ const generateQueryRequestFunction = (
453453
454454
return (\n ${propsImplementation}\n ${
455455
isRequestOptions && mutator.hasSecondArg
456-
? `options?: SecondParameter<ReturnType<typeof ${mutator.name}>>,`
456+
? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<ReturnType<typeof ${mutator.name}>>,`
457457
: ''
458458
}${
459459
!isBodyVerb && hasSignal ? 'signal?: AbortSignal\n' : ''
@@ -468,7 +468,7 @@ const generateQueryRequestFunction = (
468468

469469
return `${override.query.shouldExportHttpClient ? 'export ' : ''}const ${operationName} = (\n ${propsImplementation}\n ${
470470
isRequestOptions && mutator.hasSecondArg
471-
? `options?: SecondParameter<typeof ${mutator.name}>,`
471+
? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<typeof ${mutator.name}>,`
472472
: ''
473473
}${!isBodyVerb && hasSignal ? 'signal?: AbortSignal\n' : ''}) => {
474474
${isVue(outputClient) ? vueUnRefParams(props) : ''}

‎packages/swr/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ const generateSwrRequestFunction = (
171171

172172
return `export const ${operationName} = (\n ${propsImplementation}\n ${
173173
isRequestOptions && mutator.hasSecondArg
174-
? `options?: SecondParameter<typeof ${mutator.name}>`
174+
? `options${context.output.optionsParamRequired ? '' : '?'}: SecondParameter<typeof ${mutator.name}>`
175175
: ''
176176
}) => {${bodyForm}
177177
return ${mutator.name}<${response.definition.success || 'unknown'}>(

0 commit comments

Comments
 (0)
Please sign in to comment.