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