orval
orval copied to clipboard
Syntax error in mock function when allOf and nested schema references are used together
What are the steps to reproduce this issue?
- 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
Getting the same error too. Also related: https://github.com/anymaniax/orval/issues/1101