Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated client has conflicting request when OpenApi spec has "Request" tag #479

Closed
schehlmj opened this issue Apr 23, 2024 · 9 comments
Closed
Labels
bug 🔥 Something isn't working client Client package related

Comments

@schehlmj
Copy link

Description

When the OpenApi Spec has "Request" tag, the generated client.ts contains both of these:
public readonly request: RequestService;
public readonly request: BaseHttpRequest;

These cause compile error in the client.ts.

My workaround is to rename this and all references to it:
public readonly httpRequest: BaseHttpRequest;

OpenAPI specification (optional)

"/api/v1/request/summary/{requestId}": {
  "get": {
    "tags": [
      "Request",
    ],
....

Configuration

No response

System information (optional)

No response

@schehlmj schehlmj added the bug 🔥 Something isn't working label Apr 23, 2024
@mrlubos
Copy link
Member

mrlubos commented Apr 23, 2024

Hey @schehlmj, are you able to share your config? It looks like you're using a custom client instance? Can I ask why?

@schehlmj
Copy link
Author

I am generating with this:
npx @hey-api/openapi-ts --input ./app.json --output ./src/services/app-client-lib --client axios --name AppClient

@mrlubos
Copy link
Member

mrlubos commented Apr 23, 2024

Why do you use --name?

@schehlmj
Copy link
Author

schehlmj commented Apr 23, 2024

I now see that it is deprecated in @next. I am using it as a carryover from before, but I am not tied to it. I am not sure what I should do instead. As a simple fix, I can just not use --name, and then just keep using the old generated AppClient.ts as my own src code. I don't see a way to just use the Services directly because I am not clear how I would authenticate.

My current code has an app-client.ts:

import { AppClient } from './app-client-lib';
import { useSessionStore } from '../stores/session';  // pinia

const sessionStore = useSessionStore();

export const appClient = new AppClient({
  TOKEN: async () => {
    if (sessionStore.bypassAuth === true) {
      console.log('Bypassing adding Authorization header Bearer token');
      return '';
    } else if (sessionStore.isAuthenticated !== true) {
      throw 'Not authenticated';
    } else {
      return sessionStore.token || '';
    }
  },
});

Then I would just import appClient from that and use it like appClient.request.summary(requestId);

@mrlubos
Copy link
Member

mrlubos commented Apr 23, 2024

If you're using it only for authorisation, you can set that function directly on OpenAPI config object https://github.com/ferdikoomen/openapi-typescript-codegen/wiki/Authorization

We plan to improve this in the clients release too

@schehlmj
Copy link
Author

schehlmj commented Apr 23, 2024

@mrlubos and @jordanshatford Thanks for you attention and help with this.

One other nice thing about --name generated clients is that each instance of them can point to a different base URL. That isn't so easy to do with setting the OpenAPI singleton. Hopefully the clients release will handle that if --name generate clients are removed.

@schehlmj schehlmj reopened this Apr 24, 2024
@mrlubos
Copy link
Member

mrlubos commented Apr 24, 2024

Yep they will!

@mrlubos
Copy link
Member

mrlubos commented Jul 21, 2024

Hey @schehlmj, the new Axios client is available now https://www.npmjs.com/package/@hey-api/client-axios

Docs: https://heyapi.vercel.app/openapi-ts/clients.html#axios

Let me know your thoughts if you do try it out

@schehlmj
Copy link
Author

@mrlubos It looks good. Thanks for your hard work on all this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🔥 Something isn't working client Client package related
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants