Many-to-many bidirectional doesn't show type at OpenAPI
See original GitHub issueI’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
- Create 2 entities, having a many-to-many relation between them with a
@JoinTable()
at one of them. - Decorate them with
@ApiModelProperty()
to define them in OpenAPI. - (Optional) Specify the type by
@ApiModelProperty({type: MyClass})
. - 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
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
How to achieve @ManyToMany bi-directional association in ...
1 Entity: @Entity public class Book { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, ...
Read more >Many-to-Many Relationship in Spring Boot Rest + JPA
In JPA, we use the @ManyToMany annotation to model Many to Many Relationships. It could either be Uni-directional or Bi-directional. In a ...
Read more >Modeling Most SQL Relationships In Entity Framework Core
The transparent many-to-many relationship is only available since EF Core 5. Let's look at two entities of ManyToManyLeft and ManyToManyRight .
Read more >API with NestJS #7. Creating relationships with Postgres and ...
In this article, we go through what is a relationship in the context of a Postgres database and how do we work with...
Read more >Hibernate Tips: How to map a bidirectional many-to-many ...
The attribute models the association, and the annotation declares the kind of relationship. The @JoinTable annotation is optional. It allows you to define...
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
4.0.0 has been published
Fixed in the
next
version (to install runnpm i @nestjs/swagger@next
). Note: remember to update@nestjs/common
,@nestjs/core
andtypescript
as well to ensure that you’re using the latest versions.Steps to migrate: https://github.com/nestjs/swagger/pull/355#issuecomment-547925879