|
1 | 1 | package io.swagger.jackson; |
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.annotation.JsonCreator; |
3 | 4 | import com.fasterxml.jackson.core.Version; |
4 | 5 | import com.fasterxml.jackson.databind.AnnotationIntrospector; |
5 | 6 | import com.fasterxml.jackson.databind.introspect.Annotated; |
|
15 | 16 | import java.util.List; |
16 | 17 |
|
17 | 18 | public class SwaggerAnnotationIntrospector extends AnnotationIntrospector { |
18 | | - private static final long serialVersionUID = 1L; |
| 19 | + private static final long serialVersionUID = 1L; |
| 20 | + private boolean isThereAHiddenField = false; |
19 | 21 |
|
20 | | - @Override |
21 | | - public Version version() { |
22 | | - return PackageVersion.VERSION; |
23 | | - } |
| 22 | + @Override |
| 23 | + public Version version() { |
| 24 | + return PackageVersion.VERSION; |
| 25 | + } |
24 | 26 |
|
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 | + } |
33 | 41 |
|
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 | + } |
48 | 56 |
|
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 | + } |
61 | 69 |
|
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 | + } |
70 | 78 |
|
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 | + } |
84 | 92 |
|
85 | | - return Collections.emptyList(); |
86 | | - } |
| 93 | + return Collections.emptyList(); |
| 94 | + } |
87 | 95 |
|
88 | | - @Override |
89 | | - public String findTypeName(AnnotatedClass ac) { |
90 | | - return null; |
91 | | - } |
| 96 | + @Override |
| 97 | + public String findTypeName(AnnotatedClass ac) { |
| 98 | + return null; |
| 99 | + } |
92 | 100 | } |
0 commit comments