Standalone package for your client
shriekdj opened this issue · comments
Description
When We Generate Client For Our OpenAPI.json, It Can Also Create an Standalone Package with Script Like this openapi --input http://127.0.0.1:8000/openapi.json --output ./src/client2 --client fetch --name Backend --useOptions
.
Which can be used like this
import { Backend } from '@/client';
export default const appClient = new Backend({
BASE: 'http://localhost:8000',
});
Now I Can Use this single appClient
Anywhere i want. and all functions are in this single object as method of that object.
Please Allow Option name
instead of deprecating name in @hey-api/openapi-ts
@shriekdj with new clients, you'll be able to do
import * as Backend from '@/client';
And then call the client the same way. Except it will be tree shakeable. What's the value in keeping name
?
Ok, Thanks @mrlubos this help my issue.
But the details like this should be also in docs for existing user of name
option to use customClient Name package.
currently i have to use it like this
import * as Backend from '@/client';
Backend.OpenAPI.BASE = 'http://localhost:8000';
Backend.OpenAPI.interceptors.request.use((request) => {
request.cache = 'no-store';
// request.headers.set('Authorization', 'Bearer <my_token>');
return request;
});
export const appClient = Backend;
I also had to change my object methods also like before it was look like this
await appClient.district.searchDistrictsDistrictSearchGet();
which looks like after this type code using
await appClient.DistrictService.searchDistrictsDistrictSearchGet();
Everything else was the same for me. I am closing the issue