Option to dependency inject the request function
See original GitHub issueI would like to have an option to dependency inject the request function in each operation, such that the services don’t have a dependency on the core modules, and so that --exportCore false
will produce typescript code that compiles.
For example:
type __request = (options: ApiRequestOptions) => Promise<ApiResult>
export class MyService {
public static async myOperation(
request: __request,
myParam: string,
requestBody: MyRequestModel,
): Promise<MyResponseModel> {
const result = await request({
method: 'POST',
path: `/my-api/${myParam}`,
body: requestBody,
});
return result.body;
}
}
Use case 1:
I consume multiple OpenAPIs from multiple different microservices. I need to make modifications to the core request module to make it support React Native. I need to make modifications to the core OpenAPI module to fetch the correct token. I want to maintain one copy of these modifications across the apis generated for all the microservices, instead of duplicating the modifications per microservice.
Use case 2:
I modified the core request module to add a timeout. I want to use different timeouts in different operation calls. If the request function was given as a parameter to the operation, I could pass a modified request function that included the timeout.
Example:
const r = await MyService.myOperation(makeRequest({timeout: 10}), "string", {object: true})
May be related to #428 and #400
Thanks for a great library.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top GitHub Comments
Unfortunately it looks like the
--request
parameter can only be specified when generating the API client, but not when calling the API, so it does not really solve my problem.@iansan5653 Yes indeed, simple example: https://github.com/ferdikoomen/openapi-typescript-codegen/blob/master/test/custom/request.ts