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
21 import java.util.*;
22
23 import org.apache.juneau.*;
24 import org.apache.juneau.annotation.*;
25 import org.apache.juneau.http.annotation.*;
26 import org.junit.jupiter.api.*;
27
28 class Swagger_Path_Test extends TestBase {
29
30
31
32
33
34 @Rest
35 public static class A {
36
37 @Path("P")
38 @Schema(
39 d={"a","b"},
40 e="a,b",
41 t="string"
42 )
43 public static class A1 {
44 public A1(String x) {}
45 @Override
46 public String toString() {
47 return "a";
48 }
49 }
50 @RestGet(path="/a/{P}")
51 public void a(A1 f) { }
52
53 @Path(
54 name="P",
55 schema=@Schema(description="a\nb",type="string",_enum={"a","b"})
56 )
57 public static class A2 {
58 public A2(String x) {}
59 @Override
60 public String toString() {
61 return "b";
62 }
63 }
64 @RestPut(path="/b/{P}")
65 public void b(A2 f) { }
66
67 @Path(
68 name="P",
69 schema=@Schema(description="b\nc",type="string",_enum={"b","c"})
70 )
71 @Schema(
72 d={"a","b"},
73 t="string",
74 e="a,b"
75 )
76 public static class A3 {
77 public A3(String x) {}
78 @Override
79 public String toString() {
80 return "c";
81 }
82 }
83 @RestPost(path="/c/{P}")
84 public void c(A3 f) { }
85
86
87 @Path("P")
88 public static class A4 {
89 @Override
90 public String toString() {
91 return "d";
92 }
93 }
94 @RestDelete(path="/d/{P}")
95 public void d(A4 f) { }
96
97 @Path("P")
98 @Schema(e="a,b")
99 public static class A5 {
100 @Override
101 public String toString() {
102 return "e";
103 }
104 }
105 @RestOp(path="/e/{P}")
106 public void e(A5 f) { }
107 }
108
109 @Test void a01_fromPojo() {
110 var s = getSwagger(A.class);
111 var x = s.getParameterInfo("/a/{P}","get","path","P");
112
113 assertBean(x, "in,name,type,description,required,enum", "path,P,string,a\nb,true,[a,b]");
114
115 x = s.getParameterInfo("/b/{P}","put","path","P");
116 assertBean(x, "in,name,type,description,required,enum", "path,P,string,a\nb,true,[a,b]");
117
118 x = s.getParameterInfo("/c/{P}","post","path","P");
119 assertBean(x, "in,name,type,description,required,enum", "path,P,string,b\nc,true,[b,c]");
120
121 x = s.getParameterInfo("/d/{P}","delete","path","P");
122 assertBean(x, "in,name,type,required", "path,P,string,true");
123
124 x = s.getParameterInfo("/e/{P}","get","path","P");
125 assertBean(x, "in,name,type,required,enum", "path,P,string,true,[a,b]");
126 }
127
128 @Rest
129 public static class B {
130
131 @Path(name="P")
132 public static class B1 {}
133 @RestGet(path="/a/{P}")
134 public void a(B1 f) { }
135
136 @Path("P")
137 public static class B2 {
138 public String f1;
139 }
140 @RestPut(path="/b/{P}")
141 public void b(B2 b) { }
142
143 @Path("P")
144 public static class B3 extends LinkedList<String> {
145 private static final long serialVersionUID = 1L;
146 }
147 @RestPost(path="/c/{P}")
148 public void c(B3 b) { }
149
150 @Path("P")
151 public static class B4 {}
152 @RestDelete(path="/d/{P}")
153 public void d(B4 b) { }
154 }
155
156 @Test void b01_schemaFromPojo() {
157 var s = getSwagger(B.class);
158 var x = s.getParameterInfo("/a/{P}","get","path","P");
159
160 assertBean(x, "in,name,type,required", "path,P,string,true");
161
162 x = s.getParameterInfo("/b/{P}","put","path","P");
163 assertBean(x, "in,name,type,required,schema{properties{f1{type}}}", "path,P,object,true,{{{string}}}");
164
165 x = s.getParameterInfo("/c/{P}","post","path","P");
166 assertBean(x, "in,name,type,required,items{type}", "path,P,array,true,{string}");
167
168 x = s.getParameterInfo("/d/{P}","delete","path","P");
169 assertBean(x, "in,name,type,required", "path,P,string,true");
170 }
171
172 @Rest
173 public static class D {
174
175 @RestGet(path="/a/{P}")
176 public void a(
177 @Path("P")
178 @Schema(d="a", t="string")
179 String h
180 ) { }
181
182 @RestPut(path="/b/{P}")
183 public void b(
184 @Path(
185 name="P",
186 schema=@Schema(description="a",type="string")
187 )
188 String h
189 ) { }
190
191 @RestPost(path="/c/{P}")
192 public void c(
193 @Path(
194 name="P",
195 schema=@Schema(description="b",type="string")
196 )
197 @Schema(d="a", t="string")
198 String h
199 ) { }
200
201 @RestDelete(path="/d/{P}")
202 public void d(@Path("P") String h) { }
203
204 @RestOp(path="/e/{P}")
205 public void e(@Path("P") @Schema(e="a,b") String h) { }
206 }
207
208 @Test void d01_fromParameter() {
209 var s = getSwagger(D.class);
210 var x = s.getParameterInfo("/a/{P}","get","path","P");
211
212 assertBean(x, "description,type", "a,string");
213
214 x = s.getParameterInfo("/b/{P}","put","path","P");
215 assertBean(x, "description,type", "a,string");
216
217 x = s.getParameterInfo("/c/{P}","post","path","P");
218 assertBean(x, "description,type", "b,string");
219
220 x = s.getParameterInfo("/d/{P}","delete","path","P");
221
222 x = s.getParameterInfo("/e/{P}","get","path","P");
223 assertList(x.getEnum(), "a", "b");
224 }
225
226 @Rest
227 public static class E {
228
229 @RestGet(path="/a/{P}")
230 public void a(@Path("P") String h) { }
231
232 public static class E2 {
233 public String f1;
234 }
235 @RestPut(path="/b/{P}")
236 public void b(@Path("P") E2 b) { }
237
238 public static class E3 extends LinkedList<String> {
239 private static final long serialVersionUID = 1L;
240 }
241 @RestPost(path="/c/{P}")
242 public void c(@Path("P") E3 b) { }
243
244 public static class E4 {}
245 @RestDelete(path="/d/{P}")
246 public void d(@Path("P") E4 b) { }
247
248 @RestOp(path="/e/{P}")
249 public void e(@Path("P") Integer b) { }
250
251 @RestGet(path="/f/{P}")
252 public void f(@Path("P") Boolean b) { }
253 }
254
255 @Test void d01_schemaFromParameter() {
256 var s = getSwagger(E.class);
257 var x = s.getParameterInfo("/a/{P}","get","path","P");
258
259 assertBean(x, "in,name,type,required", "path,P,string,true");
260
261 x = s.getParameterInfo("/b/{P}","put","path","P");
262 assertBean(x, "in,name,type,required,schema{properties{f1{type}}}", "path,P,object,true,{{{string}}}");
263
264 x = s.getParameterInfo("/c/{P}","post","path","P");
265 assertBean(x, "in,name,type,required,items{type}", "path,P,array,true,{string}");
266
267 x = s.getParameterInfo("/d/{P}","delete","path","P");
268 assertBean(x, "in,name,type,required", "path,P,string,true");
269
270 x = s.getParameterInfo("/e/{P}","get","path","P");
271 assertBean(x, "in,name,type,required,format", "path,P,integer,true,int32");
272
273 x = s.getParameterInfo("/f/{P}","get","path","P");
274 assertBean(x, "in,name,type,required", "path,P,boolean,true");
275 }
276 }