-
Notifications
You must be signed in to change notification settings - Fork 534
When param is an array of objects, it converts to array of arrays #3624
Description
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
My sort param is used like ?sort[][created_on]=desc so I desire some openapi json like
"/some-endpoint": {
"get": {
"operationId": "SomeController_list",
"parameters": [
{
"required": false,
"name": "sort",
"in": "query",
"schema": {
"example": [ { "created_on": "desc" } ],
"type": "array",
"items": {
"type": "object",
"additionalProperties": { "type": "string", "enum": [ "asc", "desc" ] }
}
}
}
]
}
},but instead, nestjs/swagger is generating the get.paramaters[0].schema with an incorrect schema for the items field
{
"required": false,
"name": "sort",
"in": "query",
"schema": {
"default": [ { "created_on": "desc" } ],
"example": [ { "created_on": "desc" } ],
"type": "array",
"items": { "type": "array" }
}
}In my case I am using @anatine/zod-openapi in combination with @nestjs/swagger to generate the docs; I am not using decorators besides @ApiQuery({ type: SomeClass }) where SomeClass is generated by a zod plugin. As I explain below, this issue does appear to be with @nestjs/swagger though, not the zod plugin.
I can see that the correct metadata gets passed to transformToArraySchemaProperty:
{
"type": "array",
"items": {
"type": "object",
"additionalProperties": {
"type": "string",
"enum": ["asc", "desc"]
}
},
"example": [{ "created_on": "desc" }],
"required": false,
"isArray": true
}and that on line 550 that type is literally the string 'array' so the first part of the ternary is used, whereas I need the 2nd part of the ternary to be used.
Minimum reproduction code
https://github.com/nestjs/swagger
Steps to reproduce
No response
Expected behavior
The transformToArraySchemaProperty method correctly sets the items schema.
Package version
11.2.1
NestJS version
11.1.8
Node.js version
v22.16.0
In which operating systems have you tested?
- macOS
- Windows
- Linux
Other
No response