Skip to content

Commit

Permalink
This I think is a fix for issue swagger-api#4059.
Browse files Browse the repository at this point in the history
  • Loading branch information
madeleine-a committed Jan 19, 2022
1 parent 02b1e77 commit 38c2672
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ protected boolean ignore(final Annotated member, final XmlAccessorType xmlAccess
if (propertiesToIgnore.contains(propName)) {
return true;
}
if (member.hasAnnotation(JsonIgnore.class)) {
if (member.hasAnnotation(JsonIgnore.class) && !member.getAnnotation( JsonIgnore.class ).value() == false ) {
return true;
}
if (hasHiddenAnnotation(member)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package io.swagger.v3.core.resolving;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonValue;
import io.swagger.v3.core.converter.AnnotatedType;
import io.swagger.v3.core.converter.ModelConverterContextImpl;
import io.swagger.v3.core.jackson.ModelResolver;
import io.swagger.v3.core.matchers.SerializationMatchers;
import io.swagger.v3.oas.models.media.Schema;
import org.testng.annotations.Test;

public class Ticket4059Test extends SwaggerTestBase {

@Test
public void testJsonIgnoreAnnotation() throws Exception {

final ModelResolver modelResolver = new ModelResolver(mapper());

ModelConverterContextImpl context = new ModelConverterContextImpl(modelResolver);

Schema model = context
.resolve(new AnnotatedType(ExtendedRequest.class));

SerializationMatchers.assertEqualsToYaml(context.getDefinedModels(), "ExtendedRequest:\n" +
" type: object\n" +
" properties:\n" +
" id:\n" +
" type: string\n" +
" id2:\n" +
" type: string");

}

static class ExtendedRequest extends Request{
@JsonIgnore(value = false) // Don't ignore me
private Id id;
@JsonIgnore(value = true)
private String fieldTwo;
@JsonIgnore
private String fieldThree;

public String getFieldTwo() {
return fieldTwo;
}

public void setFieldTwo(String fieldTwo) {
this.fieldTwo = fieldTwo;
}

public String getFieldThree() {
return fieldThree;
}

public void setFieldThree(String fieldThree) {
this.fieldThree = fieldThree;
}

public Id getId() {
return id;
}

public void setId(Id id) {
this.id = id;
}
}

static class Request {
@JsonIgnore
private Id id;

@JsonIgnore(value = false) // Don't ignore me
private Id id2;

public Id getId2() {
return id2;
}

public void setId2(Id id2) {
this.id2 = id2;
}

public Id getId() {
return id;
}

public void setId(Id id) {
this.id = id;
}
}

static class Id {
private String value;

@JsonValue
public String getValue() {
return value;
}
}
}

0 comments on commit 38c2672

Please sign in to comment.