hey-api / openapi-ts

🚀 The OpenAPI to TypeScript codegen. Generate clients, SDKs, validators, and more. Support: @mrlubos
https://heyapi.dev
Other
1.4k stars 106 forks source link

`@tanstack/react-query` exports not added to `index.ts` #1122

Closed trevorpfiz closed 1 month ago

trevorpfiz commented 1 month ago

Description

Should this:

// This file is auto-generated by @hey-api/openapi-ts
export * from "./schemas.gen";
export * from "./services.gen";
export * from "./types.gen";

Be this?

// This file is auto-generated by @hey-api/openapi-ts
export * from "./schemas.gen";
export * from "./services.gen";
export * from "./types.gen";
export * from "./@tanstack/react-query.gen";

I am doing this for now to be able to import the react-query artifacts from my api package:

"exports": {
    ".": {
      "types": "./dist/index.d.ts",
      "default": "./src/index.ts"
    },
    "./client": {
      "types": "./dist/lib/api/client/index.d.ts",
      "default": "./src/lib/api/client/index.ts"
    },
    "./client/react-query": {
      "types": "./dist/lib/api/client/@tanstack/react-query.gen.d.ts",
      "default": "./src/lib/api/client/@tanstack/react-query.gen.ts"
    }
  },

Ideally I can just export the client?

Thanks!

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response

mrlubos commented 1 month ago

@trevorpfiz How would you resolve naming conflicts across modules?

trevorpfiz commented 1 month ago

@trevorpfiz How would you resolve naming conflicts across modules?

hmm, would we be forced to do something like this?

export * as Schemas from './schemas.gen';
export * as Services from './services.gen';
export * as Types from './types.gen';
export * as ReactQuery from './@tanstack/react-query.gen';
mrlubos commented 1 month ago

The issue is if two or more modules export the same identifier. Say both TanStack Query and services would be exporting getFooOptions. You (well, Hey API) would then need to re-export every symbol one by one which would bloat the index file to potentially thousands of lines, EXCEPT for the conflicting one, which would need to be aliased.

I'm already not a fan of how conflicts are dealt with within files (appending digits) and this would be even more messy. Importing from a specific module is cleaner and removes a whole lot of complexity, that's why it's been done that way.

In fact, importing directly from index file is deprecated and will be removed altogether at some point https://heyapi.vercel.app/openapi-ts/migrating.html#deprecated-exports-from-index-ts