Skip to content

Commit bba2d79

Browse files
authored
Merge pull request #2251 from ralphdoe/bugfix/2061-model-hidden-not-working
2061-Validation-added
2 parents c4ad492 + 1c3e307 commit bba2d79

File tree

1 file changed

+74
-66
lines changed

1 file changed

+74
-66
lines changed
Lines changed: 74 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package io.swagger.jackson;
22

3+
import com.fasterxml.jackson.annotation.JsonCreator;
34
import com.fasterxml.jackson.core.Version;
45
import com.fasterxml.jackson.databind.AnnotationIntrospector;
56
import com.fasterxml.jackson.databind.introspect.Annotated;
@@ -15,78 +16,85 @@
1516
import java.util.List;
1617

1718
public class SwaggerAnnotationIntrospector extends AnnotationIntrospector {
18-
private static final long serialVersionUID = 1L;
19+
private static final long serialVersionUID = 1L;
20+
private boolean isThereAHiddenField = false;
1921

20-
@Override
21-
public Version version() {
22-
return PackageVersion.VERSION;
23-
}
22+
@Override
23+
public Version version() {
24+
return PackageVersion.VERSION;
25+
}
2426

25-
@Override
26-
public boolean hasIgnoreMarker(AnnotatedMember m) {
27-
ApiModelProperty ann = m.getAnnotation(ApiModelProperty.class);
28-
if (ann != null && ann.hidden()) {
29-
return true;
30-
}
31-
return false;
32-
}
27+
@Override
28+
public boolean hasIgnoreMarker(AnnotatedMember m) {
29+
ApiModelProperty ann = m.getAnnotation(ApiModelProperty.class);
30+
if (ann != null && ann.hidden()) {
31+
isThereAHiddenField = true;
32+
return true;
33+
}
34+
// Add a Ignore Marker when there's a Constructor with JsonCreator and also if there's any Hidden Field
35+
JsonCreator constructor = m.getAnnotation(JsonCreator.class);
36+
if (constructor != null && isThereAHiddenField) {
37+
return true;
38+
}
39+
return false;
40+
}
3341

34-
@Override
35-
public Boolean hasRequiredMarker(AnnotatedMember m) {
36-
ApiModelProperty ann = m.getAnnotation(ApiModelProperty.class);
37-
if (ann != null) {
38-
return ann.required();
39-
}
40-
XmlElement elem = m.getAnnotation(XmlElement.class);
41-
if (elem != null) {
42-
if (elem.required()) {
43-
return true;
44-
}
45-
}
46-
return null;
47-
}
42+
@Override
43+
public Boolean hasRequiredMarker(AnnotatedMember m) {
44+
ApiModelProperty ann = m.getAnnotation(ApiModelProperty.class);
45+
if (ann != null) {
46+
return ann.required();
47+
}
48+
XmlElement elem = m.getAnnotation(XmlElement.class);
49+
if (elem != null) {
50+
if (elem.required()) {
51+
return true;
52+
}
53+
}
54+
return null;
55+
}
4856

49-
@Override
50-
public String findPropertyDescription(Annotated a) {
51-
ApiModel model = a.getAnnotation(ApiModel.class);
52-
if (model != null && !"".equals(model.description())) {
53-
return model.description();
54-
}
55-
ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
56-
if (prop != null) {
57-
return prop.value();
58-
}
59-
return null;
60-
}
57+
@Override
58+
public String findPropertyDescription(Annotated a) {
59+
ApiModel model = a.getAnnotation(ApiModel.class);
60+
if (model != null && !"".equals(model.description())) {
61+
return model.description();
62+
}
63+
ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
64+
if (prop != null) {
65+
return prop.value();
66+
}
67+
return null;
68+
}
6169

62-
@Override
63-
public Integer findPropertyIndex(Annotated a) {
64-
ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
65-
if (prop != null && prop.position() != 0) {
66-
return prop.position();
67-
}
68-
return null;
69-
}
70+
@Override
71+
public Integer findPropertyIndex(Annotated a) {
72+
ApiModelProperty prop = a.getAnnotation(ApiModelProperty.class);
73+
if (prop != null && prop.position() != 0) {
74+
return prop.position();
75+
}
76+
return null;
77+
}
7078

71-
@Override
72-
public List<NamedType> findSubtypes(Annotated a) {
73-
final ApiModel api = a.getAnnotation(ApiModel.class);
74-
if (api != null) {
75-
final Class<?>[] classes = api.subTypes();
76-
final List<NamedType> names = new ArrayList<NamedType>(classes.length);
77-
for (Class<?> subType : classes) {
78-
names.add(new NamedType(subType));
79-
}
80-
if (!names.isEmpty()) {
81-
return names;
82-
}
83-
}
79+
@Override
80+
public List<NamedType> findSubtypes(Annotated a) {
81+
final ApiModel api = a.getAnnotation(ApiModel.class);
82+
if (api != null) {
83+
final Class<?>[] classes = api.subTypes();
84+
final List<NamedType> names = new ArrayList<NamedType>(classes.length);
85+
for (Class<?> subType : classes) {
86+
names.add(new NamedType(subType));
87+
}
88+
if (!names.isEmpty()) {
89+
return names;
90+
}
91+
}
8492

85-
return Collections.emptyList();
86-
}
93+
return Collections.emptyList();
94+
}
8795

88-
@Override
89-
public String findTypeName(AnnotatedClass ac) {
90-
return null;
91-
}
96+
@Override
97+
public String findTypeName(AnnotatedClass ac) {
98+
return null;
99+
}
92100
}

0 commit comments

Comments
 (0)