Skip to content
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

Syntax error in mock function when allOf and nested schema references are used together #1119

Closed
TakashiAihara opened this issue Dec 22, 2023 · 1 comment · Fixed by #1638
Assignees
Labels
bug Something isn't working msw MSW related issues
Milestone

Comments

@TakashiAihara
Copy link

What are the steps to reproduce this issue?

  1. Generated with below

orval.config.ts

import { defineConfig } from "orval";
export default defineConfig({
  test: {
    input: {
      target: "./test.yaml",
    },
    output: {
      workspace: "./generated",
      target: "functions",
      client: "react-query",
      mock: true,
    },
  },
});

test.yaml

openapi: 3.0.3
info:
  version: 1.0.0
  title: Test
paths:
  /users:
    get:
      operationId: getUsers
      responses:
        "200":
          description: OK
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/User"
                  - $ref: "#/components/schemas/Meta"
components:
  schemas:
    User:
      type: object
      properties:
        name:
          type: string
    Users:
      type: array
      items:
        $ref: "#/components/schemas/User"
    Meta:
      $ref: "#/components/schemas/MetaData"
    MetaData:
      type: object
      properties:
        total:
          type: integer

command

> pnpm orval
🍻 Start orval v6.23.0 - A swagger client generator for typescript
⚠️  test - Prettier not found
🎉 test - Your OpenAPI spec has been converted into ready to use orval!

What happens?

generated functions with below mock function with syntax errors

generated/functions/test.ts

export const getGetUsersMock = () => ({name: faker.helpers.arrayElement([faker.word.sample(), undefined]),{total: faker.helpers.arrayElement([faker.number.int({min: undefined, max: undefined}), undefined])}})

tsc errors

> pnpm tsc         
generated/functions/test.ts:103:107 - error TS1136: Property assignment expected.

103 export const getGetUsersMock = () => ({name: faker.helpers.arrayElement([faker.word.sample(), undefined]),{total: faker.helpers.arrayElement([faker.number.int({min: undefined, max: undefined}), undefined])}})
                                                                                                              ~

generated/functions/test.ts:103:120 - error TS1005: ',' expected.

103 export const getGetUsersMock = () => ({name: faker.helpers.arrayElement([faker.word.sample(), undefined]),{total: faker.helpers.arrayElement([faker.number.int({min: undefined, max: undefined}), undefined])}})
                                                                                                                           ~

generated/functions/test.ts:103:128 - error TS1005: ',' expected.

103 export const getGetUsersMock = () => ({name: faker.helpers.arrayElement([faker.word.sample(), undefined]),{total: faker.helpers.arrayElement([faker.number.int({min: undefined, max: undefined}), undefined])}})
                                                                                                                                   ~

generated/functions/test.ts:103:141 - error TS1005: ',' expected.

103 export const getGetUsersMock = () => ({name: faker.helpers.arrayElement([faker.word.sample(), undefined]),{total: faker.helpers.arrayElement([faker.number.int({min: undefined, max: undefined}), undefined])}})
                                                                                                                                                ~

generated/functions/test.ts:103:206 - error TS1128: Declaration or statement expected.

103 export const getGetUsersMock = () => ({name: faker.helpers.arrayElement([faker.word.sample(), undefined]),{total: faker.helpers.arrayElement([faker.number.int({min: undefined, max: undefined}), undefined])}})
                                                             
...

What were you expecting to happen?

The following functions were obtained by eliminating the "Meta" nesting.
The syntax seems to be correct.

-                  - $ref: "#/components/schemas/Meta"
+                  - $ref: "#/components/schemas/MetaData"
❯ pnpm orval
🍻 Start orval v6.23.0 - A swagger client generator for typescript
🎉 test - Your OpenAPI spec has been converted into ready to use orval!
export const getGetUsersMock = () => ({
  name: faker.helpers.arrayElement([faker.word.sample(), undefined]),
  total: faker.helpers.arrayElement([
    faker.number.int({ min: undefined, max: undefined }),
    undefined,
  ]),
});

Any logs, error output, etc?

Any other comments?

What versions are you using?

Operating System:
Ubuntu 22.04

> uname -a                                                  
Linux deve 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
> cat /etc/os-release 
PRETTY_NAME="Ubuntu 22.04.3 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.3 LTS (Jammy Jellyfish)"

Package Version:
orval 6.23.0

> cat package.json| grep orval
    "orval": "^6.23.0",

Browser Version:
None

@melloware melloware added the bug Something isn't working label Dec 22, 2023
@canvural
Copy link

Getting the same error too. Also related: #1101

@soartec-lab soartec-lab added the msw MSW related issues label Sep 23, 2024
@soartec-lab soartec-lab added this to the 7.2.0 milestone Sep 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working msw MSW related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants