oneOf always references plain Object
Is there an existing issue for this?
- [x] I have searched the existing issues
Current behavior
Using oneOf for @ApiProperty always results in ref to Object
export class Example {
foo: string;
bar: string;
}
export class Params {
@ApiProperty({
oneOf: [
{$ref: getSchemaPath(Example)},
{type: 'array', items: {$ref: getSchemaPath(Example)}}
],
})
example: Example | Example[]
}
Results in the generated swagger schema
schema:
$ref: '#/components/schemas/Object'
Minimum reproduction code
https://gist.github.com/mbehm/965da4b9251118b288115aac160291e1
Steps to reproduce
No response
Expected behavior
Expect oneOf to correctly produce the following schema
schema:
oneOf:
- $ref: '#/components/schemas/Example'
- type: array
items:
$ref: '#/components/schemas/Example'
Package version
11.2.0
NestJS version
11.0.1
Node.js version
24.3.0
In which operating systems have you tested?
- [ ] macOS
- [x] Windows
- [ ] Linux
Other
No response
As a workaround using a noop function for type eg. type: () => {} fixes the problem and produces the correct schema definition, but the way shown in the documentation seems to always result in a ref to Object so don't think that's intended.
I’m interested in working on this issue. Is it okay to proceed before triage is complete?
+1
As a workaround using a noop function for type eg.
type: () => {}fixes the problem and produces the correct schema definition, but the way shown in the documentation seems to always result in a ref toObjectso don't think that's intended.
ApiProperty({
type: () => {},
oneOf: [{ type: 'string' }, { type: 'array', items: { type: 'string' } }],
description,
required,
})
it will throw error.
throw new Error(A circular dependency has been detected (property key: "${key}"). Please, make sure that each side of a bidirectional relationships are using lazy resolvers ("type: () => ClassType").)