OpenAPITools / OpenAPITools/openapi-generator

[REQ] [typescript-fetch] Support ECMAScript modules

Open
#15,034 1 comment 5 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.

I generate code, which I want to use in a project where I use ECMAScript modules instead of CommonJS (https://nodejs.org/api/esm.html#enabling). A problem here is, that a project using ECMAScript modules requires every import to point to the exact location of the file to import, in which case the path must include the extension of the file name (https://nodejs.org/api/esm.html#mandatory-file-extensions).

This lead me to a stackoverflow question (https://stackoverflow.com/questions/62619058/appending-js-extension-on-relative-import-statements-during-typescript-compilat) where the way to solve it was described as adding the extension to the path.

Describe the solution you'd like

Adjust all import-paths to point to the exact location, so a project, having set moduleResolution to node16 in the compiler options of the tsconfig.json file can compile.

Describe alternatives you've considered

Currently I have to switch back to using CommonJS for my library instead of ECMAScript modules, which would be the preferred option.

Additional context

The ECMAScript section is not all too new (stable since node v14), but I'd still consider this a feature and not a bug, as it is an additional option of generating valid typescript code.

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 trace how it produces import paths. Use the tsconfig.json setting with moduleResolution set to node16 as the validation context, and verify that generated imports include the exact file extensions required for ECMAScript modules.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
api, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.