orval
orval copied to clipboard
MSW: Error using oneOf nested inside allOf
Minimal input schema:
{
"openapi": "3.0.1",
"info": {
"title": "bug report"
},
"paths": {
"/something": {
"post": {
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"uploads": {
"type": "array",
"items": {
"allOf": [
{
"type": "object",
"properties": {
"file_type": {
"type": "string"
}
}
},
{
"oneOf": [
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["a"]
}
}
},
{
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["b"]
},
"other": {
"type": "string"
}
}
}
]
}
]
}
}
}
}
}
}
}
}
}
}
}
}
Output with syntax error:
export const getPostSomethingResponseMock = (overrideResponse: Partial< PostSomething200 > = {}): PostSomething200 => ({uploads: faker.helpers.arrayElement([Array.from({ length: faker.number.int({ min: 1, max: 10 }) }, (_, i) => i + 1).map(() => ({file_type: faker.helpers.arrayElement([faker.word.sample(), undefined]),{type: faker.helpers.arrayElement([faker.helpers.arrayElement(['a'] as const), undefined])},{other: faker.helpers.arrayElement([faker.word.sample(), undefined]), type: faker.helpers.arrayElement([faker.helpers.arrayElement(['b'] as const), undefined])}})), undefined]), ...overrideResponse})
Tested on orval 6.29.1 and 6.31.0. The code in the schema file and the API file is correct; only the MSW file has this problem.
This seems to only happen with a oneOf nested inside an allOf.
Similar to this issue: https://github.com/anymaniax/orval/issues/1508
And this one: https://github.com/anymaniax/orval/issues/1101