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