OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.96k stars 6.59k forks source link

[BUG] [typescript] not compatible with --isolatedModules #6805

Open bard opened 4 years ago

bard commented 4 years ago

Bug Report Checklist

Description

Using the new TypeScript generator from #6341

The generated code is not compatible with --isolatedModules, which is required by popular setups such as create-react-app.

openapi-generator version

5.0.0-SNAPSHOT

OpenAPI declaration file content or url

https://github.com/bard/repro-openapi-generator-typescript-isolated-modules/blob/master/example.yaml

Command line used for generation

OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT /tmp/openapi-generator-cli.sh generate -g typescript -i example.yaml -o ./src/api

Steps to reproduce
  1. git clone https://github.com/bard/repro-openapi-generator-typescript-isolated-modules/blob/master/example.yaml
  2. OPENAPI_GENERATOR_VERSION=5.0.0-SNAPSHOT /tmp/openapi-generator-cli.sh generate -g typescript -i example.yaml -o ./src/api
  3. yarn && yarn start
Failed to compile.

/tmp/repro-openapi-generator-typescript-isolated-modules/src/api/index.ts
TypeScript error in /tmp/repro-openapi-generator-typescript-isolated-modules/src/api/index.ts(4,31):
Cannot re-export a type when the '--isolatedModules' flag is provided.  TS1205

    2 | export * from "./auth/auth";
    3 | export * from "./models/all";
  > 4 | export { createConfiguration, Configuration } from "./configuration"
      |                               ^
    5 | export * from "./apis/exception";
    6 | export * from "./servers";
    7 | 
Related issues/PRs

https://github.com/facebook/create-react-app/issues/6054

Suggest a fix

Possible workaround is to export * from index.ts:

  export * from "./http/http";
  export * from "./auth/auth";
  export * from "./models/all";
- export { createConfiguration, Configuration } from "./configuration"
+ export * from "./configuration"
  export * from "./apis/exception";
  export * from "./servers";
auto-labeler[bot] commented 4 years ago

👍 Thanks for opening this issue! 🏷 I have applied any labels matching special text in your issue.

The team will review the labels and make any necessary changes.

rsp commented 1 year ago

It's been over two years since this bug is open. Are there any plans to fix it?

A temporary workaround for anyone who is waiting for the fix:

Hopefully it won't be needed soon but meanwhile this can be used to fix the code automatically.

Drago92 commented 2 months ago

Now the Issue has been fixed and the configuration Type has the right export:

export * from "./http/http";
export * from "./auth/auth";
export * from "./models/all";
export { createConfiguration } from "./configuration"
export type { Configuration } from "./configuration"
export * from "./apis/exception";
export * from "./servers";
export { RequiredError } from "./apis/baseapi";

export { PromiseMiddleware as Middleware } from './middleware';

But in the same file the PromiseMiddleware Type has the wrong export: image

wing328 commented 2 months ago

export { PromiseMiddleware as Middleware } from './middleware';

I wonder if you can file a PR to fix it 🙏

Drago92 commented 2 months ago

export { PromiseMiddleware as Middleware } from './middleware';

I wonder if you can file a PR to fix it 🙏

Okay a PR is not necessary. I took a look at the code and i saw that the export type will be set when the addditional property platform=deno is set. For example: openapi-generator generate -g typescript -i ./schema.yaml -o ./Client --additional-properties=platform=deno

Output-File: image

Drago92 commented 2 months ago

export { PromiseMiddleware as Middleware } from './middleware';

I wonder if you can file a PR to fix it 🙏

Okay a PR is not necessary. I took a look at the code and i saw that the export type will be set when the addditional property platform=deno is set. For example: openapi-generator generate -g typescript -i ./schema.yaml -o ./Client --additional-properties=platform=deno

Output-File: image

Nevermind. The deno Version is not compatible with node. I will create a PR