I'm using ApiModelPropertyOptional and ApiModelProperty in dto along with class-validator and passing this dto to @Body. Like
export class UpdatePayload {
@ApiModelPropertyOptional({ description: 'Client name', type: String }) @iIsNotEmpty() name: String
@ApiModelPropertyOptional({ description: 'Client email', type: String }) email: String
}
this is supposed to just body. But this get listed in Models as UpdatePayload but This is not model
As far as Swagger concerns, that is a model whether you see it as models or not.
async update(@Body() payload: UpdatePayload) {}
The above snippet shows that your update() method expects an UpdatePayload model (whether it's a class or it's an interface, it has to conform UpdatePayload definitions).
Let's assume you use some kind of 3rd party generation tool to generate client code with this Swagger-powered API. I'd assume TypeScript. In the generated TypeScript code, you'd have to pass in an UpdatePayload model to the methodupdate() for it to work.
tldr; Models in Swagger's language might not be the same as your definition of Model. This is the expected behavior of Swagger.
export class UpdatePayload {
@ApiModelPropertyOptional({ description: 'Client name' })
@IsNotEmpty()
name: string
@ApiModelPropertyOptional({ description: 'Client email' })
@IsNotEmpty()
@IsEmail()
email: string
}
Here it its UpdatePayload which is class. And I used same for validation (class-validator) Swagger using @nestjs/swagger
As per your last statement. Are you saying it is fine to have UpdatePayload in Model listing ? But model must be entities not Payloads
@patilrevansidh My point was Swagger shouldn't be concerning what you call it whether it is the standard convention. In Swagger language, it's a Model. It could be an Entity, a DTO, a ViewModel whatever you want to call it because Swagger cannot standardize the convention in the programming world, Model is the most generic imho.
And this is the expected behavior of Swagger, to generate your Entity/DTO/Model/ViewModel as definitions. I think this issue should be closed.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.