001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.http.annotation; 014 015import static java.lang.annotation.ElementType.*; 016import static java.lang.annotation.RetentionPolicy.*; 017 018import java.lang.annotation.*; 019import java.util.*; 020 021import org.apache.juneau.*; 022import org.apache.juneau.annotation.*; 023import org.apache.juneau.httppart.*; 024import org.apache.juneau.json.*; 025import org.apache.juneau.jsonschema.*; 026import org.apache.juneau.oapi.*; 027 028/** 029 * REST request form-data annotation. 030 * 031 * <p> 032 * Identifies a POJO to be used as a form-data entry on an HTTP request. 033 * 034 * <p> 035 * Can be used in the following locations: 036 * <ul> 037 * <li>Arguments and argument-types of server-side <ja>@RestMethod</ja>-annotated methods. 038 * <li>Arguments and argument-types of client-side <ja>@RemoteResource</ja>-annotated interfaces. 039 * <li>Methods and return types of server-side and client-side <ja>@Request</ja>-annotated interfaces. 040 * </ul> 041 * 042 * <h5 class='topic'>Arguments and argument-types of server-side @RestMethod-annotated methods</h5> 043 * 044 * Annotation that can be applied to a parameter of a <ja>@RestMethod</ja>-annotated method to identify it as a URL query parameter. 045 * 046 * <p> 047 * Unlike {@link FormData @FormData}, using this annotation does not result in the servlet reading the contents of 048 * URL-encoded form posts. 049 * Therefore, this annotation can be used in conjunction with the {@link Body @Body} annotation or 050 * <code>RestRequest.getBody()</code> method for <code>application/x-www-form-urlencoded POST</code> calls. 051 * 052 * <h5 class='section'>Example:</h5> 053 * <p class='bcode w800'> 054 * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>) 055 * <jk>public void</jk> doGet( 056 * <ja>@Query</ja>(<js>"p1"</js>) <jk>int</jk> p1, 057 * <ja>@Query</ja>(<js>"p2"</js>) String p2, 058 * <ja>@Query</ja>(<js>"p3"</js>) UUID p3 059 * ) {...} 060 * </p> 061 * 062 * <p> 063 * This is functionally equivalent to the following code... 064 * <p class='bcode w800'> 065 * <ja>@RestMethod</ja>(name=<jsf>GET</jsf>) 066 * <jk>public void</jk> doGet(RestRequest req, RestResponse res) { 067 * <jk>int</jk> p1 = req.getQueryParameter(<jk>int</jk>.<jk>class</jk>, <js>"p1"</js>, 0); 068 * String p2 = req.getQueryParameter(String.<jk>class</jk>, <js>"p2"</js>); 069 * UUID p3 = req.getQueryParameter(UUID.<jk>class</jk>, <js>"p3"</js>); 070 * ... 071 * } 072 * </p> 073 * 074 * <h5 class='section'>See Also:</h5> 075 * <ul> 076 * <li class='link'>{@doc juneau-rest-server.HttpPartAnnotations.Query} 077 * <li class='link'>{@doc juneau-rest-server.Swagger} 078 * <li class='extlink'>{@doc SwaggerParameterObject} 079 * </ul> 080 * 081 * <h5 class='topic'>Arguments and argument-types of client-side @RemoteResource-annotated interfaces</h5> 082 * 083 * <h5 class='section'>See Also:</h5> 084 * <ul class='doctree'> 085 * <li class='link'>{@doc juneau-rest-client.RestProxies.Query} 086 * </ul> 087 * 088 * <h5 class='topic'>Methods and return types of server-side and client-side @Request-annotated interfaces</h5> 089 * 090 * <h5 class='section'>See Also:</h5> 091 * <ul class='doctree'> 092 * <li class='link'>{@doc juneau-rest-server.HttpPartAnnotations.Request} 093 * <li class='link'>{@doc juneau-rest-client.RestProxies.Request} 094 * </ul> 095 */ 096@Documented 097@Target({PARAMETER,FIELD,METHOD,TYPE}) 098@Retention(RUNTIME) 099@Inherited 100public @interface Query { 101 102 /** 103 * Skips this value during serialization if it's an empty string or empty collection/array. 104 * 105 * <p> 106 * Note that <jk>null</jk> values are already ignored. 107 * 108 * <h5 class='section'>Used for:</h5> 109 * <ul class='spaced-list'> 110 * <li> 111 * Client-side schema-based serializing. 112 * </ul> 113 */ 114 boolean skipIfEmpty() default false; 115 116 /** 117 * Specifies the {@link HttpPartSerializer} class used for serializing values to strings. 118 * 119 * <p> 120 * Overrides for this part the part serializer defined on the REST client which by default is {@link OpenApiSerializer}. 121 */ 122 Class<? extends HttpPartSerializer> serializer() default HttpPartSerializer.Null.class; 123 124 /** 125 * Specifies the {@link HttpPartParser} class used for parsing strings to values. 126 * 127 * <p> 128 * Overrides for this part the part parser defined on the REST resource which by default is {@link OpenApiParser}. 129 */ 130 Class<? extends HttpPartParser> parser() default HttpPartParser.Null.class; 131 132 //================================================================================================================= 133 // Attributes common to all Swagger Parameter objects 134 //================================================================================================================= 135 136 /** 137 * URL query parameter name. 138 * 139 * Required. The name of the parameter. Parameter names are case sensitive. 140 * 141 * <p> 142 * The value should be either a valid query parameter name, or <js>"*"</js> to represent multiple name/value pairs 143 * 144 * <p> 145 * A blank value (the default) has the following behavior: 146 * <ul class='spaced-list'> 147 * <li> 148 * If the data type is <code>NameValuePairs</code>, <code>Map</code>, or a bean, 149 * then it's the equivalent to <js>"*"</js> which will cause the value to be serialized as name/value pairs. 150 * 151 * <h5 class='figure'>Examples:</h5> 152 * <p class='bcode w800'> 153 * <jc>// When used on a REST method</jc> 154 * <ja>@RestMethod</ja>(path=<js>"/addPet"</js>) 155 * <jk>public void</jk> addPet(<ja>@Query</ja> ObjectMap allQueryParameters) {...} 156 * </p> 157 * <p class='bcode w800'> 158 * <jc>// When used on a remote method parameter</jc> 159 * <ja>@RemoteResource</ja>(path=<js>"/myproxy"</js>) 160 * <jk>public interface</jk> MyProxy { 161 * 162 * <jc>// Equivalent to @Query("*")</jc> 163 * <ja>@RemoteMethod</ja>(path=<js>"/mymethod"</js>) 164 * String myProxyMethod1(<ja>@Query</ja> Map<String,Object> allQueryParameters); 165 * } 166 * </p> 167 * <p class='bcode w800'> 168 * <jc>// When used on a request bean method</jc> 169 * <jk>public interface</jk> MyRequest { 170 * 171 * <jc>// Equivalent to @Query("*")</jc> 172 * <ja>@Query</ja> 173 * Map<String,Object> getFoo(); 174 * } 175 * </p> 176 * </li> 177 * <li> 178 * If used on a request bean method, uses the bean property name. 179 * 180 * <h5 class='figure'>Example:</h5> 181 * <p class='bcode w800'> 182 * <jk>public interface</jk> MyRequest { 183 * 184 * <jc>// Equivalent to @Query("foo")</jc> 185 * <ja>@Query</ja> 186 * String getFoo(); 187 * } 188 * </p> 189 * </li> 190 * </ul> 191 * <h5 class='section'>Notes:</h5> 192 * <ul class='spaced-list'> 193 * <li> 194 * The format is plain-text. 195 * </ul> 196 */ 197 String name() default ""; 198 199 /** 200 * A synonym for {@link #name()}. 201 * 202 * <p> 203 * Allows you to use shortened notation if you're only specifying the name. 204 * 205 * <p> 206 * The following are completely equivalent ways of defining the existence of a query entry: 207 * <p class='bcode w800'> 208 * <jk>public</jk> Order placeOrder(<ja>@Query</ja>(name=<js>"petId"</js>) <jk>long</jk> petId) {...} 209 * </p> 210 * <p class='bcode w800'> 211 * <jk>public</jk> Order placeOrder(<ja>@Query</ja>(<js>"petId"</js>) <jk>long</jk> petId) {...} 212 * </p> 213 */ 214 String value() default ""; 215 216 /** 217 * <mk>description</mk> field of the {@doc SwaggerParameterObject}. 218 * 219 * <p> 220 * A brief description of the parameter. This could contain examples of use. 221 * 222 * <h5 class='section'>Used for:</h5> 223 * <ul class='spaced-list'> 224 * <li> 225 * Server-side generated Swagger documentation. 226 * </ul> 227 * 228 * <h5 class='section'>Notes:</h5> 229 * <ul class='spaced-list'> 230 * <li> 231 * The format is plain text. 232 * <br>Multiple lines are concatenated with newlines. 233 * <li> 234 * Supports {@doc DefaultRestSvlVariables} 235 * (e.g. <js>"$L{my.localized.variable}"</js>). 236 * </ul> 237 */ 238 String[] description() default {}; 239 240 /** 241 * <mk>required</mk> field of the {@doc SwaggerParameterObject}. 242 * 243 * <p> 244 * Determines whether the parameter is mandatory. 245 * 246 * <p> 247 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 248 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 249 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 250 * 251 * <h5 class='section'>Used for:</h5> 252 * <ul class='spaced-list'> 253 * <li> 254 * Server-side schema-based parsing validation. 255 * <li> 256 * Server-side generated Swagger documentation. 257 * <li> 258 * Client-side schema-based serializing validation. 259 * </ul> 260 */ 261 boolean required() default false; 262 263 //================================================================================================================= 264 // Attributes specific to parameters other than body 265 //================================================================================================================= 266 267 /** 268 * <mk>type</mk> field of the {@doc SwaggerParameterObject}. 269 * 270 * <p> 271 * The type of the parameter. 272 * 273 * <p> 274 * The possible values are: 275 * <ul class='spaced-list'> 276 * <li> 277 * <js>"string"</js> 278 * <br>Parameter must be a string or a POJO convertible from a string. 279 * <li> 280 * <js>"number"</js> 281 * <br>Parameter must be a number primitive or number object. 282 * <br>If parameter is <code>Object</code>, creates either a <code>Float</code> or <code>Double</code> depending on the size of the number. 283 * <li> 284 * <js>"integer"</js> 285 * <br>Parameter must be a integer/long primitive or integer/long object. 286 * <br>If parameter is <code>Object</code>, creates either a <code>Short</code>, <code>Integer</code>, or <code>Long</code> depending on the size of the number. 287 * <li> 288 * <js>"boolean"</js> 289 * <br>Parameter must be a boolean primitive or object. 290 * <li> 291 * <js>"array"</js> 292 * <br>Parameter must be an array or collection. 293 * <br>Elements must be strings or POJOs convertible from strings. 294 * <br>If parameter is <code>Object</code>, creates an {@link ObjectList}. 295 * <li> 296 * <js>"object"</js> 297 * <br>Parameter must be a map or bean. 298 * <br>If parameter is <code>Object</code>, creates an {@link ObjectMap}. 299 * <br>Note that this is an extension of the OpenAPI schema as Juneau allows for arbitrarily-complex POJOs to be serialized as HTTP parts. 300 * <li> 301 * <js>"file"</js> 302 * <br>This type is currently not supported. 303 * </ul> 304 * 305 * <p> 306 * Static strings are defined in {@link ParameterType}. 307 * 308 * <h5 class='section'>Used for:</h5> 309 * <ul class='spaced-list'> 310 * <li> 311 * Server-side schema-based parsing. 312 * <li> 313 * Server-side generated Swagger documentation. 314 * <li> 315 * Client-side schema-based serializing. 316 * </ul> 317 * 318 * <h5 class='section'>See Also:</h5> 319 * <ul class='doctree'> 320 * <li class='extlink'>{@doc SwaggerDataTypes} 321 * </ul> 322 */ 323 String type() default ""; 324 325 /** 326 * <mk>format</mk> field of the {@doc SwaggerParameterObject}. 327 * 328 * <p> 329 * The extending format for the previously mentioned {@doc SwaggerParameterTypes parameter type}. 330 * 331 * <p> 332 * The possible values are: 333 * <ul class='spaced-list'> 334 * <li> 335 * <js>"int32"</js> - Signed 32 bits. 336 * <br>Only valid with type <js>"integer"</js>. 337 * <li> 338 * <js>"int64"</js> - Signed 64 bits. 339 * <br>Only valid with type <js>"integer"</js>. 340 * <li> 341 * <js>"float"</js> - 32-bit floating point number. 342 * <br>Only valid with type <js>"number"</js>. 343 * <li> 344 * <js>"double"</js> - 64-bit floating point number. 345 * <br>Only valid with type <js>"number"</js>. 346 * <li> 347 * <js>"byte"</js> - BASE-64 encoded characters. 348 * <br>Only valid with type <js>"string"</js>. 349 * <br>Parameters of type POJO convertible from string are converted after the string has been decoded. 350 * <li> 351 * <js>"binary"</js> - Hexadecimal encoded octets (e.g. <js>"00FF"</js>). 352 * <br>Only valid with type <js>"string"</js>. 353 * <br>Parameters of type POJO convertible from string are converted after the string has been decoded. 354 * <li> 355 * <js>"date"</js> - An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 full-date</a>. 356 * <br>Only valid with type <js>"string"</js>. 357 * <li> 358 * <js>"date-time"</js> - An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 date-time</a>. 359 * <br>Only valid with type <js>"string"</js>. 360 * <li> 361 * <js>"password"</js> - Used to hint UIs the input needs to be obscured. 362 * <br>This format does not affect the serialization or parsing of the parameter. 363 * <li> 364 * <js>"uon"</js> - UON notation (e.g. <js>"(foo=bar,baz=@(qux,123))"</js>). 365 * <br>Only valid with type <js>"object"</js>. 366 * <br>If not specified, then the input is interpreted as plain-text and is converted to a POJO directly. 367 * </ul> 368 * 369 * <p> 370 * Static strings are defined in {@link FormatType}. 371 * 372 * <h5 class='section'>Used for:</h5> 373 * <ul class='spaced-list'> 374 * <li> 375 * Server-side schema-based parsing. 376 * <li> 377 * Server-side generated Swagger documentation. 378 * <li> 379 * Client-side schema-based serializing. 380 * </ul> 381 * 382 * <h5 class='section'>See Also:</h5> 383 * <ul class='doctree'> 384 * <li class='extlink'>{@doc SwaggerDataTypeFormats} 385 * </ul> 386 */ 387 String format() default ""; 388 389 /** 390 * <mk>allowEmptyValue</mk> field of the {@doc SwaggerParameterObject}. 391 * 392 * <p> 393 * Sets the ability to pass empty-valued parameters. 394 * <br>This is valid only for either query or formData parameters and allows you to send a parameter with a name only or an empty value. 395 * 396 * <p> 397 * The default value is <jk>false</jk>. 398 * 399 * <h5 class='section'>Used for:</h5> 400 * <ul class='spaced-list'> 401 * <li> 402 * Server-side schema-based parsing validation. 403 * <li> 404 * Server-side generated Swagger documentation. 405 * <li> 406 * Client-side schema-based serializing validation. 407 * </ul> 408 */ 409 boolean allowEmptyValue() default false; 410 411 /** 412 * <mk>items</mk> field of the {@doc SwaggerParameterObject}. 413 * 414 * <p> 415 * Describes the type of items in the array. 416 * 417 * <p> 418 * Required if <code>type</code> is <js>"array"</js>. 419 * <br>Can only be used if <code>type</code> is <js>"array"</js>. 420 * 421 * <h5 class='section'>Used for:</h5> 422 * <ul class='spaced-list'> 423 * <li> 424 * Server-side schema-based parsing and parsing validation. 425 * <li> 426 * Server-side generated Swagger documentation. 427 * <li> 428 * Client-side schema-based serializing and serializing validation. 429 * </ul> 430 */ 431 Items items() default @Items; 432 433 /** 434 * <mk>collectionFormat</mk> field of the {@doc SwaggerParameterObject}. 435 * 436 * <p> 437 * Determines the format of the array if <code>type</code> <js>"array"</js> is used. 438 * <br>Can only be used if <code>type</code> is <js>"array"</js>. 439 * 440 * <br>Possible values are: 441 * <ul class='spaced-list'> 442 * <li> 443 * <js>"csv"</js> (default) - Comma-separated values (e.g. <js>"foo,bar"</js>). 444 * <li> 445 * <js>"ssv"</js> - Space-separated values (e.g. <js>"foo bar"</js>). 446 * <li> 447 * <js>"tsv"</js> - Tab-separated values (e.g. <js>"foo\tbar"</js>). 448 * <li> 449 * <js>"pipes</js> - Pipe-separated values (e.g. <js>"foo|bar"</js>). 450 * <li> 451 * <js>"multi"</js> - Corresponds to multiple parameter instances instead of multiple values for a single instance (e.g. <js>"foo=bar&foo=baz"</js>). 452 * <br>Note: This is not supported by {@link OpenApiSerializer}. 453 * <li> 454 * <js>"uon"</js> - UON notation (e.g. <js>"@(foo,bar)"</js>). 455 * </ul> 456 * 457 * <p> 458 * Static strings are defined in {@link CollectionFormatType}. 459 * 460 * <p> 461 * Note that for collections/arrays parameters with POJO element types, the input is broken into a string array before being converted into POJO elements. 462 * 463 * <h5 class='section'>Used for:</h5> 464 * <ul class='spaced-list'> 465 * <li> 466 * Server-side schema-based parsing. 467 * <li> 468 * Server-side generated Swagger documentation. 469 * <li> 470 * Client-side schema-based serializing. 471 * </ul> 472 */ 473 String collectionFormat() default ""; 474 475 /** 476 * <mk>default</mk> field of the {@doc SwaggerParameterObject}. 477 * 478 * <p> 479 * Declares the value of the parameter that the server will use if none is provided, for example a "count" to control the number of results per page might default to 100 if not supplied by the client in the request. 480 * <br>(Note: "default" has no meaning for required parameters.) 481 * 482 * <p> 483 * Additionally, this value is used to create instances of POJOs that are then serialized as language-specific examples in the generated Swagger documentation 484 * if the examples are not defined in some other way. 485 * 486 * <p> 487 * The format of this value is a string. 488 * <br>Multiple lines are concatenated with newlines. 489 * 490 * <h5 class='section'>Examples:</h5> 491 * <p class='bcode w800'> 492 * <jk>public</jk> Order placeOrder( 493 * <ja>@Query</ja>(name=<js>"petId"</js>, _default=<js>"100"</js>) <jk>long</jk> petId, 494 * <ja>@Query</ja>(name=<js>"additionalInfo"</js>, format=<js>"uon"</js>, _default=<js>"(rushOrder=false)"</js>) AdditionalInfo additionalInfo, 495 * <ja>@Query</ja>(name=<js>"flags"</js>, collectionFormat=<js>"uon"</js>, _default=<js>"@(new-customer)"</js>) String[] flags 496 * ) {...} 497 * </p> 498 * 499 * <h5 class='section'>Used for:</h5> 500 * <ul class='spaced-list'> 501 * <li> 502 * Server-side schema-based parsing. 503 * <li> 504 * Server-side generated Swagger documentation. 505 * <li> 506 * Client-side schema-based serializing. 507 * </ul> 508 */ 509 String[] _default() default {}; 510 511 /** 512 * <mk>maximum</mk> field of the {@doc SwaggerParameterObject}. 513 * 514 * <p> 515 * Defines the maximum value for a parameter of numeric types. 516 * <br>The value must be a valid JSON number. 517 * 518 * <p> 519 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 520 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 521 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 522 * 523 * <p> 524 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 525 * 526 * <h5 class='section'>Used for:</h5> 527 * <ul class='spaced-list'> 528 * <li> 529 * Server-side schema-based parsing validation. 530 * <li> 531 * Server-side generated Swagger documentation. 532 * <li> 533 * Client-side schema-based serializing validation. 534 * </ul> 535 */ 536 String maximum() default ""; 537 538 /** 539 * <mk>exclusiveMaximum</mk> field of the {@doc SwaggerParameterObject}. 540 * 541 * <p> 542 * Defines whether the maximum is matched exclusively. 543 * 544 * <p> 545 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 546 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 547 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 548 * 549 * <p> 550 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 551 * <br>If <jk>true</jk>, must be accompanied with <code>maximum</code>. 552 * 553 * <h5 class='section'>Used for:</h5> 554 * <ul class='spaced-list'> 555 * <li> 556 * Server-side schema-based parsing validation. 557 * <li> 558 * Server-side generated Swagger documentation. 559 * <li> 560 * Client-side schema-based serializing validation. 561 * </ul> 562 */ 563 boolean exclusiveMaximum() default false; 564 565 /** 566 * <mk>minimum</mk> field of the {@doc SwaggerParameterObject}. 567 * 568 * <p> 569 * Defines the minimum value for a parameter of numeric types. 570 * <br>The value must be a valid JSON number. 571 * 572 * <p> 573 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 574 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 575 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 576 * 577 * <p> 578 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 579 * 580 * <h5 class='section'>Used for:</h5> 581 * <ul class='spaced-list'> 582 * <li> 583 * Server-side schema-based parsing validation. 584 * <li> 585 * Server-side generated Swagger documentation. 586 * <li> 587 * Client-side schema-based serializing validation. 588 * </ul> 589 */ 590 String minimum() default ""; 591 592 /** 593 * <mk>exclusiveMinimum</mk> field of the {@doc SwaggerParameterObject}. 594 * 595 * <p> 596 * Defines whether the minimum is matched exclusively. 597 * 598 * <p> 599 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 600 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 601 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 602 * 603 * <p> 604 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 605 * <br>If <jk>true</jk>, Must be accompanied with <code>minimum</code>. 606 * 607 * <h5 class='section'>Used for:</h5> 608 * <ul class='spaced-list'> 609 * <li> 610 * Server-side schema-based parsing validation. 611 * <li> 612 * Server-side generated Swagger documentation. 613 * <li> 614 * Client-side schema-based serializing validation. 615 * </ul> 616 */ 617 boolean exclusiveMinimum() default false; 618 619 /** 620 * <mk>maxLength</mk> field of the {@doc SwaggerParameterObject}. 621 * 622 * <p> 623 * A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword. 624 * <br>The length of a string instance is defined as the number of its characters as defined by <a href='https://tools.ietf.org/html/rfc4627'>RFC 4627</a>. 625 * <br>The value <code>-1</code> is always ignored. 626 * 627 * <p> 628 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 629 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 630 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 631 * 632 * <p> 633 * Only allowed for the following types: <js>"string"</js>. 634 * 635 * <h5 class='section'>Used for:</h5> 636 * <ul class='spaced-list'> 637 * <li> 638 * Server-side schema-based parsing validation. 639 * <li> 640 * Server-side generated Swagger documentation. 641 * <li> 642 * Client-side schema-based serializing validation. 643 * </ul> 644 */ 645 long maxLength() default -1; 646 647 /** 648 * <mk>minLength</mk> field of the {@doc SwaggerParameterObject}. 649 * 650 * <p> 651 * A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword. 652 * <br>The length of a string instance is defined as the number of its characters as defined by <a href='https://tools.ietf.org/html/rfc4627'>RFC 4627</a>. 653 * <br>The value <code>-1</code> is always ignored. 654 * 655 * <p> 656 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 657 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 658 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 659 * 660 * <p> 661 * Only allowed for the following types: <js>"string"</js>. 662 * 663 * <h5 class='section'>Used for:</h5> 664 * <ul class='spaced-list'> 665 * <li> 666 * Server-side schema-based parsing validation. 667 * <li> 668 * Server-side generated Swagger documentation. 669 * <li> 670 * Client-side schema-based serializing validation. 671 * </ul> 672 */ 673 long minLength() default -1; 674 675 /** 676 * <mk>pattern</mk> field of the {@doc SwaggerParameterObject}. 677 * 678 * <p> 679 * A string input is valid if it matches the specified regular expression pattern. 680 * 681 * <p> 682 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 683 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 684 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 685 * 686 * <p> 687 * Only allowed for the following types: <js>"string"</js>. 688 * 689 * <h5 class='section'>Used for:</h5> 690 * <ul class='spaced-list'> 691 * <li> 692 * Server-side schema-based parsing validation. 693 * <li> 694 * Server-side generated Swagger documentation. 695 * <li> 696 * Client-side schema-based serializing validation. 697 * </ul> 698 */ 699 String pattern() default ""; 700 701 /** 702 * <mk>maxItems</mk> field of the {@doc SwaggerParameterObject}. 703 * 704 * <p> 705 * An array or collection is valid if its size is less than, or equal to, the value of this keyword. 706 * 707 * <p> 708 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 709 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 710 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 711 * 712 * <p> 713 * Only allowed for the following types: <js>"array"</js>. 714 * 715 * <h5 class='section'>Used for:</h5> 716 * <ul class='spaced-list'> 717 * <li> 718 * Server-side schema-based parsing validation. 719 * <li> 720 * Server-side generated Swagger documentation. 721 * <li> 722 * Client-side schema-based serializing validation. 723 * </ul> 724 */ 725 long maxItems() default -1; 726 727 /** 728 * <mk>minItems</mk> field of the {@doc SwaggerParameterObject}. 729 * 730 * <p> 731 * An array or collection is valid if its size is greater than, or equal to, the value of this keyword. 732 * 733 * <p> 734 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 735 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 736 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 737 * 738 * <p> 739 * Only allowed for the following types: <js>"array"</js>. 740 * 741 * <h5 class='section'>Used for:</h5> 742 * <ul class='spaced-list'> 743 * <li> 744 * Server-side schema-based parsing validation. 745 * <li> 746 * Server-side generated Swagger documentation. 747 * <li> 748 * Client-side schema-based serializing validation. 749 * </ul> 750 */ 751 long minItems() default -1; 752 753 /** 754 * <mk>uniqueItems</mk> field of the {@doc SwaggerParameterObject}. 755 * 756 * <p> 757 * If <jk>true</jk> the input validates successfully if all of its elements are unique. 758 * 759 * <p> 760 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 761 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 762 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 763 * 764 * <p> 765 * If the parameter type is a subclass of {@link Set}, this validation is skipped (since a set can only contain unique items anyway). 766 * <br>Otherwise, the collection or array is checked for duplicate items. 767 * 768 * <p> 769 * Only allowed for the following types: <js>"array"</js>. 770 * 771 * <h5 class='section'>Used for:</h5> 772 * <ul class='spaced-list'> 773 * <li> 774 * Server-side schema-based parsing validation. 775 * <li> 776 * Server-side generated Swagger documentation. 777 * <li> 778 * Client-side schema-based serializing validation. 779 * </ul> 780 */ 781 boolean uniqueItems() default false; 782 783 /** 784 * <mk>enum</mk> field of the {@doc SwaggerParameterObject}. 785 * 786 * <p> 787 * If specified, the input validates successfully if it is equal to one of the elements in this array. 788 * 789 * <p> 790 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 791 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 792 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 793 * 794 * <p> 795 * The format is a {@doc juneau-marshall.JsonDetails.SimplifiedJson} array or comma-delimited list. 796 * <br>Multiple lines are concatenated with newlines. 797 * 798 * <h5 class='section'>Examples:</h5> 799 * <p class='bcode w800'> 800 * <jc>// Comma-delimited list</jc> 801 * <jk>public</jk> Collection<Pet> findPetsByStatus( 802 * <ja>@Query</ja>( 803 * name=<js>"status"</js>, 804 * _enum=<js>"AVAILABLE,PENDING,SOLD"</js>, 805 * ) PetStatus status 806 * ) {...} 807 * </p> 808 * <p class='bcode w800'> 809 * <jc>// JSON array</jc> 810 * <jk>public</jk> Collection<Pet> findPetsByStatus( 811 * <ja>@Query</ja>( 812 * name=<js>"status"</js>, 813 * _enum=<js>"['AVAILABLE','PENDING','SOLD']"</js>, 814 * ) PetStatus status 815 * ) {...} 816 * </p> 817 * 818 * <h5 class='section'>Used for:</h5> 819 * <ul class='spaced-list'> 820 * <li> 821 * Server-side schema-based parsing validation. 822 * <li> 823 * Server-side generated Swagger documentation. 824 * <li> 825 * Client-side schema-based serializing validation. 826 * </ul> 827 */ 828 String[] _enum() default {}; 829 830 /** 831 * <mk>multipleOf</mk> field of the {@doc SwaggerParameterObject}. 832 * 833 * <p> 834 * A numeric instance is valid if the result of the division of the instance by this keyword's value is an integer. 835 * <br>The value must be a valid JSON number. 836 * 837 * <p> 838 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 839 * <br>On the client-side, this gets converted to a <code>RestCallException</code> which is thrown before the connection is made. 840 * <br>On the server-side, this gets converted to a <code>BadRequest</code> (400). 841 * 842 * <p> 843 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 844 * 845 * <h5 class='section'>Used for:</h5> 846 * <ul class='spaced-list'> 847 * <li> 848 * Server-side schema-based parsing validation. 849 * <li> 850 * Server-side generated Swagger documentation. 851 * <li> 852 * Client-side schema-based serializing validation. 853 * </ul> 854 */ 855 String multipleOf() default ""; 856 857 //================================================================================================================= 858 // Other 859 //================================================================================================================= 860 861 /** 862 * A serialized example of the parameter. 863 * 864 * <p> 865 * This attribute defines a representation of the value that is used by <code>BasicRestInfoProvider</code> to construct 866 * an example of parameter. 867 * 868 * <h5 class='section'>Example:</h5> 869 * <p class='bcode w800'> 870 * <ja>@Query</ja>( 871 * name=<js>"status"</js>, 872 * type=<js>"array"</js>, 873 * collectionFormat=<js>"csv"</js>, 874 * example=<js>"AVAILABLE,PENDING"</js> 875 * ) 876 * PetStatus[] status 877 * </p> 878 * 879 * <p> 880 * If not specified, Juneau will automatically create examples from sample POJOs serialized using the registered {@link HttpPartSerializer}. 881 * <br> 882 * 883 * </p> 884 * <h5 class='section'>Used for:</h5> 885 * <ul class='spaced-list'> 886 * <li> 887 * Server-side generated Swagger documentation. 888 * </ul> 889 * 890 * <h5 class='section'>See also:</h5> 891 * <ul> 892 * <li class='ja'>{@link Example} 893 * <li class='jc'>{@link BeanContext} 894 * <ul> 895 * <li class='jf'>{@link BeanContext#BEAN_examples BEAN_examples} 896 * </ul> 897 * <li class='jc'>{@link JsonSchemaSerializer} 898 * <ul> 899 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_addExamplesTo JSONSCHEMA_addExamplesTo} 900 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_allowNestedExamples JSONSCHEMA_allowNestedExamples} 901 * </ul> 902 * </ul> 903 * 904 * <h5 class='section'>Notes:</h5> 905 * <ul class='spaced-list'> 906 * <li> 907 * The format is a {@doc juneau-marshall.JsonDetails.SimplifiedJson} object or plain text string. 908 * <br>Multiple lines are concatenated with newlines. 909 * <li> 910 * Supports {@doc DefaultRestSvlVariables} 911 * (e.g. <js>"$L{my.localized.variable}"</js>). 912 * </ul> 913 */ 914 String[] example() default {}; 915 916 /** 917 * Free-form value for the {@doc SwaggerParameterObject}. 918 * 919 * <p> 920 * This is a {@doc juneau-marshall.JsonDetails.SimplifiedJson} object that makes up the swagger information for this field. 921 * 922 * <p> 923 * The following are completely equivalent ways of defining the swagger description of the Query object: 924 * <p class='bcode w800'> 925 * <jc>// Normal</jc> 926 * <ja>@Query</ja>( 927 * name=<js>"status"</js>, 928 * description=<js>"Status values that need to be considered for filter."</js>, 929 * required=<jk>true</jk>, 930 * type=<js>"array"</js>, 931 * items=<ja>@Items</ja>( 932 * type=<js>"string"</js>, 933 * _enum=<js>"AVAILABLE,PENDING,SOLD"</js>, 934 * _default=<js>"AVAILABLE"</js> 935 * ), 936 * example=<js>"['AVAILABLE','PENDING']"</js> 937 * ) 938 * </p> 939 * <p class='bcode w800'> 940 * <jc>// Free-form</jc> 941 * <ja>@Query</ja>( 942 * name=<js>"status"</js>, 943 * api={ 944 * <js>"description: 'Status values that need to be considered for filter.',"</js>, 945 * <js>"required: true,"</js>, 946 * <js>"type: 'array',"</js>, 947 * <js>"items: {"</js>, 948 * <js>"type: 'string',"</js>, 949 * <js>"enum: 'AVAILABLE,PENDING,SOLD',"</js>, 950 * <js>"default: 'AVAILABLE'"</js>, 951 * <js>"}"</js>, 952 * <js>"example: "['AVAILABLE','PENDING']"</js> 953 * } 954 * ) 955 * </p> 956 * <p class='bcode w800'> 957 * <jc>// Free-form using variables</jc> 958 * <ja>@Query</ja>( 959 * name=<js>"status"</js>, 960 * api=<js>"$L{statusSwagger}"</js> 961 * ) 962 * </p> 963 * <p class='bcode w800'> 964 * <mc>// Contents of MyResource.properties</mc> 965 * <mk>statusSwagger</mk> = <mv>{ description: "Status values that need to be considered for filter.", required: true, type: "array", items: {type: "string", enum: "AVAILABLE,PENDING,SOLD", default: "AVAILABLE"}, example: "['AVAILABLE','PENDING']" } }</mv> 966 * </p> 967 * 968 * <p> 969 * The reasons why you may want to use this field include: 970 * <ul> 971 * <li>You want to pull in the entire Swagger JSON definition for this field from an external source such as a properties file. 972 * <li>You want to add extra fields to the Swagger documentation that are not officially part of the Swagger specification. 973 * </ul> 974 * 975 * <h5 class='section'>Used for:</h5> 976 * <ul class='spaced-list'> 977 * <li> 978 * Server-side generated Swagger documentation. 979 * </ul> 980 * 981 * <h5 class='section'>Notes:</h5> 982 * <ul class='spaced-list'> 983 * <li> 984 * Note that the only swagger field you can't specify using this value is <js>"name"</js> whose value needs to be known during servlet initialization. 985 * <li> 986 * Automatic validation is NOT performed on input based on attributes in this value. 987 * <li> 988 * The format is a {@doc juneau-marshall.JsonDetails.SimplifiedJson} object. 989 * <li> 990 * The leading/trailing <code>{ }</code> characters are optional. 991 * <br>The following two example are considered equivalent: 992 * <p class='bcode w800'> 993 * <ja>@Query</ja>(api=<js>"{description: 'ID of order to fetch'}"</js>) 994 * </p> 995 * <p class='bcode w800'> 996 * <ja>@Query</ja>(api=<js>"description: 'ID of order to fetch''"</js>) 997 * </p> 998 * <li> 999 * Multiple lines are concatenated with newlines so that you can format the value to be readable. 1000 * <li> 1001 * Supports {@doc DefaultRestSvlVariables} 1002 * (e.g. <js>"$L{my.localized.variable}"</js>). 1003 * <li> 1004 * Values defined in this field supersede values pulled from the Swagger JSON file and are superseded by individual values defined on this annotation. 1005 * </ul> 1006 */ 1007 String[] api() default {}; 1008}