View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.rest.annotation;
18  
19  import static org.apache.juneau.TestUtils.*;
20  
21  import org.apache.juneau.*;
22  import org.apache.juneau.http.header.*;
23  import org.junit.jupiter.api.*;
24  
25  class Swagger_RestOp_Parameters extends TestBase {
26  
27  	//------------------------------------------------------------------------------------------------------------------
28  	// Swagger on default headers.
29  	//------------------------------------------------------------------------------------------------------------------
30  
31  	@Rest
32  	public static class A {
33  
34  		@RestGet
35  		public String accept(Accept accept) {
36  			return accept.getValue();
37  		}
38  		@RestPut
39  		public String acceptCharset(AcceptCharset acceptCharset) {
40  			return acceptCharset.getValue();
41  		}
42  		@RestPost
43  		public String acceptEncoding(AcceptEncoding acceptEncoding) {
44  			return acceptEncoding.getValue();
45  		}
46  		@RestDelete
47  		public String acceptLanguage(AcceptLanguage acceptLanguage) {
48  			return acceptLanguage.getValue();
49  		}
50  		@RestOp
51  		public String authorization(Authorization authorization) {
52  			return authorization.getValue();
53  		}
54  		@RestOp
55  		public String cacheControl(CacheControl cacheControl) {
56  			return cacheControl.getValue();
57  		}
58  		@RestOp
59  		public String connection(Connection connection) {
60  			return connection.getValue();
61  		}
62  		@RestOp
63  		public String contentLength(ContentLength contentLength) {
64  			return contentLength.getValue();
65  		}
66  		@RestOp
67  		public String contentType(ContentType contentType) {
68  			return contentType.getValue();
69  		}
70  		@RestOp
71  		public String date(org.apache.juneau.http.header.Date date) {
72  			return date.getValue();
73  		}
74  		@RestOp
75  		public String expect(Expect expect) {
76  			return expect.getValue();
77  		}
78  		@RestOp
79  		public String from(From from) {
80  			return from.getValue();
81  		}
82  		@RestOp
83  		public String host(Host host) {
84  			return host.getValue();
85  		}
86  		@RestOp
87  		public String ifMatch(IfMatch ifMatch) {
88  			return ifMatch.getValue();
89  		}
90  		@RestOp
91  		public String ifModifiedSince(IfModifiedSince ifModifiedSince) {
92  			return ifModifiedSince.getValue();
93  		}
94  		@RestOp
95  		public String ifNoneMatch(IfNoneMatch ifNoneMatch) {
96  			return ifNoneMatch.getValue();
97  		}
98  		@RestOp
99  		public String ifRange(IfRange ifRange) {
100 			return ifRange.getValue();
101 		}
102 		@RestOp
103 		public String ifUnmodifiedSince(IfUnmodifiedSince ifUnmodifiedSince) {
104 			return ifUnmodifiedSince.getValue();
105 		}
106 		@RestOp
107 		public String maxForwards(MaxForwards maxForwards) {
108 			return maxForwards.getValue();
109 		}
110 		@RestOp
111 		public String pragma(Pragma pragma) {
112 			return pragma.getValue();
113 		}
114 		@RestOp
115 		public String proxyAuthorization(ProxyAuthorization proxyAuthorization) {
116 			return proxyAuthorization.getValue();
117 		}
118 		@RestOp
119 		public String range(Range range) {
120 			return range.getValue();
121 		}
122 		@RestOp
123 		public String referer(Referer referer) {
124 			return referer.getValue();
125 		}
126 		@RestOp
127 		public String te(TE te) {
128 			return te.getValue();
129 		}
130 		@RestOp
131 		public String upgrade(Upgrade upgrade) {
132 			return upgrade.getValue();
133 		}
134 		@RestOp
135 		public String userAgent(UserAgent userAgent) {
136 			return userAgent.getValue();
137 		}
138 		@RestOp
139 		public String warning(Warning warning) {
140 			return warning.getValue();
141 		}
142 	}
143 
144 	@Test void a01_headerParameters() {
145 		var s = getSwagger(A.class);
146 		var x = s.getParameterInfo("/accept","get","header","Accept");
147 
148 		assertJson("{'in':'header',name:'Accept',type:'string'}", x);
149 
150 		x = s.getParameterInfo("/acceptCharset","put","header","Accept-Charset");
151 		assertJson("{'in':'header',name:'Accept-Charset',type:'string'}", x);
152 
153 		x = s.getParameterInfo("/acceptEncoding","post","header","Accept-Encoding");
154 		assertJson("{'in':'header',name:'Accept-Encoding',type:'string'}", x);
155 
156 		x = s.getParameterInfo("/acceptLanguage","delete","header","Accept-Language");
157 		assertJson("{'in':'header',name:'Accept-Language',type:'string'}", x);
158 
159 		x = s.getParameterInfo("/authorization","get","header","Authorization");
160 		assertJson("{'in':'header',name:'Authorization',type:'string'}", x);
161 
162 		x = s.getParameterInfo("/cacheControl","get","header","Cache-Control");
163 		assertJson("{'in':'header',name:'Cache-Control',type:'string'}", x);
164 
165 		x = s.getParameterInfo("/connection","get","header","Connection");
166 		assertJson("{'in':'header',name:'Connection',type:'string'}", x);
167 
168 		x = s.getParameterInfo("/contentLength","get","header","Content-Length");
169 		assertJson("{format:'int64','in':'header',name:'Content-Length',type:'integer'}", x);
170 
171 		x = s.getParameterInfo("/contentType","get","header","Content-Type");
172 		assertJson("{'in':'header',name:'Content-Type',type:'string'}", x);
173 
174 		x = s.getParameterInfo("/date","get","header","Date");
175 		assertJson("{'in':'header',name:'Date',type:'string'}", x);
176 
177 		x = s.getParameterInfo("/expect","get","header","Expect");
178 		assertJson("{'in':'header',name:'Expect',type:'string'}", x);
179 
180 		x = s.getParameterInfo("/from","get","header","From");
181 		assertJson("{'in':'header',name:'From',type:'string'}", x);
182 
183 		x = s.getParameterInfo("/host","get","header","Host");
184 		assertJson("{'in':'header',name:'Host',type:'string'}", x);
185 
186 		x = s.getParameterInfo("/ifMatch","get","header","If-Match");
187 		assertJson("{'in':'header',name:'If-Match',type:'string'}", x);
188 
189 		x = s.getParameterInfo("/ifModifiedSince","get","header","If-Modified-Since");
190 		assertJson("{'in':'header',name:'If-Modified-Since',type:'string'}", x);
191 
192 		x = s.getParameterInfo("/ifNoneMatch","get","header","If-None-Match");
193 		assertJson("{'in':'header',name:'If-None-Match',type:'string'}", x);
194 
195 		x = s.getParameterInfo("/ifRange","get","header","If-Range");
196 		assertJson("{'in':'header',name:'If-Range',type:'string'}", x);
197 
198 		x = s.getParameterInfo("/ifUnmodifiedSince","get","header","If-Unmodified-Since");
199 		assertJson("{'in':'header',name:'If-Unmodified-Since',type:'string'}", x);
200 
201 		x = s.getParameterInfo("/maxForwards","get","header","Max-Forwards");
202 		assertJson("{format:'int32','in':'header',name:'Max-Forwards',type:'integer'}", x);
203 
204 		x = s.getParameterInfo("/pragma","get","header","Pragma");
205 		assertJson("{'in':'header',name:'Pragma',type:'string'}", x);
206 
207 		x = s.getParameterInfo("/proxyAuthorization","get","header","Proxy-Authorization");
208 		assertJson("{'in':'header',name:'Proxy-Authorization',type:'string'}", x);
209 
210 		x = s.getParameterInfo("/range","get","header","Range");
211 		assertJson("{'in':'header',name:'Range',type:'string'}", x);
212 
213 		x = s.getParameterInfo("/referer","get","header","Referer");
214 		assertJson("{'in':'header',name:'Referer',type:'string'}", x);
215 
216 		x = s.getParameterInfo("/te","get","header","TE");
217 		assertJson("{'in':'header',name:'TE',type:'string'}", x);
218 
219 		x = s.getParameterInfo("/upgrade","get","header","Upgrade");
220 		assertJson("{'in':'header',name:'Upgrade',type:'string'}", x);
221 
222 		x = s.getParameterInfo("/userAgent","get","header","User-Agent");
223 		assertJson("{'in':'header',name:'User-Agent',type:'string'}", x);
224 
225 		x = s.getParameterInfo("/warning","get","header","Warning");
226 		assertJson("{'in':'header',name:'Warning',type:'string'}", x);
227 	}
228 }