[x] Regression
[ ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Consider the following code:
import { Entity, Column, PrimaryGeneratedColumn, ManyToMany, JoinColumn, JoinTable } from 'typeorm';
import { ApiProperty } from '@nestjs/swagger';
import { User } from './user.entity';
@Entity('events')
export class Event {
@PrimaryGeneratedColumn()
@ApiProperty()
id: number;
@ManyToMany(type => User, user => user.events)
@JoinTable()
@ApiProperty({ type: [User] })
users: User[];
}
This generates the following OAS3 output:
"Event": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"users": {
"type": "array",
"items": {
"type": "array"
}
},
},
"required": [
"id",
"users",
]
}
We expect the following output:
"Event": {
"type": "object",
"properties": {
"id": {
"type": "number"
},
"users": {
"type": "array",
"items": {
"$ref": "#/components/schemas/User"
}
},
},
"required": [
"id",
"users",
]
}
Minimal repo that shows the issue: https://github.com/dennisameling/nest-swagger-example
Worked in previous NestJS/Swagger version
Nest version: 4.0.0-next.16
For Tooling issues:
- Node version: 10.16.3
- Platform: Windows
Others:
Happy to provide a PR if you can confirm that this is indeed a regression that needs to be fixed
You have a circular dependency between your entities. For that, you should use lazy type resolvers:
@ApiProperty({ type: () => [User] })
(notice arrow function)
Otherwise, we won't be able to infer your type at runtime
Thank you! Is it okay if I provide a PR in the https://github.com/nestjs/docs.nestjs.com repo to add some documentation for this?
https://docs.nestjs.com/recipes/swagger#working-with-arrays
Currently the docs mention the following:
@ApiModelProperty({ type: [String] })
readonly names: string[];
I could either
@ApiModelProperty({ type: [String] }) by @ApiModelProperty({ type: () => [String] }) in the docs, as the lazy type resolver should work in all cases (non-circular and circular dependencies), so that it's consistent@ApiModelProperty({ type: () => [String] })If you could leave your preference here, I'll close this issue and reference it in my PR in https://github.com/nestjs/docs.nestjs.com
It's already covered here https://github.com/nestjs/docs.nestjs.com/pull/825 馃槃
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.