orval-labs / orval

orval is able to generate client with appropriate type-signatures (TypeScript) from any valid OpenAPI v3 or Swagger v2 specification, either in yaml or json formats. 🍺
https://orval.dev
MIT License
3.1k stars 335 forks source link

Orval generated TypeScript fails to compile #170

Closed wedi closed 3 years ago

wedi commented 3 years ago

What are the steps to reproduce this issue?

  1. Run orval with the following config using the OpenAPI specification at the bottom. N.B. Spec was generated with Orion, removed a DELETE request with body to achieve standard compliance.

    module.exports = {
       orion_test_react_query: {
         output: {
           target: 'src/',
           client: 'react-query',
           mock: false,
         },
         input: {
           target: './orion_test.yaml',
         },
       },
     };
  2. Compile TypeScript: tsc --build with tsconfig from https://github.com/anymaniax/orval/tree/master/samples/react-app-with-react-query/ + outDir + rootDir.

    {
        "compilerOptions":
        {
            "target": "es5",
            "lib":
            [
                "dom",
                "dom.iterable",
                "esnext"
            ],
            "allowJs": true,
            "skipLibCheck": true,
            "esModuleInterop": true,
            "allowSyntheticDefaultImports": true,
            "strict": true,
            "forceConsistentCasingInFileNames": true,
            "noFallthroughCasesInSwitch": true,
            "module": "esnext",
            "moduleResolution": "node",
            "resolveJsonModule": true,
            "isolatedModules": true,
            "noEmit": true,
            "jsx": "react-jsx",
            "outDir": "./dist",
            "rootDir": "./src"
        },
        "include":
        [
            "src"
        ]
    }

    What happens?

    Orval runs successfully. TypeScript result attached at the bottom.

yarn run v1.22.10
$ orval
🍻 Start orval v5.4.9 - A swagger client generator for typescript
🎉 orion_test_react_query - Your OpenAPI spec has been converted into ready to use orval!
✨  Done in 1.52s.

Compilation fails with several errors (see below)

What were you expecting to happen?

Compile a working API client

Any logs, error output, etc?

yarn run v1.22.10
$ tsc --build
src/orion_test_react_query.ts:25:13 - error TS2456: Type alias 'CustomerResource' circularly references itself.

25 export type CustomerResource = CustomerResource & CustomerResourceAllOf;
               ~~~~~~~~~~~~~~~~

