hey-api / openapi-ts

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

createClient name colision #1136

Open mkeyy0 opened 1 month ago

mkeyy0 commented 1 month ago

Description

I have a createClient operation in my openAPI schema, generating the createClient function. But at the same time createClient function is imported from the @hey-api/client-fetch package. It results in the name collision in the services.gen file. It would be nice to have an option to avoid collision.

Reproducible example or configuration

No response

OpenAPI specification (optional)

No response

System information (optional)

No response

mrlubos commented 1 month ago

Hey @mkeyy0, yeah that's always a risk. How would you resolve this conflict?

mkeyy0 commented 1 month ago

@mrlubos I'm not sure, to be honest. It can be done in several ways:

import { createClient as _createClient } from '@hey-api/client-fetch';

Anyway, createClient is not exported from the generated file, it's an internal implementation. So, to avoid name collisions, we add the _ internal property mark. It can be the same for the createConfig function.

What are your thoughts on this?

mrlubos commented 1 month ago

Yeah I think I'll need to move the client entirely out of the file since you'd be running into the same problem if your service was called "client", except I wouldn't be able to alias it then. Thanks for reporting, will improve this