teobler / swr-request-generator

A tool for generating TypeScript code and interface from swagger by using SWR and axios as client.

Home Page:https://www.npmjs.com/package/@openapi-integration/swr-request-generator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AxiosResponse Inside AxiosResponse

MonsignorEduardo opened this issue · comments

This is maybe an error on my side.
But for some reason the result type of trigger is an AxiosResponse inside an AxiosResponse.

export function UserAuthForm({ className, ...props }: UserAuthFormProps) {
    const { trigger, isMutating } = useLoginForAccessTokenAuthPostRequest();
 
    const form = useForm<z.infer<typeof formSchema>>({
        resolver: zodResolver(formSchema),
        defaultValues: {
            username: "",
            password: "",
        },
    });

    async function onSubmit(values: z.infer<typeof formSchema>) {
        try {
            // According to the types this is a AxiosResponse<AxiosResponse<Token, any>, any> | undefined
            // But it is actually a AxiosResponse<Token, any> | undefined
            const result = await trigger({ body: { username: values.username, password: values.password } });

            if (!result) {
                throw new Error("No response");
            }
            console.dir(result);
            console.dir(result.data);
            // This does not work because the types are wrong
            const { access_token } = result.data.data;

This is my openAPI.json if you want to try
openAPI.txt