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

Ignore @JsonBackReference when resolving the model #4699

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.swagger.v3.core.jackson;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
Expand Down Expand Up @@ -1178,7 +1179,7 @@ protected boolean ignore(final Annotated member, final XmlAccessorType xmlAccess
if (propertiesToIgnore.contains(propName)) {
return true;
}
if (member.hasAnnotation(JsonIgnore.class) && member.getAnnotation(JsonIgnore.class).value()) {
if ((member.hasAnnotation(JsonIgnore.class) && member.getAnnotation(JsonIgnore.class).value()) || member.hasAnnotation(JsonBackReference.class)) {
return true;
}
if (hasHiddenAnnotation(member)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.swagger.v3.core.resolving;

import com.fasterxml.jackson.annotation.JsonBackReference;
import io.swagger.v3.core.converter.ModelConverters;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

import java.util.List;
import java.util.Map;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertNull;

public class JsonBackReferenceTest {

@Test(description = "it should ignore a reference field")
public void testReferenceField() {
final Map<String, Schema> models = ModelConverters.getInstance().readAll(Parent.class);

final Schema parent = models.get("Parent");
assertNotNull(parent);
assertEquals(parent.getProperties().size(), 1);

final Schema child = models.get("Child");
assertNotNull(child);
assertNull(child.getProperties());
}

static class Parent {

public List<Child> children = null;

}

static class Child {

@JsonBackReference
public Parent parent = null;

}

}