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