-
Notifications
You must be signed in to change notification settings - Fork 12
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
Expose request and response types in a simple way #31
Comments
Hi @huang-julien, Unfortunately, the author said he won't be working on it anymore, so I'll give it a shot :) The main problem as I understand is this one:
|
interesting 👀 ... I'll be waiting then. import type { operations } from '#build/types/nuxt-open-fetch/schemas/bff'
export type OperationParameters<T extends keyof operations> = 'parameters' extends keyof operations[T]
? operations[T]['parameters']
: never
// example
function (t: Partial<OperationParameters<'GetPet'>['query']>) {
$fetch('...', { query : t })
} It does work but def not my fav way of using types haha I don't have a solution for enums yet. For now enums generated from open-api-generator with axios-typescript are compatible with openapi-typescript |
Created a PR to export types with friendly names openapi-ts/openapi-typescript#1599. RequestEnterpriseAdminListGlobalWebhooks['query']
// or
RequestEnterpriseAdminListGlobalWebhooksQuery
// or
EnterpriseAdminListGlobalWebhooksQuery
// etc Good news is that enums generation is supported out of the box in v7 by using |
I'm not sure if it's relevant for this issue. 😅 I'm wondering how I can access the response type for a certain request. I would like to type my Pinia store without having to type something like this: export const useStore = defineStore("test", {
// ...
state: () => ({
token: null as null | string,
userInfo: null as {
deactivate?: string | undefined;
email: string;
id: string;
instances: {
id: string;
name: string;
}[];
name: string;
phone?: string | undefined;
roles: string[];
} | null
})
}); Ideally the code would look something like this: export const useStore = defineStore("test", {
// ...
state: () => ({
token: null as null | string,
userInfo: null as UserInfoByToken | null
})
}); Here's the code I'm using to set const { data, error } = await useAuthService(
"/user-info-by-token/{token}",
{
path: { token: this.token }
}
);
this.userInfo = data.value; |
@jonkri I suggest opening new issue for this. However, here's my suggestion as per what I understand you're trying to do:
|
How about this: import type { paths } from '#open-fetch-schemas/auth-fetch'
type Paths = keyof paths
type Methods<path extends Paths> = keyof paths[path]
type AuthService<pathT extends Paths, methodT extends Methods<pathT>> = paths[pathT][methodT]['responses']['200']['content']['application/json']
let userInfo: AuthService<'/user-info-by-token/{token}', 'get'> userInfo should then be properly typed. |
Hey thanks for your module !
I'm coming from open-api-generator with axios-typescript which exposes enum and types directly from what's generated.
It could be nice to expose directly quer/params and response types from generation and maybe adding them to auto-import ?
Currently the only way to retrieve thse types is to import from the
operations
type:The text was updated successfully, but these errors were encountered: