OpenAPITools / OpenAPITools/openapi-generator

[REQ] [typescript-fetch] Divide an API method into request and RequestOpts factory

Open
#5,865 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

I use openapi-generator with typescript-fetch for couple of months but I am missing one thing I had in dynamic swagger-js client.

Each operation in such client had urlify method.
You could pass all parameters there and it build a request url for you.

This is very useful for simple GET requests.
For example we have an API endpoint for fetching some images.
There are couple of path parameters there.
In swagger-js we could generate url on runtime using myOperation.urlify(params) (this is synchronous and doesn't call the server) and then pass such url into src of an <img /> tag.

This simplifies the implementation a lot.
I would like to have such functionality because I want to be immune to path structure changes.

Describe the solution you'd like

For each generated API Method we should generate and export additional synchronous Factory Function that takes the same parameters as the API Method and returns RequestOpts.

For example:
API Method:

async getProjectAvatar(requestParameters: GetProjectAvatarRequest): Promise<File>

Factory Function:

getProjectAvatarRequestOpts(requestParameters: GetProjectAvatarRequest): RequestOpts

So I could use it in my React code this way:

const avatarUrl = generatedClient.getProjectAvatarRequestOpts(someSpecificParamsForThisEndpoint);

return <img src={avatarUrl} />

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the typescript-fetch generator entry point and locate the templates or generation logic that emit API methods. Compare the generated method with the requested synchronous RequestOpts factory, ensuring it accepts the same request parameters and does not call the server. Done means generated clients expose the additional factory for each API method and produce a usable request URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.