@@ -41,126 +41,134 @@ public abstract class AbstractModelConverter implements ModelConverter {
41
41
42
42
43
43
protected AbstractModelConverter (ObjectMapper mapper ) {
44
- mapper .registerModule (
45
- new SimpleModule ("swagger" , Version .unknownVersion ()) {
46
- @ Override
47
- public void setupModule (SetupContext context ) {
48
- context .insertAnnotationIntrospector (new SwaggerAnnotationIntrospector ());
49
- }
50
- });
51
- _mapper = mapper ;
52
- _intr = mapper .getSerializationConfig ().getAnnotationIntrospector ();
44
+ mapper .registerModule (
45
+ new SimpleModule ("swagger" , Version .unknownVersion ()) {
46
+ @ Override
47
+ public void setupModule (SetupContext context ) {
48
+ context .insertAnnotationIntrospector (new SwaggerAnnotationIntrospector ());
49
+ }
50
+ });
51
+ _mapper = mapper ;
52
+ _intr = mapper .getSerializationConfig ().getAnnotationIntrospector ();
53
53
54
54
}
55
55
56
56
protected static Comparator <Property > getPropertyComparator () {
57
- return new Comparator <Property >() {
58
- @ Override
59
- public int compare (Property one , Property two ) {
60
- if (one .getPosition () == null && two .getPosition () == null )
61
- return 0 ;
62
- if (one .getPosition () == null )
63
- return -1 ;
64
- if (two .getPosition () == null )
65
- return 1 ;
66
- return one .getPosition ().compareTo (two .getPosition ());
67
- }
68
- };
69
- }
57
+ return new Comparator <Property >() {
58
+ @ Override
59
+ public int compare (Property one , Property two ) {
60
+ if (one .getPosition () == null && two .getPosition () == null )
61
+ return 0 ;
62
+ if (one .getPosition () == null )
63
+ return -1 ;
64
+ if (two .getPosition () == null )
65
+ return 1 ;
66
+ return one .getPosition ().compareTo (two .getPosition ());
67
+ }
68
+ };
69
+ }
70
70
71
71
@ Override
72
72
public Property resolveProperty (Type type , ModelConverterContext context ) {
73
73
return null ;
74
74
}
75
75
76
76
protected Property getPrimitiveProperty (String typeName ) {
77
- Property property = null ;
78
- if ("boolean" .equals (typeName )) {
79
- property = new BooleanProperty ();
80
- }
81
- if ("string" .equals (typeName )) {
82
- property = new StringProperty ();
83
- }
84
- else if ("integer" .equals (typeName )) {
85
- property = new IntegerProperty ();
86
- }
87
- else if ("long" .equals (typeName )) {
88
- property = new LongProperty ();
89
- }
90
- else if ("float" .equals (typeName )) {
91
- property = new FloatProperty ();
92
- }
93
- else if ("double" .equals (typeName )) {
94
- property = new DoubleProperty ();
95
- }
96
- else if ("dateTime" .equals (typeName )) {
97
- property = new DateTimeProperty ();
98
- }
99
- return property ;
100
- }
77
+ Property property = null ;
78
+ if ("boolean" .equals (typeName )) {
79
+ property = new BooleanProperty ();
80
+ }
81
+ if ("string" .equals (typeName )) {
82
+ property = new StringProperty ();
83
+ }
84
+ else if ("integer" .equals (typeName )) {
85
+ property = new IntegerProperty ();
86
+ }
87
+ else if ("long" .equals (typeName )) {
88
+ property = new LongProperty ();
89
+ }
90
+ else if ("float" .equals (typeName )) {
91
+ property = new FloatProperty ();
92
+ }
93
+ else if ("double" .equals (typeName )) {
94
+ property = new DoubleProperty ();
95
+ }
96
+ else if ("dateTime" .equals (typeName )) {
97
+ property = new DateTimeProperty ();
98
+ }
99
+ return property ;
100
+ }
101
101
102
102
protected String _description (Annotated ann ) {
103
- // while name suggests it's only for properties, should work for any Annotated thing.
104
- // also; with Swagger introspector's help, should get it from ApiModel/ApiModelProperty
105
- return _intr .findPropertyDescription (ann );
106
- }
103
+ // while name suggests it's only for properties, should work for any Annotated thing.
104
+ // also; with Swagger introspector's help, should get it from ApiModel/ApiModelProperty
105
+ return _intr .findPropertyDescription (ann );
106
+ }
107
107
108
108
protected String _typeName (JavaType type ) {
109
- return _typeName (type , null );
110
- }
109
+ return _typeName (type , null );
110
+ }
111
111
112
112
protected String _typeName (JavaType type , BeanDescription beanDesc ) {
113
- String name = _resolvedTypeNames .get (type );
114
- if (name != null ) {
115
- return name ;
116
- }
117
- name = _findTypeName (type , beanDesc );
118
- _resolvedTypeNames .put (type , name );
119
- return name ;
120
- }
113
+ String name = _resolvedTypeNames .get (type );
114
+ if (name != null ) {
115
+ return name ;
116
+ }
117
+ name = _findTypeName (type , beanDesc );
118
+ _resolvedTypeNames .put (type , name );
119
+ return name ;
120
+ }
121
121
122
122
protected String _findTypeName (JavaType type , BeanDescription beanDesc ) {
123
- // First, handle container types; they require recursion
124
- if (type .isArrayType ())
125
- return "Array" ;
126
-
127
- if (type .isMapLikeType ())
128
- return "Map" ;
129
-
130
- if (type .isContainerType ()) {
131
- if (Set .class .isAssignableFrom (type .getRawClass ()))
132
- return "Set" ;
133
- return "List" ;
134
- }
135
- if (beanDesc == null ) {
136
- beanDesc = _mapper .getSerializationConfig ().introspectClassAnnotations (type );
137
- }
138
-
139
- PropertyName rootName = _intr .findRootName (beanDesc .getClassInfo ());
140
- if (rootName != null && rootName .hasSimpleName ()) {
141
- return rootName .getSimpleName ();
142
- }
143
- return _typeNameResolver .nameForType (type );
144
- }
123
+ // First, handle container types; they require recursion
124
+ if (type .isArrayType ())
125
+ return "Array" ;
126
+
127
+ if (type .isMapLikeType ())
128
+ return "Map" ;
129
+
130
+ if (type .isContainerType ()) {
131
+ if (Set .class .isAssignableFrom (type .getRawClass ()))
132
+ return "Set" ;
133
+ return "List" ;
134
+ }
135
+ if (beanDesc == null ) {
136
+ beanDesc = _mapper .getSerializationConfig ().introspectClassAnnotations (type );
137
+ }
138
+
139
+ PropertyName rootName = _intr .findRootName (beanDesc .getClassInfo ());
140
+ if (rootName != null && rootName .hasSimpleName ()) {
141
+ return rootName .getSimpleName ();
142
+ }
143
+ return _typeNameResolver .nameForType (type );
144
+ }
145
145
146
146
protected String _typeQName (JavaType type ) {
147
- return type .getRawClass ().getName ();
148
- }
147
+ return type .getRawClass ().getName ();
148
+ }
149
149
150
150
protected String _subTypeName (NamedType type ) {
151
- // !!! TODO: should this use 'name' instead?
152
- return type .getType ().getName ();
153
- }
151
+ // !!! TODO: should this use 'name' instead?
152
+ return type .getType ().getName ();
153
+ }
154
154
155
155
protected String _findExampleValue (Annotated a ) {
156
- ApiModelProperty prop = a .getAnnotation (ApiModelProperty .class );
157
- if (prop != null ) {
158
- if (!prop .example ().isEmpty ()) {
159
- return prop .example ();
160
- }
161
- }
162
- return null ;
163
- }
156
+ ApiModelProperty prop = a .getAnnotation (ApiModelProperty .class );
157
+ if (prop != null ) {
158
+ if (!prop .example ().isEmpty ()) {
159
+ return prop .example ();
160
+ }
161
+ }
162
+ return null ;
163
+ }
164
+
165
+ protected Boolean _findReadOnly (Annotated a ) {
166
+ ApiModelProperty prop = a .getAnnotation (ApiModelProperty .class );
167
+ if (prop != null ) {
168
+ return prop .readOnly ();
169
+ }
170
+ return null ;
171
+ }
164
172
165
173
@ Override
166
174
public Model resolve (Type type , ModelConverterContext context ) {
0 commit comments