6
6
import io .swagger .oas .inflector .validators .ValidationError ;
7
7
import io .swagger .oas .inflector .validators .ValidationMessage ;
8
8
9
+ import io .swagger .oas .models .media .ArraySchema ;
9
10
import io .swagger .oas .models .media .Schema ;
10
11
import io .swagger .oas .models .parameters .Parameter ;
12
+ import io .swagger .oas .models .parameters .QueryParameter ;
11
13
import io .swagger .util .Json ;
12
14
import org .apache .commons .csv .CSVFormat ;
13
15
import org .apache .commons .csv .CSVParser ;
@@ -29,40 +31,43 @@ public class DefaultConverter extends ReflectionUtils implements Converter {
29
31
public DefaultConverter (){}
30
32
31
33
public Object convert (List <String > value , Parameter parameter , Class <?> cls , Map <String , Schema > definitions , Iterator <Converter > chain ) throws ConversionException {
32
- //return coerceValue(value, parameter, cls);
33
- return null ; //added by Grace to test ResolvedFully Functionallity TODO remove it afterwards
34
+
35
+ return coerceValue (value , parameter , cls );
36
+
34
37
}
35
38
36
39
37
40
38
- /* public Object coerceValue(List<String> o, Parameter parameter, Class<?> cls) throws ConversionException {
41
+ public Object coerceValue (List <String > o , Parameter parameter , Class <?> cls ) throws ConversionException {
39
42
if (o == null || o .size () == 0 ) {
40
43
return null ;
41
44
}
42
45
43
46
LOGGER .debug ("casting `" + o + "` to " + cls );
44
47
if (List .class .equals (cls )) {
45
- if (parameter instanceof SerializableParameter) {
46
- List<Object> output = new ArrayList<Object>();
47
- SerializableParameter sp = (SerializableParameter) parameter;
48
- if (sp.getItems() != null) {
49
- Property inner = sp.getItems();
48
+ if (parameter .getSchema () != null ) {
49
+ List <Object > output = new ArrayList <>();
50
+ if (parameter .getSchema () instanceof ArraySchema ) {
51
+ ArraySchema arraySchema = ((ArraySchema ) parameter .getSchema ());
52
+ Schema inner = arraySchema .getItems ();
53
+
50
54
51
55
// TODO: this does not need to be done this way, update the helper method
52
- Parameter innerParam = new QueryParameter().property(inner);
56
+ Parameter innerParam = new QueryParameter ();
57
+ innerParam .setSchema (inner );
53
58
JavaType innerClass = getTypeFromParameter (innerParam , definitions );
54
59
for (String obj : o ) {
55
60
String [] parts = new String [0 ];
56
- if ("csv". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
61
+ if (Parameter . StyleEnum . FORM . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj ) && parameter . getExplode () == false ) {
57
62
parts = obj .split ("," );
58
63
}
59
- if ("pipes". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
64
+ if (Parameter . StyleEnum . PIPEDELIMITED . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj )) {
60
65
parts = obj .split ("|" );
61
66
}
62
- if ("ssv". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
67
+ if (Parameter . StyleEnum . SPACEDELIMITED . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj )) {
63
68
parts = obj .split (" " );
64
69
}
65
- if ("multi". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
70
+ if (Parameter . StyleEnum . FORM . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj ) && parameter . getExplode () == true ) {
66
71
parts = new String [1 ];
67
72
parts [0 ]= obj ;
68
73
}
@@ -76,40 +81,41 @@ public Object convert(List<String> value, Parameter parameter, Class<?> cls, Map
76
81
}
77
82
return output ;
78
83
}
79
- } else if (parameter instanceof SerializableParameter ) {
84
+ } else if (parameter . getSchema () != null ) {
80
85
TypeFactory tf = Json .mapper ().getTypeFactory ();
81
- SerializableParameter sp = (SerializableParameter) parameter;
82
- return cast(o.get(0), sp.getItems(), tf.constructType(cls));
86
+
87
+ return cast (o .get (0 ), parameter .getSchema (), tf .constructType (cls ));
88
+
83
89
}
84
90
return null ;
85
91
}
86
92
87
- public Object cast(List<String> o, Parameter parameter, JavaType javaType, Map<String, Model > definitions) throws ConversionException {
93
+ public Object cast (List <String > o , Parameter parameter , JavaType javaType , Map <String , Schema > definitions ) throws ConversionException {
88
94
if (o == null || o .size () == 0 ) {
89
95
return null ;
90
96
}
91
97
Class <?> cls = javaType .getRawClass ();
92
98
93
99
LOGGER .debug ("converting array `" + o + "` to `" + cls + "`" );
94
100
if (javaType .isArrayType ()) {
95
- if (parameter instanceof SerializableParameter ) {
96
- List<Object> output = new ArrayList<Object >();
97
- SerializableParameter sp = (SerializableParameter) parameter;
98
- if (sp.getItems() != null) {
99
- if (sp .getItems() instanceof ArrayProperty ) {
100
- Property inner = ((ArrayProperty) sp.getItems()) .getItems();
101
+ if (parameter . getSchema () != null ) {
102
+ List <Object > output = new ArrayList <>();
103
+ if ( parameter . getSchema () instanceof ArraySchema ) {
104
+ ArraySchema arraySchema = ( ArraySchema ) parameter . getSchema ();
105
+ if (arraySchema .getItems () != null ) {
106
+ Schema inner = arraySchema .getItems ();
101
107
102
108
// TODO: this does not need to be done this way, update the helper method
103
- Parameter innerParam = new QueryParameter().property (inner);
109
+ Parameter innerParam = new QueryParameter ().schema (inner );
104
110
JavaType innerClass = getTypeFromParameter (innerParam , definitions );
105
111
for (String obj : o ) {
106
112
String [] parts = new String [0 ];
107
113
CSVFormat format = null ;
108
- if ("csv". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
114
+ if (Parameter . StyleEnum . FORM . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj ) && parameter . getExplode () == false ) {
109
115
format = CSVFormat .DEFAULT ;
110
- } else if ("pipes". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
116
+ } else if (Parameter . StyleEnum . PIPEDELIMITED . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj )) {
111
117
format = CSVFormat .newFormat ('|' ).withQuote ('"' );
112
- } else if ("ssv". equals(sp.getCollectionFormat ()) && !StringUtils.isEmpty(obj)) {
118
+ } else if (Parameter . StyleEnum . SPACEDELIMITED . equals (parameter . getStyle ()) && !StringUtils .isEmpty (obj )) {
113
119
format = CSVFormat .newFormat (' ' ).withQuote ('"' );
114
120
}
115
121
if (format != null ) {
@@ -133,19 +139,20 @@ public Object cast(List<String> o, Parameter parameter, JavaType javaType, Map<S
133
139
output .add (ob );
134
140
}
135
141
}
142
+
136
143
}
144
+
145
+ return output ;
137
146
}
138
147
}
139
- return output;
140
148
}
141
- } else if (parameter instanceof SerializableParameter) {
142
- SerializableParameter sp = (SerializableParameter) parameter;
143
- return cast(o.get(0), sp.getItems(), javaType);
149
+ } else if (parameter != null ) {
150
+ return cast (o .get (0 ), parameter .getSchema (), javaType );
144
151
}
145
152
return null ;
146
153
}
147
154
148
- public Object cast(String o, Property property, JavaType javaType) throws ConversionException {
155
+ public Object cast (String o , Schema property , JavaType javaType ) throws ConversionException {
149
156
if (o == null || javaType == null ) {
150
157
return null ;
151
158
}
@@ -199,5 +206,5 @@ public Object cast(String o, Property property, JavaType javaType) throws Conver
199
206
.message ("couldn't convert `" + o + "` to type `" + cls + "`" ));
200
207
}
201
208
return null ;
202
- }*/
203
- }
209
+ }
210
+ }
0 commit comments