Skip to content

oneOf always references plain Object #3549

@mbehm

Description

@mbehm

Is there an existing issue for this?

  • 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
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions