CARVIEW |
Navigation Menu
-
How to configure the client to use basic authentication if OpenAPI is behind basic auth? |
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 2 comments · 9 replies
-
@ddhanak are you using the standalone client? (Fetch or Axios) |
Beta Was this translation helpful? Give feedback.
All reactions
-
@mrlubos I am using the Axios client, here is my config: import { defineConfig } from "@hey-api/openapi-ts";
const DEFAULT_URL = "https://my.api.com";
export default defineConfig({
base: DEFAULT_URL,
plugins: ["@tanstack/react-query"],
client: {
name: "@hey-api/client-axios"
},
input: `${DEFAULT_URL}/openapi.json`,
output: {
path: "./api/client",
format: "prettier",
lint: "eslint"
},
types: {
enums: "typescript",
name: "PascalCase"
}
});
|
Beta Was this translation helpful? Give feedback.
All reactions
-
And are you not able to accomplish the auth using interceptors? I see Axios has a built-in support for it https://stackoverflow.com/a/44239543 |
Beta Was this translation helpful? Give feedback.
All reactions
-
I can successfully use interceptors but only after the client is generated. Right now I get a 401 when trying to generate the services. I am not sure how I can configure the client that is used to fetch the OpenAPI specification. |
Beta Was this translation helpful? Give feedback.
All reactions
-
Oh wait, are you asking how to fetch the spec behind auth? You could use programmatic access to call the generator from TypeScript once you have the spec. How you get the spec is then up to you. There's no current support for different security schemes, think there's an issue related to this |
Beta Was this translation helpful? Give feedback.
All reactions
-
π 1
-
@mrlubos it seems like the underlying library that is used to fetch the schema supports adding additional headers/options. from my understanding, this is where we could potentially add some additional configuration. Update: that's a valid solution. Thank you for your help (and this amazing library!). |
Beta Was this translation helpful? Give feedback.
All reactions
-
β€οΈ 1
-
Yep! I didn't decide yet what to do with that package, but that would be a potential route if we keep using it |
Beta Was this translation helpful? Give feedback.
All reactions
-
@ddhanak I am also looking for the same . openapi file is behind the authentication and wanted to pass the header. Can you please let me know did you solve this issue? |
Beta Was this translation helpful? Give feedback.
All reactions
-
@cmark1302 you can fetch the spec yourself before passing it to the codegen, would that work for you? I don't think I've exposed the configs still, although I've adapted the previous dependency to Hey API needs so it would be very easy to do now |
Beta Was this translation helpful? Give feedback.
Oh wait, are you asking how to fetch the spec behind auth? You could use programmatic access to call the generator from TypeScript once you have the spec. How you get the spec is then up to you. There's no current support for different security schemes, think there's an issue related to this