I have an action that gets an object in the query. The object has an optional property which itself is an object with a required property. In the swagger UI, the inner required property shows as required incorrectly at the level action (without its parent property):
class childObject {
@swagger.ApiProperty({
required: true,
type: String,
})
requiredInnerProp!: string;
}
class parentObject {
@swagger.ApiProperty({
required: false,
type: childObject,
})
optionalChildProp?: childObject;
}
@common.Get("/action")
async getWithChildObjectInQuery(
@common.Query() query: parentObject
): Promise<string> {
return "";
}

I also tried to add ApiQuery decorator like this:
@common.Get("/action")
@swagger.ApiQuery({
required: false,
style: "deepObject",
explode: true,
type: parentObject,
})
async getWithChildObjectInQuery(
@common.Query() query: parentObject
): Promise<string> {
return "";
}
but then I see both properties

Link to repo with reproducable code
https://github.com/yuval-hazaz/nest-swagger-child-prop
I expect to see two only the optional parameter of type object with inner required property
Nest version: 7.6.15
For Tooling issues:
- Node version: v15.13.0
- Platform: Mac & Windows
Others:
reproduced on your sample swagger project
Can anyone confirm or direct me what I am doing wrong?
no one?
After some further investigation, I found the way to make it work.
Instead of @query I used @ApiQuery with style:"deepObject" and explode:true.
I also had to remove @Query and use @Req to get the query values - otherwise all the parameters were listed twice on the open-api Json
@Get("/action")
+ @ApiQuery({
+ type:parentObject,
+ style:"deepObject",
+ explode:true
+ })
async getWithChildObjectInQuery(
+ @Req() request: Request
- @Query() query: parentObject
): Promise<string> {
const query :parentObject = request.query
console.log(query);
return "";
}
When using this method I see the parameters correctly in the open-api json and on swagger UI
This looks good:

But, there is still a minor issue in Swagger UI -
When I use this value, it is sent incorrectly to the server (as an immediate parameter called "rquiredInnerLoop"
{
"requiredInnerProp": "string"
}
Instead, I have to use this value for it to work correctly (note the additional "optionalChildPop" object although it is the name of the parameter
{
"optionalChildProp":
{
"requiredInnerProp": "string"
}
}

Most helpful comment
After some further investigation, I found the way to make it work.
Instead of @query I used @ApiQuery with style:"deepObject" and explode:true.
I also had to remove @Query and use @Req to get the query values - otherwise all the parameters were listed twice on the open-api Json
When using this method I see the parameters correctly in the open-api json and on swagger UI

This looks good:
But, there is still a minor issue in Swagger UI -
When I use this value, it is sent incorrectly to the server (as an immediate parameter called "rquiredInnerLoop"
Instead, I have to use this value for it to work correctly (note the additional "optionalChildPop" object although it is the name of the parameter