1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.rest.annotation;
18
19 import static org.apache.juneau.TestUtils.*;
20 import static org.junit.jupiter.api.Assertions.*;
21
22 import java.util.*;
23
24 import org.apache.juneau.*;
25 import org.apache.juneau.annotation.*;
26 import org.apache.juneau.http.annotation.*;
27 import org.junit.jupiter.api.*;
28
29 class Swagger_FormData_Test extends TestBase {
30
31
32
33
34
35 @Rest
36 public static class A {
37
38 @FormData(
39 name="F"
40 )
41 @Schema(description={"a","b"}, type="string")
42 public static class A1 {
43 public A1(String x) {}
44 }
45 @RestGet
46 public void a(A1 f) { }
47
48 @FormData(
49 name="F",
50 schema=@Schema(description="a\nb",type="string")
51 )
52 public static class A2 {
53 public A2(String x) {}
54 }
55 @RestPut
56 public void b(A2 f) { }
57
58 @FormData(
59 name="F",
60 schema=@Schema(description="b\nc",type="string")
61 )
62 @Schema(description={"a","b"}, type="string")
63 public static class A3 {
64 public A3(String x) {}
65 }
66 @RestPost
67 public void c(A3 f) { }
68
69 @FormData("F")
70 public static class A4 {}
71 @RestDelete
72 public void d(A4 f) { }
73 }
74
75 @Test void a01_fromPojo() {
76 var s = getSwagger(A.class);
77 var x = s.getParameterInfo("/a","get","formData","F");
78 assertBean(x, "name,description,type", "F,a\nb,string");
79
80 x = s.getParameterInfo("/b","put","formData","F");
81 assertBean(x, "name,description,type", "F,a\nb,string");
82
83 x = s.getParameterInfo("/c","post","formData","F");
84 assertBean(x, "name,description,type", "F,b\nc,string");
85
86 x = s.getParameterInfo("/d","delete","formData","F");
87 assertEquals("F", x.getName());
88 }
89
90 @Rest
91 public static class B {
92
93 @FormData(name="F")
94 public static class B1 {}
95 @RestGet
96 public void a(B1 f) { }
97
98 @FormData("F")
99 public static class B2 {
100 public String f1;
101 }
102 @RestPut
103 public void b(B2 f) { }
104
105 @FormData("F")
106 public static class B3 extends LinkedList<String> {
107 private static final long serialVersionUID = 1L;
108 }
109 @RestPost
110 public void c(B3 f) { }
111
112 @FormData("F")
113 public static class B4 {}
114 @RestDelete
115 public void d(B4 f) { }
116 }
117
118 @Test void b01_schemaFromPojo() {
119 var s = getSwagger(B.class);
120 var x = s.getParameterInfo("/a","get","formData","F");
121
122 assertBean(x, "in,name,type", "formData,F,string");
123
124 x = s.getParameterInfo("/b","put","formData","F");
125 assertBean(x, "in,name,type,schema{properties{f1{type}}}", "formData,F,object,{{{string}}}");
126
127 x = s.getParameterInfo("/c","post","formData","F");
128 assertBean(x, "in,name,type,items{type}", "formData,F,array,{string}");
129
130 x = s.getParameterInfo("/d","delete","formData","F");
131 assertBean(x, "in,name,type", "formData,F,string");
132 }
133
134 @Rest
135 public static class D {
136
137 @RestGet
138 public void a(
139 @FormData(
140 name="F"
141 )
142 @Schema(description={"a","b"}, type="string")
143 String f) { }
144
145 @RestPut
146 public void b(
147 @FormData(
148 name="F",
149 schema=@Schema(description="a\nb",type="string")
150 ) String f) { }
151
152 @RestPost
153 public void c(
154 @FormData(
155 name="F",
156 schema=@Schema(description="b\nc",type="string")
157 )
158 @Schema(description={"a","b"}, type="string")
159 String f) { }
160
161 @RestDelete
162 public void d(@FormData("F") String f) { }
163 }
164
165 @Test void d01_fromParameter() {
166 var s = getSwagger(D.class);
167 var x = s.getParameterInfo("/a","get","formData","F");
168 assertBean(x, "name,description,type", "F,a\nb,string");
169
170 x = s.getParameterInfo("/b","put","formData","F");
171 assertBean(x, "name,description,type", "F,a\nb,string");
172
173 x = s.getParameterInfo("/c","post","formData","F");
174 assertBean(x, "name,description,type", "F,b\nc,string");
175
176 x = s.getParameterInfo("/d","delete","formData","F");
177 assertEquals("F", x.getName());
178 }
179
180 @Rest
181 public static class E {
182
183 @RestGet
184 public void a(@FormData(name="F") String f) { }
185
186 public static class E2 {
187 public String f1;
188 }
189 @RestPut
190 public void b(@FormData("F") E2 b) { }
191
192 public static class E3 extends LinkedList<String> {
193 private static final long serialVersionUID = 1L;
194 }
195 @RestPost
196 public void c(@FormData("F") E3 b) { }
197
198 public static class E4 {}
199 @RestDelete
200 public void d(@FormData("F") E4 b) { }
201
202 @RestOp
203 public void e(@FormData("F") Integer b) { }
204
205 @RestGet
206 public void f(@FormData("F") Boolean b) { }
207 }
208
209 @Test void e01_schemaFromParameter() {
210 var s = getSwagger(E.class);
211 var x = s.getParameterInfo("/a","get","formData","F");
212
213 assertBean(x, "in,name,type", "formData,F,string");
214
215 x = s.getParameterInfo("/b","put","formData","F");
216 assertBean(x, "in,name,type,schema{properties{f1{type}}}", "formData,F,object,{{{string}}}");
217
218 x = s.getParameterInfo("/c","post","formData","F");
219 assertBean(x, "in,name,type,items{type}", "formData,F,array,{string}");
220
221 x = s.getParameterInfo("/d","delete","formData","F");
222 assertBean(x, "in,name,type", "formData,F,string");
223
224 x = s.getParameterInfo("/e","get","formData","F");
225 assertBean(x, "in,name,type,format", "formData,F,integer,int32");
226
227 x = s.getParameterInfo("/f","get","formData","F");
228 assertBean(x, "in,name,type", "formData,F,boolean");
229 }
230 }