Bug - Swagger - Properties from inner DTO are expanded
See original GitHub issueBug Report
Current behavior
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
Input Code
Link to repo with reproducable code
https://github.com/yuval-hazaz/nest-swagger-child-prop
Expected behavior
I expect to see two only the optional parameter of type object with inner required property
Environment
Nest version: 7.6.15
For Tooling issues:
- Node version: v15.13.0
- Platform: Mac & Windows
Others:
reproduced on your sample swagger project
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Parameter Serialization - Swagger
Parameter Serialization · style defines how multiple values are delimited. Possible styles depend on the parameter location – path, query, header or cookie....
Read more >Swagger Inheritance and Composition - Stack Overflow
The response_header and response_body objects can be extended and inserted into any response object, which is done in the case of a filename_ ......
Read more >F.A.Q - Springdoc-openapi
You can use the same swagger properties in the documentation as Spring Boot ... default expansion setting for the operations and tags, in...
Read more >Step 5: The components object (OpenAPI tutorial)
The properties for each object inside components are the same as they ... Replace the existing paths object in the Swagger Editor with...
Read more >Hide a Request Field in Swagger API - Baeldung
@ApiParam is also a Swagger annotation that we can use to specify metadata related to request parameters. We can set the hidden property...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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
Would be great to have an option to overwrite @Query generated params.