nest icon indicating copy to clipboard operation
nest copied to clipboard

Swagger : Generate documentation using interfaces

Open fmeynard opened this issue 8 years ago • 4 comments

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

fmeynard avatar Jan 05 '18 12:01 fmeynard

Hi @fmeynard, I would love to do that either, but it's TypeScript-related thing. It's not possible so far.

kamilmysliwiec avatar Jan 05 '18 13:01 kamilmysliwiec

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

fmeynard avatar Jan 05 '18 13:01 fmeynard

Unfortunately, I think the POJO classes are the only way so far. 🙁

kamilmysliwiec avatar Jan 06 '18 11:01 kamilmysliwiec

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.

lock[bot] avatar Sep 25 '19 07:09 lock[bot]