SpringDataRest with multiple DTO-s
See original GitHub issueVersion: 3.0.0-SNAPSHOT
Generating swagger document from SpringDataRest, multiple DTO is generated in contract.
In https://github.com/csegedicsaba/springfox-poc project we have Person and City entities.
@Entity
@Table(name = "PERSON")
public class Person {
@Id
private Long personId;
@ManyToOne
@JoinColumn(name = "CITY_ID")
private City city;
public Long getPersonId() {
return this.personId;
}
public void setPersonId(Long zarolasId) {
this.personId = zarolasId;
}
public City getCity() {
return city;
}
public void setCity(City city) {
this.city = city;
}
}
@Entity
@Table(name = "CITY")
public class City {
@Id
private long cityId;
public long getCityId() {
return cityId;
}
public void setCityId(long cityId) {
this.cityId = cityId;
}
}
The contract (getting from http://localhost:8080/v2/api-docs) contains Person, Person_1 and Person_2. The generated contract is different sometimes when I restart the application (no change, only restart). In springfox-poc_api-docs_v1.json.txt Person_1 and Person_2 is generated and used. But in springfox-poc_api-docs_v2.json.txt Person_2 is generated but not used.
By adding the opposite relation to City only the Person is generated (no Person_1 or Person_2).
@OneToMany(mappedBy = "city")
private Collection<Person> persons;
public Collection<Person> getPersons() {
return persons;
}
public void setPersons(Collection<Person> persons) {
this.persons = persons;
}
We don’t want to add always both side of relationship because it is unnecessary.
springfox-poc_api-docs_v1.json.txt springfox-poc_api-docs_v2.json.txt
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (6 by maintainers)
Thx @MaksimOrlov! We are waiting for merge…
Here is the PR #3247 to fix this issue.