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
2.98k stars 327 forks source link

ReactQuery: Typecheck fails on the generated code #1581

Open DragosRomaniuc opened 2 months ago

DragosRomaniuc commented 2 months ago

What are the steps to reproduce this issue?

  1. yarn run build

  2. Errors: ../../resources/common/src/clients/models/check503Info.ts:14:5 - error TS2411: Property 'status' of type 'string | undefined' is not assignable to 'string' index type 'string'.

14 status?: string;


817   const formData = new FormData();

../../resources/common/src/clients/api/events/events.ts:890:24 - error TS2693: 'FormData' only refers to a type, but is being used as a value here

What happens?

When I build a project with the generated orval clients it fails.

Screenshot 2024-08-16 at 16 02 52

export const createEvent = (createEventBody: CreateEventBody) => {
  const formData = new FormData();
  if (createEventBody.coverImage !== undefined) {
    formData.append("coverImage", createEventBody.coverImage);
  }
  if (createEventBody.data !== undefined) {
    formData.append("data", JSON.stringify(createEventBody.data));
  }

  return customInstance<PrivateEventDto>({
    url: `/events`,
    method: "POST",
    headers: { "Content-Type": "multipart/form-data" },
    data: formData,
  });
};

What were you expecting to happen?

Not to fail.

Any logs, error output, etc?

Any other comments?

module.exports = {
  'api-clients': {
    input: './bin/definition.yaml',
    output: {
      client: 'react-query',
      httpClient: 'axios',
      target: '../../resources/common/src/clients/api/index.ts',
      schemas: '../../resources/common/src/clients/models',
      indexFiles: true,
      mode: 'tags-split',
      mock: false,
      prettier: true,
      hooks: {
        afterAllFilesWrite: 'prettier --write',
      },
      override: {
        mutator: {
          path: '../../resources/common/src/clients/mutator/custom-instance.ts',
          name: 'customInstance',
        },
        query: {
          useQuery: true,
          signal: true,
          indexFiles: true,
          useInfiniteQueryParam: "page",
        },
      },
    },
  },
}

What versions are you using?

Please execute npx envinfo --system --npmPackages orval,zod,axios,msw,swr,@tanstack/react-query,@tanstack/vue-query,react,vue and paste the results here.

System:

    OS: macOS 14.5
    CPU: (10) arm64 Apple M1 Max
    Memory: 107.83 MB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  npmPackages:
    orval: ^7.0.1 => 7.0.1 

   "typescript": "^5.3.3"
melloware commented 2 months ago

can you provide your openAPI document too so it can be reproduced?