src/orion_test_react_query.ts:145:86 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(mutationFn: MutationFunction<TData, { data: PostApiCustomerSearchBody; }>, options?: UseMutationOptions<TData, TError, { data: PostApiCustomerSearchBody; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PostApiCustomerSearchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationFunction<TData, { data: PostApiCustomerSearchBody; }>'.
      Type 'Promise<AxiosResponse<TData>>' is not assignable to type 'Promise<TData>'.
        Type 'AxiosResponse<TData>' is not assignable to type 'TData'.
          'TData' could be instantiated with an arbitrary type which could be unrelated to 'AxiosResponse<TData>'.
  Overload 2 of 4, '(mutationKey: MutationKey, options?: UseMutationOptions<TData, TError, { data: PostApiCustomerSearchBody; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PostApiCustomerSearchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: PostApiCustomerSearchBody; }) => Promise<AxiosResponse<TData>>' is missing the following properties from type 'readonly unknown[]': concat, join, slice, indexOf, and 17 more.
  Overload 3 of 4, '(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, { data: PostApiCustomerSearchBody; }> | undefined, options?: UseMutationOptions<...> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PostApiCustomerSearchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: PostApiCustomerSearchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to type 'readonly unknown[]'.

145       return useMutation<TData, TError, {data: PostApiCustomerSearchBody}, TContext>((props) => {
                                                                                         ~~~~~~~~~~~~

src/orion_test_react_query.ts:169:85 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(mutationFn: MutationFunction<TData, { data: PostApiCustomerBatchBody; }>, options?: UseMutationOptions<TData, TError, { data: PostApiCustomerBatchBody; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PostApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationFunction<TData, { data: PostApiCustomerBatchBody; }>'.
      Type 'Promise<AxiosResponse<TData>>' is not assignable to type 'Promise<TData>'.
  Overload 2 of 4, '(mutationKey: MutationKey, options?: UseMutationOptions<TData, TError, { data: PostApiCustomerBatchBody; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PostApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: PostApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is missing the following properties from type 'readonly unknown[]': concat, join, slice, indexOf, and 17 more.
  Overload 3 of 4, '(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, { data: PostApiCustomerBatchBody; }> | undefined, options?: UseMutationOptions<...> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PostApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: PostApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to type 'readonly unknown[]'.

169       return useMutation<TData, TError, {data: PostApiCustomerBatchBody}, TContext>((props) => {
                                                                                        ~~~~~~~~~~~~

src/orion_test_react_query.ts:193:86 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(mutationFn: MutationFunction<TData, { data: PatchApiCustomerBatchBody; }>, options?: UseMutationOptions<TData, TError, { data: PatchApiCustomerBatchBody; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PatchApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationFunction<TData, { data: PatchApiCustomerBatchBody; }>'.
      Type 'Promise<AxiosResponse<TData>>' is not assignable to type 'Promise<TData>'.
  Overload 2 of 4, '(mutationKey: MutationKey, options?: UseMutationOptions<TData, TError, { data: PatchApiCustomerBatchBody; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PatchApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: PatchApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is missing the following properties from type 'readonly unknown[]': concat, join, slice, indexOf, and 17 more.
  Overload 3 of 4, '(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, { data: PatchApiCustomerBatchBody; }> | undefined, options?: UseMutationOptions<...> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: PatchApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: PatchApiCustomerBatchBody; }) => Promise<AxiosResponse<TData>>' is not assignable to type 'readonly unknown[]'.

193       return useMutation<TData, TError, {data: PatchApiCustomerBatchBody}, TContext>((props) => {
                                                                                         ~~~~~~~~~~~~

src/orion_test_react_query.ts:220:71 - error TS2322: Type 'Promise<AxiosResponse<TQueryFnData>>' is not assignable to type 'TQueryFnData | Promise<TQueryFnData>'.
  Type 'Promise<AxiosResponse<TQueryFnData>>' is not assignable to type 'Promise<TQueryFnData>'.

220   const query = useQuery<TQueryFnData, TError, TData>(queryKey, () => getApiCustomer<TQueryFnData>(axiosOptions), queryOptions )
                                                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/react-query/types/core/types.d.ts:7:89
    7 export declare type QueryFunction<T = unknown, TQueryKey extends QueryKey = QueryKey> = (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>;
                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from the return type of this signature.

src/orion_test_react_query.ts:246:77 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(mutationFn: MutationFunction<TData, { data: any; }>, options?: UseMutationOptions<TData, TError, { data: any; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationFunction<TData, { data: any; }>'.
      Type 'Promise<AxiosResponse<TData>>' is not assignable to type 'Promise<TData>'.
  Overload 2 of 4, '(mutationKey: MutationKey, options?: UseMutationOptions<TData, TError, { data: any; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: any; }) => Promise<AxiosResponse<TData>>' is missing the following properties from type 'readonly unknown[]': concat, join, slice, indexOf, and 17 more.
  Overload 3 of 4, '(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, { data: any; }> | undefined, options?: UseMutationOptions<TData, TError, { data: any; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to type 'readonly unknown[]'.

246       return useMutation<TData, TError, {data: CustomerResource}, TContext>((props) => {
                                                                                ~~~~~~~~~~~~

src/orion_test_react_query.ts:273:71 - error TS2322: Type 'Promise<AxiosResponse<TQueryFnData>>' is not assignable to type 'TQueryFnData | Promise<TQueryFnData>'.
  Type 'Promise<AxiosResponse<TQueryFnData>>' is not assignable to type 'Promise<TQueryFnData>'.

273   const query = useQuery<TQueryFnData, TError, TData>(queryKey, () => getApiCustomerCustomer<TQueryFnData>(customer, axiosOptions), {enabled: !!(customer), ...queryOptions} )
                                                                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  node_modules/react-query/types/core/types.d.ts:7:89
    7 export declare type QueryFunction<T = unknown, TQueryKey extends QueryKey = QueryKey> = (context: QueryFunctionContext<TQueryKey>) => T | Promise<T>;
                                                                                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The expected type comes from the return type of this signature.

src/orion_test_react_query.ts:300:94 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(mutationFn: MutationFunction<TData, { customer: string; data: any; }>, options?: UseMutationOptions<TData, TError, { customer: string; data: any; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { customer: string; data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationFunction<TData, { customer: string; data: any; }>'.
      Type 'Promise<AxiosResponse<TData>>' is not assignable to type 'Promise<TData>'.
  Overload 2 of 4, '(mutationKey: MutationKey, options?: UseMutationOptions<TData, TError, { customer: string; data: any; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { customer: string; data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { customer: string; data: any; }) => Promise<AxiosResponse<TData>>' is missing the following properties from type 'readonly unknown[]': concat, join, slice, indexOf, and 17 more.
  Overload 3 of 4, '(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, { customer: string; data: any; }> | undefined, options?: UseMutationOptions<TData, TError, { ...; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { customer: string; data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { customer: string; data: any; }) => Promise<AxiosResponse<TData>>' is not assignable to type 'readonly unknown[]'.

300       return useMutation<TData, TError, {customer: string;data: CustomerResource}, TContext>((props) => {
                                                                                                 ~~~~~~~~~~~~

src/orion_test_react_query.ts:323:71 - error TS2769: No overload matches this call.
  Overload 1 of 4, '(mutationFn: MutationFunction<TData, { customer: string; }>, options?: UseMutationOptions<TData, TError, { customer: string; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { customer: string; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationFunction<TData, { customer: string; }>'.
      Type 'Promise<AxiosResponse<TData>>' is not assignable to type 'Promise<TData>'.
  Overload 2 of 4, '(mutationKey: MutationKey, options?: UseMutationOptions<TData, TError, { customer: string; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { customer: string; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { customer: string; }) => Promise<AxiosResponse<TData>>' is missing the following properties from type 'readonly unknown[]': concat, join, slice, indexOf, and 17 more.
  Overload 3 of 4, '(mutationKey: MutationKey, mutationFn?: MutationFunction<TData, { customer: string; }> | undefined, options?: UseMutationOptions<TData, TError, { ...; }, TContext> | undefined): UseMutationResult<...>', gave the following error.
    Argument of type '(props: { customer: string; }) => Promise<AxiosResponse<TData>>' is not assignable to parameter of type 'MutationKey'.
      Type '(props: { customer: string; }) => Promise<AxiosResponse<TData>>' is not assignable to type 'readonly unknown[]'.

323       return useMutation<TData, TError, {customer: string}, TContext>((props) => {
                                                                          ~~~~~~~~~~~~

Found 9 errors.

error Command failed with exit code 1.

What versions are you using?

Operating System: macOS Package Version: 5.4.9 TypeScript Version: 4.3.4 Browser Version: Not applicable

OpenAPI spec

openapi: 3.0.3
info:
  title: Laravel
  version: 1.0.0
servers:
  - url: 'http://orion.test/api'
    description: Default Environment
security:
  - BearerAuth: []
paths:
  /api/customer/search:
    post:
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                search:
                  type: object
                  properties:
                    value:
                      type: string
                      description: 'A search for the given value will be performed on the following fields: name, email, street_and_number'
                sort:
                  type: array
                  items:
                    type: object
                    properties:
                      field:
                        type: string
                        enum:
                          - name
                          - email
                          - street_and_number
                      direction:
                        type: string
                        enum:
                          - asc
                          - desc
                    required:
                      - field
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/CustomerResource'
                  links:
                    $ref: '#/components/schemas/ResourceLinks'
                  meta:
                    $ref: '#/components/schemas/ResourceMeta'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
      summary: Search for customers
      tags:
        - Customer
  /api/customer/batch:
    post:
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                resources:
                  type: array
                  items:
                    $ref: '#/components/schemas/CustomerResource'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/CustomerResource'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
        '404':
          description: Resource not found
        '422':
          description: Validation error
      summary: Create a batch of customers
      tags:
        - Customer
    patch:
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                resources:
                  type: array
                  items:
                    $ref: '#/components/schemas/CustomerResource'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/CustomerResource'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
        '404':
          description: Resource not found
        '422':
          description: Validation error
      summary: Update a batch of customers
      tags:
        - Customer
  /api/customer:
    get:
      parameters: []
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      $ref: '#/components/schemas/CustomerResource'
                  links:
                    $ref: '#/components/schemas/ResourceLinks'
                  meta:
                    $ref: '#/components/schemas/ResourceMeta'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
      summary: Get a list of customers
      tags:
        - Customer
    post:
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerResource'
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/CustomerResource'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
        '422':
          description: Validation error
      summary: Create customer
      tags:
        - Customer
  '/api/customer/{customer}':
    get:
      parameters:
        - schema:
            type: string
          name: customer
          in: path
          required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/CustomerResource'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
        '404':
          description: Resource not found
      summary: Get customer
      tags:
        - Customer
    patch:
      parameters:
        - schema:
            type: string
          name: customer
          in: path
          required: true
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CustomerResource'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/CustomerResource'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
        '404':
          description: Resource not found
        '422':
          description: Validation error
      summary: Update customer
      tags:
        - Customer
    delete:
      parameters:
        - schema:
            type: string
          name: customer
          in: path
          required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/CustomerResource'
        '401':
          description: Unauthenticated
        '403':
          description: Unauthorized
        '404':
          description: Resource not found
      summary: Delete customer
      tags:
        - Customer
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
  schemas:
    Customer:
      title: Customer
      type: object
      properties:
        name:
          type: string
        email:
          type: string
        street_and_number:
          type: string
        street_additional:
          type: string
    CustomerResource:
      title: CustomerResource
      allOf:
        - $ref: '#/components/schemas/CustomerResource'
        - type: object
          properties: {}
    ResourceLinks:
      title: ResourceLinks
      type: object
      properties:
        first:
          type: string
          format: uri
        last:
          type: string
          format: uri
        prev:
          type: string
          format: uri
        next:
          type: string
          format: uri
    ResourceMeta:
      title: ResourceMeta
      type: object
      properties:
        current_page:
          type: integer
        from:
          type: integer
        last_page:
          type: integer
        path:
          type: string
        per_page:
          type: integer
        to:
          type: integer
        total:
          type: integer
tags:
  - name: Customer

TypeScript generated by Orval

/*
 * Generated by orval v5.4.9 🍺
 * Do not edit manually.
 * Laravel
 * OpenAPI spec version: 1.0.0
 */
import axios,{
  AxiosRequestConfig
} from 'axios'
import {
  useQuery,
  useMutation,
  UseQueryOptions,
  UseMutationOptions
} from 'react-query'
export interface Customer {
  name?: string;
  email?: string;
  street_and_number?: string;
  street_additional?: string;
}

export type CustomerResourceAllOf = {};

export type CustomerResource = CustomerResource & CustomerResourceAllOf;

export interface ResourceLinks {
  first?: string;
  last?: string;
  prev?: string;
  next?: string;
}

export interface ResourceMeta {
  current_page?: number;
  from?: number;
  last_page?: number;
  path?: string;
  per_page?: number;
  to?: number;
  total?: number;
}

export type PostApiCustomerSearchBodySearch = {
  value?: string;
};

export type PostApiCustomerSearchBodySortItemField = 'name' | 'email' | 'street_and_number';

export const PostApiCustomerSearchBodySortItemField = {
  name: 'name' as PostApiCustomerSearchBodySortItemField,
  email: 'email' as PostApiCustomerSearchBodySortItemField,
  street_and_number: 'street_and_number' as PostApiCustomerSearchBodySortItemField,
};

export type PostApiCustomerSearchBodySortItemDirection = 'asc' | 'desc';

export const PostApiCustomerSearchBodySortItemDirection = {
  asc: 'asc' as PostApiCustomerSearchBodySortItemDirection,
  desc: 'desc' as PostApiCustomerSearchBodySortItemDirection,
};

export type PostApiCustomerSearchBodySortItem = {
  field: PostApiCustomerSearchBodySortItemField;
  direction?: PostApiCustomerSearchBodySortItemDirection;
};

export type PostApiCustomerSearchBody = {
  search?: PostApiCustomerSearchBodySearch;
  sort?: PostApiCustomerSearchBodySortItem[];
};

export type PostApiCustomerSearch200 = {
  data?: CustomerResource[];
  links?: ResourceLinks;
  meta?: ResourceMeta;
};

export type PostApiCustomerBatchBody = {
  resources?: CustomerResource[];
};

export type PostApiCustomerBatch200 = {
  data?: CustomerResource[];
};

export type PatchApiCustomerBatchBody = {
  resources?: CustomerResource[];
};

export type PatchApiCustomerBatch200 = {
  data?: CustomerResource[];
};

export type GetApiCustomer200 = {
  data?: CustomerResource[];
  links?: ResourceLinks;
  meta?: ResourceMeta;
};

export type PostApiCustomer201 = {
  data?: CustomerResource;
};

export type GetApiCustomerCustomer200 = {
  data?: CustomerResource;
};

export type PatchApiCustomerCustomer200 = {
  data?: CustomerResource;
};

export type DeleteApiCustomerCustomer200 = {
  data?: CustomerResource;
};

type AsyncReturnType<
T extends (...args: any) => Promise<any>,
U = unknown
> = T extends (...args: any) => Promise<infer R> ? (U extends R ? U : R) : any;

export const postApiCustomerSearch = <TData = PostApiCustomerSearch200>(
    postApiCustomerSearchBody: PostApiCustomerSearchBody, options?: AxiosRequestConfig
 ) => {
    return axios.post<TData>(
      `/api/customer/search`,
      postApiCustomerSearchBody,options
    );
  }

    export const usePostApiCustomerSearch = <TData = AsyncReturnType<typeof postApiCustomerSearch,PostApiCustomerSearch200>,
    TError = unknown,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: PostApiCustomerSearchBody}, TContext>, axios?: AxiosRequestConfig}
) => {
      const {mutation: mutationOptions, axios: axiosOptions} = options || {}

      return useMutation<TData, TError, {data: PostApiCustomerSearchBody}, TContext>((props) => {
        const {data} = props || {};

        return  postApiCustomerSearch<TData>(data,axiosOptions)
      }, mutationOptions)
    }
    export const postApiCustomerBatch = <TData = PostApiCustomerBatch200>(
    postApiCustomerBatchBody: PostApiCustomerBatchBody, options?: AxiosRequestConfig
 ) => {
    return axios.post<TData>(
      `/api/customer/batch`,
      postApiCustomerBatchBody,options
    );
  }

    export const usePostApiCustomerBatch = <TData = AsyncReturnType<typeof postApiCustomerBatch,PostApiCustomerBatch200>,
    TError = unknown,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: PostApiCustomerBatchBody}, TContext>, axios?: AxiosRequestConfig}
) => {
      const {mutation: mutationOptions, axios: axiosOptions} = options || {}

      return useMutation<TData, TError, {data: PostApiCustomerBatchBody}, TContext>((props) => {
        const {data} = props || {};

        return  postApiCustomerBatch<TData>(data,axiosOptions)
      }, mutationOptions)
    }
    export const patchApiCustomerBatch = <TData = PatchApiCustomerBatch200>(
    patchApiCustomerBatchBody: PatchApiCustomerBatchBody, options?: AxiosRequestConfig
 ) => {
    return axios.patch<TData>(
      `/api/customer/batch`,
      patchApiCustomerBatchBody,options
    );
  }

    export const usePatchApiCustomerBatch = <TData = AsyncReturnType<typeof patchApiCustomerBatch,PatchApiCustomerBatch200>,
    TError = unknown,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: PatchApiCustomerBatchBody}, TContext>, axios?: AxiosRequestConfig}
) => {
      const {mutation: mutationOptions, axios: axiosOptions} = options || {}

      return useMutation<TData, TError, {data: PatchApiCustomerBatchBody}, TContext>((props) => {
        const {data} = props || {};

        return  patchApiCustomerBatch<TData>(data,axiosOptions)
      }, mutationOptions)
    }
    export const getApiCustomer = <TData = GetApiCustomer200>(
     options?: AxiosRequestConfig
 ) => {
    return axios.get<TData>(
      `/api/customer`,options
    );
  }

export const getGetApiCustomerQueryKey = () => [`/api/customer`]

export const useGetApiCustomer = <TQueryFnData = AsyncReturnType<typeof getApiCustomer, GetApiCustomer200>, TError = unknown, TData = TQueryFnData>(
  options?: { query?:UseQueryOptions<TQueryFnData, TError, TData>, axios?: AxiosRequestConfig}

  ) => {

  const {query: queryOptions, axios: axiosOptions} = options || {}

  const queryKey = queryOptions?.queryKey ?? getGetApiCustomerQueryKey();

  const query = useQuery<TQueryFnData, TError, TData>(queryKey, () => getApiCustomer<TQueryFnData>(axiosOptions), queryOptions )

  return {
    queryKey,
    ...query
  }
}

export const postApiCustomer = <TData = PostApiCustomer201>(
    customerResource: CustomerResource, options?: AxiosRequestConfig
 ) => {
    return axios.post<TData>(
      `/api/customer`,
      customerResource,options
    );
  }

    export const usePostApiCustomer = <TData = AsyncReturnType<typeof postApiCustomer,PostApiCustomer201>,
    TError = unknown,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{data: CustomerResource}, TContext>, axios?: AxiosRequestConfig}
) => {
      const {mutation: mutationOptions, axios: axiosOptions} = options || {}

      return useMutation<TData, TError, {data: CustomerResource}, TContext>((props) => {
        const {data} = props || {};

        return  postApiCustomer<TData>(data,axiosOptions)
      }, mutationOptions)
    }
    export const getApiCustomerCustomer = <TData = GetApiCustomerCustomer200>(
    customer: string, options?: AxiosRequestConfig
 ) => {
    return axios.get<TData>(
      `/api/customer/${customer}`,options
    );
  }

export const getGetApiCustomerCustomerQueryKey = (customer: string,) => [`/api/customer/${customer}`]

export const useGetApiCustomerCustomer = <TQueryFnData = AsyncReturnType<typeof getApiCustomerCustomer, GetApiCustomerCustomer200>, TError = unknown, TData = TQueryFnData>(
 customer: string, options?: { query?:UseQueryOptions<TQueryFnData, TError, TData>, axios?: AxiosRequestConfig}

  ) => {

  const {query: queryOptions, axios: axiosOptions} = options || {}

  const queryKey = queryOptions?.queryKey ?? getGetApiCustomerCustomerQueryKey(customer);

  const query = useQuery<TQueryFnData, TError, TData>(queryKey, () => getApiCustomerCustomer<TQueryFnData>(customer, axiosOptions), {enabled: !!(customer), ...queryOptions} )

  return {
    queryKey,
    ...query
  }
}

export const patchApiCustomerCustomer = <TData = PatchApiCustomerCustomer200>(
    customer: string,
    customerResource: CustomerResource, options?: AxiosRequestConfig
 ) => {
    return axios.patch<TData>(
      `/api/customer/${customer}`,
      customerResource,options
    );
  }

    export const usePatchApiCustomerCustomer = <TData = AsyncReturnType<typeof patchApiCustomerCustomer,PatchApiCustomerCustomer200>,
    TError = unknown,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{customer: string;data: CustomerResource}, TContext>, axios?: AxiosRequestConfig}
) => {
      const {mutation: mutationOptions, axios: axiosOptions} = options || {}

      return useMutation<TData, TError, {customer: string;data: CustomerResource}, TContext>((props) => {
        const {customer,data} = props || {};

        return  patchApiCustomerCustomer<TData>(customer,data,axiosOptions)
      }, mutationOptions)
    }
    export const deleteApiCustomerCustomer = <TData = DeleteApiCustomerCustomer200>(
    customer: string, options?: AxiosRequestConfig
 ) => {
    return axios.delete<TData>(
      `/api/customer/${customer}`,options
    );
  }

    export const useDeleteApiCustomerCustomer = <TData = AsyncReturnType<typeof deleteApiCustomerCustomer,DeleteApiCustomerCustomer200>,
    TError = unknown,

    TContext = unknown>(options?: { mutation?:UseMutationOptions<TData, TError,{customer: string}, TContext>, axios?: AxiosRequestConfig}
) => {
      const {mutation: mutationOptions, axios: axiosOptions} = options || {}

      return useMutation<TData, TError, {customer: string}, TContext>((props) => {
        const {customer} = props || {};

        return  deleteApiCustomerCustomer<TData>(customer,axiosOptions)
      }, mutationOptions)
    }
lojell commented 3 years ago

I have the same issue.

Looks like the problem is about how we return the data from the axios: return axios.patch<TData>( '/api/customer/${customer}', customerResource,options );

it will return not Promise<TData> but Promise<AxiosResponse<TData>> We just need to destruct the data field from the response

anymaniax commented 3 years ago

should be fixed

danbalarin commented 3 years ago

Works for me now! Thanks ❤️

abhay-ramesh commented 9 months ago

Same for SWR