Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SpringDataRest with multiple DTO-s #3082

Closed
csegedicsaba opened this issue Aug 14, 2019 · 7 comments
Closed

SpringDataRest with multiple DTO-s #3082

csegedicsaba opened this issue Aug 14, 2019 · 7 comments
Assignees
Labels
Milestone

Comments

@csegedicsaba
Copy link
Contributor

Version: 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

@MaksimOrlov MaksimOrlov self-assigned this Aug 14, 2019
@MaksimOrlov MaksimOrlov added this to the 3.0 milestone Aug 14, 2019
@MaksimOrlov
Copy link
Member

Hi, @csegedicsaba. That issue is related to #3014.

@MaksimOrlov
Copy link
Member

It is under work and will be fixed to beginning of September.

@csegedicsaba
Copy link
Contributor Author

Any news about this issue?

@fhgbaguidi
Copy link

plop!!

@MaksimOrlov
Copy link
Member

Here is the PR #3247 to fix this issue.

@csegedicsaba
Copy link
Contributor Author

Thx @MaksimOrlov!
We are waiting for merge...

@MaksimOrlov
Copy link
Member

PR with fixes has been merged.

And I'll be grateful for your feedback, if the issue was gone.
Otherwise feel free to reopen the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants