Swagger : Generate documentation using interfaces
I'm submitting a...
[ ] Regression
[x] Bug report
[x] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
Unable to use interfaces to "type" responses using the swagger module.
src\modules\job\controller\job.controller.ts (15,49): 'JobInterface' only refers to a type, but is being used as a value here. (2693)
( also tested sending the interface name as a string but in this case swagger itself is not able to resolve : "Unknown Type: JobInterface" )
Expected behavior
We should be able to generate documentation based on interface
Minimal reproduction of the problem with instructions
`
@ApiResponse({status: HttpStatus.OK, type: JobInterface, description: "Job related information"})
@Get(':jobId')
async findOne(@Param('jobId') jobId: string): Promise<JobInterface> {
return await this.jobService.findOne(jobId);
}
`
Please note that it seems even not possible to use @ApiModelProperty() or similar decorators inside an interface.
What is the motivation / use case for changing the behavior?
Generating swagger documentation based on interfaces can be useful when :
- not having POJO implementation, often the case with mongoose ( i'm not able to do it, to be honest )
- having multiple multiple implementations of one precise interface
Hi @fmeynard, I would love to do that either, but it's TypeScript-related thing. It's not possible so far.
Hi @kamilmysliwiec
Thx for your quick answer ! That was my fear :s Do you have any recommendation for workarounds ? I'm currently generating POJO classes only for swagger, sounds "duplicated" code to me but no choice as using mongoose i'm not able to get ride of the interface and having a POJO class extending the MongooseDocument instead, otherwise its failing with :
@ApiResponse({ status: HttpStatus.CREATED, type: JobModel, description: "todo"})
....
export class JobModel extends MongooseDocument {
^
TypeError: Class extends value undefined is not a constructor or null
Unfortunately, I think the POJO classes are the only way so far. 🙁
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.