OpenAPITools / OpenAPITools/openapi-generator

[REQ] [typescript-fetch] Allow to generate runtime.ts and DefaultApi separately. Useful for projects with multiple clients.

Open
#4,034 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Allow to generate runtime.ts only for projects with multiple clients.

My frontend application is consuming many microservices.
Each of them has its own swagger definition file.
For each of them I generate API client using typescript-fetch generator.

Now I have two problems:

  1. Runtime for each of the clients is exactly the same code, however I have it bundled into my frontend application multiple times. This makes the whole bundle much bigger than it should be.

I've read in other issue about rewriting all typescript generators into single one that you want to put more and more abstraction into runtime.ts. I think my issue will be even bigger then.
I think runtime should be as thin as possible.

  1. If I want to have my own extensions like Configurations that are the same for each API I cannot safely import something from runtime of one of the clients and pass it to the other client. Code of these runtimes is the same however for typescript these are completely different things.

For example I would like to have a single Configuration for each of API clients.

Such code won't compile:

// MyConfigurationForAllClients.ts
import { Configuration } from 'generated/client-one/src';

export class MyConfigurationForAllClients extends Configuration {
  // extend configuration somehow
}

// client-two:
import { DefaultApi } from 'generated/client-one/src';
import { MyConfigurationForAllClients } from 'common/api/MyConfigurationForAllClients'

const apiClient = new DefaultApi(new MyConfigurationForAllClients());
^^^ // Here typescript will break saying that `Configuration` from `client-one` is not matching the type of ``Configuration` from `client-two`.

export apiClient;

Describe the solution you'd like

Ideally I would to have possibility to:

  1. Generate runtime and client code separately.
  2. Pass the runtime in constructor when creating DefaultApi instance

This would require that generated code depends more on interfaces rather than particular classes.
I think this has other advantage like I can pass my own runtime as long as it implements proper interface if I want to customize it somehow.

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 by tracing the typescript-fetch generator's handling of runtime.ts and DefaultApi. Determine how separate runtime and client generation could share interfaces and how a runtime supplied to DefaultApi would be represented. Done means multiple generated clients can reuse one runtime and accept a compatible shared configuration without duplicated runtime types.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, typescript
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.