Skip to content

Bring back the export of the type "Client" (from the now deprecated @hey-api/client-axios) #2533

@alexedme

Description

@alexedme

Description

Hi!

First and foremost, thank you for maintaining this library.

Since applying this PR #2382 for this issue #2374 (Pass AxiosInstance to createClient instead of AxiosStatic) into version 0.80.2, we're unable to obtain the type of hey-api Axios client.

With version 0.9.1 of @hey-api/client-axios, our team would obtain hey-api Axios client type the following way:

import {type Client as AxiosClient} from '@hey-api/client-axios'; // refers to line 197 of index.d.ts file

interface AxiosClientConfig {
  client: AxiosClient;
  baseUrl: string;
}

export type ApiClients = Partial<Record<ApiKey, AxiosClientConfig>>;

This would be in a common lib in our company used by several teams. After each team generate the typings and client from their respective api, each team do a few config overrides at runtime and we need to make sure the generated client is based on hey-api/client-axios plugin.

Each team would use the interface in their own application in the following way;

import {client as apiWhateverClient} from 'src/generated-api-clients/api-whatever/client.gen'; // refers to the following code snippet below from the generated client.gen.ts

...

const apiClients: AplClients = {
 apiWhatever: {
   client: apiWhateverClient,
   baseURL: 'value obtained at runtime from a database'
 }
}

...
// override some apiClient config and other stuff in a QueryProvider (react) from a common lib

hey-api generated client.gen.ts

// This file is auto-generated by @hey-api/openapi-ts

...

export const client = createClient(
 createConfig<ClientOptions>({
    baseURL: 'baseURL used in the initial config to generate stuff from the api swagger.json'    
 })
);

Since 0.80.2, we got an error since the type signature of Client got changed but not in @hey-api/client-axios (which is normal since that package is deprecated and now live directly inside @hey-api/client-axios)

Image Image

We tried to remove the use of the package @hey-api/client-axios since it's deprecated but looking at the index.d.ts of @hey-api/open-api-ts (node_modules/@hey-api/openapi-ts/dist/index.d.ts), we don't see the type we're looking for. The type we need to be exported is located at node_modules/@hey-api/openapi-ts/dist/clients/axios/types.ts line 134

Image

Which points to the new type Config where the property axios can be either AxiosStatic | AxiosInstance

Image

We have two options if you agree to go forward with this.

OPTION # 1

Apply PR #2382 to @hey-api/client-axios. But I'll understand if you don't want to go that route since you would probably don't want to spend time on a package that's deprecated.

OPTION # 2

Export the type Client from node_modules/@hey-api/openapi-ts/dist/clients/axios/types.ts line 134 so we can have an equivalent of what we're going with the type Client from @hey-api/client-axios.

Maybe I miss something and there's already a way to achieve this with the package @hey-api/openapi-ts. If that's the case, could you point me to the direction?

Thank you for taking the time to read this and considering this change.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions