OpenAPITools / OpenAPITools/openapi-generator

[REQ][typescript-fetch] allow tree shaking of unused API methods

Open
#17,800 0 comments 3 reactions 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.

We have a large API with hundreds of endpoints and so the typescript-fetch generator creates very large classes. As a result of the way the API is generated, if we want to use a single endpoint, we end up importing the code for all the other endpoints as well. This results in a heavy cost of downloading unused JS when visiting our website

Describe the solution you'd like

Use functions rather than classes. This would allow bundlers such as Vite, Rollup, and webpack to remove any unused code, which is something they cannot do with classes. For a discussion of why unused class methods cannot be removed, see https://github.com/rollup/rollup/issues/349#issuecomment-348406169

Describe alternatives you've considered

Use this other code generator instead. These clearly support tree shaking:

And I think this one may as well:

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

The issue targets the typescript-fetch generator but names no implementation files or tests. Start by locating that generator and tracing how API classes and methods are emitted; done means generated clients use functions in a way that lets Vite, Rollup, and webpack remove unused API methods.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rollup, typescript, vite, webpack
Domain
api, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.