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

[@nestjs/swagger v7] oneOf doesn't work as expected #3045

Open
2 tasks done
karlismelderis-mckinsey opened this issue Aug 19, 2024 · 1 comment
Open
2 tasks done

[@nestjs/swagger v7] oneOf doesn't work as expected #3045

karlismelderis-mckinsey opened this issue Aug 19, 2024 · 1 comment

Comments

@karlismelderis-mckinsey

Did you read the migration guide?

  • I have read the whole migration guide

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Potential Commit/PR that introduced the regression

No response

Versions

6 -> 7.4.0

Describe the regression

@ApiProperty({
        type: undefined,
        oneOf: [
          { type: 'array', items: { type: 'string' } },
          { type: 'array', items: { type: 'number' } },
          { type: 'array', items: { type: 'boolean' } },
        ],
        description: API_DESCRIPTION,
      })
values: string[] | number[] | boolean[]

this configuration used to produce this schema in v6

"values": {
  "oneOf": [
    {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    {
      "type": "array",
      "items": {
        "type": "number"
      }
    },
    {
      "type": "array",
      "items": {
        "type": "boolean"
      }
    }
  ]
}

in v7 for some reason type: array is added and oneOf suddenly defines items not schema of "values"

Minimum reproduction code

@ApiProperty({
        type: undefined,
        oneOf: [
          { type: 'array', items: { type: 'string' } },
          { type: 'array', items: { type: 'number' } },
          { type: 'array', items: { type: 'boolean' } },
        ],
        description: API_DESCRIPTION,
      })
values: string[] | number[] | boolean[]

Expected behavior

I expect to see this schema to be generated:

"values": {
  "oneOf": [
    {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    {
      "type": "array",
      "items": {
        "type": "number"
      }
    },
    {
      "type": "array",
      "items": {
        "type": "boolean"
      }
    }
  ]
}

Other

No response

@karlismelderis-mckinsey
Copy link
Author

I think I found a workaround

type Values = string[] | number[] | boolean[]

@ApiProperty({
        type: undefined,
        oneOf: [
          { type: 'array', items: { type: 'string' } },
          { type: 'array', items: { type: 'number' } },
          { type: 'array', items: { type: 'boolean' } },
        ],
        description: API_DESCRIPTION,
      })
values: Values

it will do for us but behaviour is unexpected nevertheless

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant