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.21k stars 337 forks source link

MSW/Faker - arrays of enum values are not generating properly #1660

Open dteske25 opened 1 month ago

dteske25 commented 1 month ago

What are the steps to reproduce this issue?

I was able to get a minimal repro stood up: https://stackblitz.com/edit/vitejs-vite-xqak8w?file=src%2Fhandlers%2Fexample.ts&view=editor

What happens?

It looks like for some reason the fake type is being generated as an array of array of enums instead of just the array of enums that it should be.

What were you expecting to happen?

Any logs, error output, etc?

Here's the typescript error that's also visible in the IDE

 ❯ npm run build

> vite-react-typescript-starter@0.0.0 build
> tsc -b && vite build

src/handlers/example.ts:36:3 - error TS2322: Type '(2 | 1 | 3)[][] | undefined' is not assignable to type 'ExampleEnum[] | null | undefined'.
  Type '(2 | 1 | 3)[][]' is not assignable to type 'ExampleEnum[]'.
    Type '(2 | 1 | 3)[]' is not assignable to type 'ExampleEnum'.

36   exampleProperty: faker.helpers.arrayElement([
     ~~~~~~~~~~~~~~~

  src/handlers/example.ts:22:3
    22   exampleProperty?: ExampleEnum[] | null;
         ~~~~~~~~~~~~~~~
    The expected type comes from property 'exampleProperty' which is declared here on type 'ExampleResponse'

Found 1 error.

Any other comments?

What versions are you using?

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  npmPackages:
    @tanstack/react-query: ^5.56.2 => 5.56.2 
    axios: ^1.7.7 => 1.7.7 
    msw: ^2.4.9 => 2.4.9 
    orval: ^7.1.1 => 7.1.1 
    react: ^18.3.1 => 18.3.1
Hypenate commented 3 weeks ago

We have the same issue with 7.2.0.

This is generated:

import {
  ChangeType
} from './schemas'

This is the error:

TS2724: './ schemas' has no exported member named ChangeType. Did you mean ChangeTypeDto

This is our a part of our override:

      override: {
        components: {
          schemas: {
            suffix: 'Dto',
          },
        },
      },
melloware commented 3 weeks ago

Any help looking through the MSW code where the issue is and providing a PR would be great!

gegorov commented 7 hours ago

same issue happens in 7.3.0, it seems that MSW generator doesn't respect override.components.schemas