1
+ package org .openapijsonschematools .client .parameter ;
2
+
3
+ import org .checkerframework .checker .nullness .qual .Nullable ;
4
+ import org .openapijsonschematools .client .configurations .SchemaConfiguration ;
5
+ import org .openapijsonschematools .client .header .PrefixSeparatorIterator ;
6
+ import org .openapijsonschematools .client .header .StyleSerializer ;
7
+ import org .openapijsonschematools .client .schemas .validation .JsonSchema ;
8
+ import org .openapijsonschematools .client .header .HeaderBase ;
9
+ import org .openapijsonschematools .client .header .PrefixSeparatorIterator ;
10
+ import org .openapijsonschematools .client .header .StyleSerializer ;
11
+ import org .openapijsonschematools .client .schemas .validation .JsonSchema ;
12
+ import java .util .Map ;
13
+
14
+ public class SchemaParameter extends ParameterBase {
15
+ public final JsonSchema <?> schema ;
16
+
17
+ public SchemaParameter (String name , ParameterInType inType , boolean required , @ Nullable ParameterStyle style , @ Nullable Boolean explode , @ Nullable Boolean allowReserved , JsonSchema <?> schema ) {
18
+ super (name , inType , required , style , explode , allowReserved );
19
+ this .schema = schema ;
20
+ }
21
+
22
+ protected Map <String , String > serialize (@ Nullable Object inData , boolean validate , SchemaConfiguration configuration , @ Nullable PrefixSeparatorIterator iterator ) {
23
+ var castInData = validate ? schema .validate (inData , configuration ) : inData ;
24
+ ParameterStyle usedStyle = getStyle ();
25
+ boolean percentEncode = inType == ParameterInType .QUERY || inType == ParameterInType .PATH ;
26
+ String value ;
27
+ boolean usedExplode = explode == null ? usedStyle == ParameterStyle .FORM : explode ;
28
+ if (usedStyle == ParameterStyle .SIMPLE ) {
29
+ // header OR path
30
+ value = StyleSerializer .serializeSimple (castInData , name , usedExplode , percentEncode );
31
+ } else if (usedStyle == ParameterStyle .FORM ) {
32
+ // query OR cookie
33
+ boolean isCookie = inType == ParameterInType .COOKIE ;
34
+ value = StyleSerializer .serializeForm (castInData , name , usedExplode , percentEncode , iterator , isCookie );
35
+ } else if (usedStyle == ParameterStyle .LABEL ) {
36
+ // path
37
+ value = StyleSerializer .serializeLabel (castInData , name , usedExplode );
38
+ } else if (usedStyle == ParameterStyle .MATRIX ) {
39
+ // path
40
+ value = StyleSerializer .serializeMatrix (castInData , name , usedExplode );
41
+ } else if (usedStyle == ParameterStyle .SPACE_DELIMITED ) {
42
+ // query
43
+ value = StyleSerializer .serializeSpaceDelimited (castInData , name , usedExplode , iterator );
44
+ } else if (usedStyle == ParameterStyle .PIPE_DELIMITED ) {
45
+ // query
46
+ value = StyleSerializer .serializePipeDelimited (castInData , name , usedExplode , iterator );
47
+ } else {
48
+ // usedStyle == ParameterStyle.DEEP_OBJECT
49
+ // query
50
+ throw new RuntimeException ("Style deep object serialization has not yet been implemented." );
51
+ }
52
+ return Map .of (name , value );
53
+ }
54
+ }
0 commit comments