Swagger: Many-to-many bidirectional doesn't show type at OpenAPI

Created on 13 May 2019  路  7Comments  路  Source: nestjs/swagger

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

When having a bi-directional many-to-many relation (which includes a join table) decorating both sides with @ApiModelProperty() does not display the type in OpenAPI, even if I define the type manually. Only the opposite side (the one that does not have the JoinTable() decorator) displays it as it should.

Expected behavior

When using @ApiModelProperty() a bi-directional relation, the OpenAPI spec should include the other end's type in a relation as a nested property.

Minimal reproduction of the problem with instructions

  1. Create 2 entities, having a many-to-many relation between them with a @JoinTable() at one of them.
  2. Decorate them with @ApiModelProperty() to define them in OpenAPI.
  3. _(Optional)_ Specify the type by @ApiModelProperty({type: MyClass}).
  4. Navigate to the model with the JoinTable() that has the OpenAPI spec to see that the type is "items":{"type":"array"}} and the type is omitted.

What is the motivation / use case for changing the behavior?

I believe that due some cyclical dependency the properties are not resolved before the OpenAPI is defined. Removing one end of the relation (uni-directional) makes it work correctly.

I have not tried to reproduce this with plain DTOs.

Environment


Nest version: 6.0.0

For Tooling issues:
- Node version: 11.14
- Platform:  Windows
next

Most helpful comment

4.0.0 has been published

All 7 comments

Any update on this? running into same issue

I am also seeing the same issue.

I also have the same issue.

I was able to solve the problem by providing the type for the ApiModelProperty decorator in a closure. It鈥檚 a problem similar to a circular dependency. Pay attention to what types are available when.

Fixed in the next version (to install run npm i @nestjs/swagger@next). Note: remember to update @nestjs/common, @nestjs/core and typescript as well to ensure that you're using the latest versions.

Steps to migrate: https://github.com/nestjs/swagger/pull/355#issuecomment-547925879

4.0.0 has been published

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.

Was this page helpful?
0 / 5 - 0 ratings