question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
kamilmysliwieccommented, Dec 3, 2019

4.0.0 has been published

1reaction
kamilmysliwieccommented, Oct 30, 2019

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found