001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.annotation; 018 019import static java.lang.annotation.ElementType.*; 020import static java.lang.annotation.RetentionPolicy.*; 021 022import java.lang.annotation.*; 023import java.util.*; 024 025import org.apache.juneau.collections.*; 026import org.apache.juneau.http.annotation.*; 027import org.apache.juneau.httppart.*; 028import org.apache.juneau.oapi.*; 029 030/** 031 * Swagger schema annotation. 032 * 033 * <p> 034 * The Schema Object allows the definition of input and output data types. 035 * These types can be objects, but also primitives and arrays. 036 * This object is based on the JSON Schema Specification Draft 4 and uses a predefined subset of it. 037 * On top of this subset, there are extensions provided by this specification to allow for more complete documentation. 038 * 039 * <p> 040 * Used to populate the auto-generated Swagger documentation and UI for server-side <ja>@Rest</ja>-annotated classes. 041 * <br>Also used to define OpenAPI schema information for POJOs serialized through {@link OpenApiSerializer} and parsed through {@link OpenApiParser}. 042 * 043 * <h5 class='section'>Examples:</h5> 044 * <p class='bjava'> 045 * <jc>// A response object thats a hex-encoded string</jc> 046 * <ja>@Response</ja>( 047 * schema=<ja>@Schema</ja>( 048 * type=<js>"string"</js>, 049 * format=<js>"binary"</js> 050 * ) 051 * ) 052 * </p> 053 * <p class='bjava'> 054 * <jc>// A request body consisting of an array of arrays, the internal 055 * // array being of type integer, numbers must be between 0 and 63 (inclusive)</jc> 056 * <ja>@Content</ja>( 057 * schema=<ja>@Schema</ja>( 058 * items=<ja>@Items</ja>( 059 * type=<js>"array"</js>, 060 * items=<ja>@SubItems</ja>( 061 * type=<js>"integer"</js>, 062 * minimum=<js>"0"</js>, 063 * maximum=<js>"63"</js> 064 * ) 065 * ) 066 * ) 067 * ) 068 * </p> 069 * 070 * <h5 class='section'>See Also:</h5><ul> 071 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> 072 * <li class='extlink'><a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a> 073 074 * </ul> 075 */ 076@Documented 077@Target({PARAMETER,METHOD,TYPE,FIELD}) 078@Retention(RUNTIME) 079@Repeatable(SchemaAnnotation.Array.class) 080@ContextApply(SchemaAnnotation.Apply.class) 081public @interface Schema { 082 083 /** 084 * <mk>default</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 085 * 086 * <p> 087 * 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. 088 * <br>(Note: "default" has no meaning for required parameters.) 089 * 090 * <p> 091 * Additionally, this value is used to create instances of POJOs that are then serialized as language-specific examples in the generated Swagger documentation 092 * if the examples are not defined in some other way. 093 * 094 * <p> 095 * The format of this value is a string. 096 * <br>Multiple lines are concatenated with newlines. 097 * 098 * <h5 class='section'>Examples:</h5> 099 * <p class='bjava'> 100 * <jk>public</jk> Order placeOrder( 101 * <ja>@Header</ja>(<js>"X-PetId"</js>) 102 * <ja>@Schema</ja>(_default=<js>"100"</js>) 103 * <jk>long</jk> <jv>petId</jv>, 104 * 105 * <ja>@Header</ja>(<js>"X-AdditionalInfo"</js>) 106 * <ja>@Schema</ja>(format=<js>"uon"</js>, _default=<js>"(rushOrder=false)"</js>) 107 * AdditionalInfo <jv>additionalInfo</jv>, 108 * 109 * <ja>@Header</ja>(<js>"X-Flags"</js>) 110 * <ja>@Schema</ja>(collectionFormat=<js>"uon"</js>, _default=<js>"@(new-customer)"</js>) 111 * String[] <jv>flags</jv> 112 * ) {...} 113 * </p> 114 * 115 * <h5 class='section'>Used for:</h5> 116 * <ul class='spaced-list'> 117 * <li> 118 * Server-side schema-based parsing. 119 * <li> 120 * Server-side generated Swagger documentation. 121 * <li> 122 * Client-side schema-based serializing. 123 * </ul> 124 * 125 * @return The annotation value. 126 */ 127 String[] _default() default {}; 128 129 /** 130 * <mk>enum</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 131 * 132 * <p> 133 * If specified, the input validates successfully if it is equal to one of the elements in this array. 134 * 135 * <p> 136 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 137 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 138 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 139 * 140 * <p> 141 * The format is either individual values or a comma-delimited list. 142 * <br>Multiple lines are concatenated with newlines. 143 * 144 * <h5 class='section'>Examples:</h5> 145 * <p class='bjava'> 146 * <jc>// Comma-delimited list</jc> 147 * <jk>public</jk> Collection<Pet> findPetsByStatus( 148 * <ja>@Header</ja>(<js>"X-Status"</js>) 149 * <ja>@Schema</ja>(_enum=<js>"AVAILABLE,PENDING,SOLD"</js>) 150 * PetStatus <jv>status</jv> 151 * ) {...} 152 * </p> 153 * 154 * <h5 class='section'>Used for:</h5> 155 * <ul class='spaced-list'> 156 * <li> 157 * Server-side schema-based parsing validation. 158 * <li> 159 * Server-side generated Swagger documentation. 160 * <li> 161 * Client-side schema-based serializing validation. 162 * </ul> 163 * 164 * @return The annotation value. 165 */ 166 String[] _enum() default {}; 167 168 /** 169 * <mk>$ref</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 170 * 171 * <p> 172 * A JSON reference to the schema definition. 173 * 174 * <h5 class='section'>Notes:</h5><ul> 175 * <li class='note'> 176 * The format is a <a href='https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03'>JSON Reference</a>. 177 * </ul> 178 * 179 * @return The annotation value. 180 */ 181 String $ref() default ""; 182 183 /** 184 * <mk>additionalProperties</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 185 * 186 * <h5 class='section'>Notes:</h5><ul> 187 * <li class='note'> 188 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 189 * <br>Multiple lines are concatenated with newlines. 190 * </ul> 191 * 192 * @return The annotation value. 193 */ 194 String[] additionalProperties() default {}; 195 196 /** 197 * <mk>allOf</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 198 * 199 * <h5 class='section'>Notes:</h5><ul> 200 * <li class='note'> 201 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 202 * <br>Multiple lines are concatenated with newlines. 203 * </ul> 204 * 205 * @return The annotation value. 206 */ 207 String[] allOf() default {}; 208 209 /** 210 * Synonym for {@link #allowEmptyValue()}. 211 * 212 * @return The annotation value. 213 */ 214 boolean aev() default false; 215 216 /** 217 * <mk>allowEmptyValue</mk> field of the <a class='doclink' href='https://swagger.io/specification/v2#parameterObject'>Swagger Parameter Object</a>. 218 * 219 * <p> 220 * Sets the ability to pass empty-valued heaver values. 221 * 222 * <h5 class='section'>Used for:</h5> 223 * <ul class='spaced-list'> 224 * <li> 225 * Server-side schema-based parsing validation. 226 * <li> 227 * Server-side generated Swagger documentation. 228 * <li> 229 * Client-side schema-based serializing validation. 230 * </ul> 231 * 232 * <p> 233 * <b>Note:</b> This is technically only valid for either query or formData parameters, but support is provided anyway for backwards compatability. 234 * 235 * @return The annotation value. 236 */ 237 boolean allowEmptyValue() default false; 238 239 /** 240 * Synonym for {@link #collectionFormat()}. 241 * 242 * @return The annotation value. 243 */ 244 String cf() default ""; 245 246 /** 247 * <mk>collectionFormat</mk> field. 248 * 249 * <p> 250 * Note that this field isn't part of the Swagger 2.0 specification, but the specification does not specify how 251 * items are supposed to be represented. 252 * 253 * <p> 254 * Determines the format of the array if <c>type</c> <js>"array"</js> is used. 255 * <br>Can only be used if <c>type</c> is <js>"array"</js>. 256 * 257 * <p> 258 * Static strings are defined in {@link CollectionFormatType}. 259 * 260 * <p> 261 * Note that for collections/arrays parameters with POJO element types, the input is broken into a string array before being converted into POJO elements. 262 * 263 * <h5 class='section'>Used for:</h5> 264 * <ul class='spaced-list'> 265 * <li> 266 * Server-side schema-based parsing. 267 * <li> 268 * Server-side generated Swagger documentation. 269 * <li> 270 * Client-side schema-based serializing. 271 * </ul> 272 * 273 * <p> 274 * Note that for collections/arrays parameters with POJO element types, the input is broken into a string array before being converted into POJO elements. 275 * 276 * <ul class='values'> 277 * <li><js>"csv"</js> (default) - Comma-separated values (e.g. <js>"foo,bar"</js>). 278 * <li><js>"ssv"</js> - Space-separated values (e.g. <js>"foo bar"</js>). 279 * <li><js>"tsv"</js> - Tab-separated values (e.g. <js>"foo\tbar"</js>). 280 * <li><js>"pipes</js> - Pipe-separated values (e.g. <js>"foo|bar"</js>). 281 * <li><js>"multi"</js> - Corresponds to multiple parameter instances instead of multiple values for a single instance (e.g. <js>"foo=bar&foo=baz"</js>). 282 * <li><js>"uon"</js> - UON notation (e.g. <js>"@(foo,bar)"</js>). 283 * </ul> 284 * 285 * @return The annotation value. 286 */ 287 String collectionFormat() default ""; 288 289 /** 290 * Synonym for {@link #description()}. 291 * 292 * @return The annotation value. 293 */ 294 String[] d() default {}; 295 296 /** 297 * <mk>description</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 298 * 299 * <p> 300 * A brief description of the body. This could contain examples of use. 301 * 302 * <h5 class='section'>Examples:</h5> 303 * <p class='bjava'> 304 * <jc>// Used on parameter</jc> 305 * <ja>@RestPost</ja> 306 * <jk>public void</jk> addPet( 307 * <ja>@Content</ja> <ja>@Schema</ja>(description=<js>"Pet object to add to the store"</js>) Pet <jv>input</jv> 308 * ) {...} 309 * </p> 310 * <p class='bjava'> 311 * <jc>// Used on class</jc> 312 * <ja>@RestPost</ja> 313 * <jk>public void</jk> addPet(Pet <jv>input</jv>) {...} 314 * 315 * <ja>@Content</ja> <ja>@Schema</ja>(description=<js>"Pet object to add to the store"</js>) 316 * <jk>public class</jk> Pet {...} 317 * </p> 318 * 319 * <h5 class='section'>Notes:</h5><ul> 320 * <li class='note'> 321 * The format is plain text. 322 * <br>Multiple lines are concatenated with newlines. 323 * <li class='note'> 324 * Supports <a class="doclink" href="https://juneau.apache.org/docs/topics/RestServerSvlVariables">SVL Variables</a> (e.g. <js>"$L{my.localized.variable}"</js>) for the swagger generator. 325 * </ul> 326 * 327 * @return The annotation value. 328 */ 329 String[] description() default {}; 330 331 /** 332 * Synonym for {@link #_default()}. 333 * 334 * @return The annotation value. 335 */ 336 String[] df() default {}; 337 338 /** 339 * <mk>discriminator</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 340 * 341 * <h5 class='section'>Notes:</h5><ul> 342 * <li class='note'> 343 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 344 * <br>Multiple lines are concatenated with newlines. 345 * </ul> 346 * 347 * @return The annotation value. 348 */ 349 String discriminator() default ""; 350 351 /** 352 * Synonym for {@link #_enum()}. 353 * 354 * @return The annotation value. 355 */ 356 String[] e() default {}; 357 358 /** 359 * Synonym for {@link #exclusiveMaximum()}. 360 * 361 * @return The annotation value. 362 */ 363 boolean emax() default false; 364 365 /** 366 * Synonym for {@link #exclusiveMinimum()}. 367 * 368 * @return The annotation value. 369 */ 370 boolean emin() default false; 371 372 /** 373 * <mk>exclusiveMaximum</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 374 * 375 * <p> 376 * Defines whether the maximum is matched exclusively. 377 * 378 * <p> 379 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 380 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 381 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 382 * 383 * <p> 384 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 385 * <br>If <jk>true</jk>, must be accompanied with <c>maximum</c>. 386 * 387 * <h5 class='section'>Used for:</h5> 388 * <ul class='spaced-list'> 389 * <li> 390 * Server-side schema-based parsing validation. 391 * <li> 392 * Server-side generated Swagger documentation. 393 * <li> 394 * Client-side schema-based serializing validation. 395 * </ul> 396 * 397 * @return The annotation value. 398 */ 399 boolean exclusiveMaximum() default false; 400 401 /** 402 * <mk>exclusiveMinimum</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 403 * 404 * <p> 405 * Defines whether the minimum is matched exclusively. 406 * 407 * <p> 408 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 409 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 410 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 411 * 412 * <p> 413 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 414 * <br>If <jk>true</jk>, must be accompanied with <c>minimum</c>. 415 * 416 * <h5 class='section'>Used for:</h5> 417 * <ul class='spaced-list'> 418 * <li> 419 * Server-side schema-based parsing validation. 420 * <li> 421 * Server-side generated Swagger documentation. 422 * <li> 423 * Client-side schema-based serializing validation. 424 * </ul> 425 * 426 * @return The annotation value. 427 */ 428 boolean exclusiveMinimum() default false; 429 430 /** 431 * <mk>externalDocs</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 432 * 433 * <h5 class='section'>Notes:</h5><ul> 434 * <li class='note'> 435 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 436 * <br>Multiple lines are concatenated with newlines. 437 * </ul> 438 * 439 * @return The annotation value. 440 */ 441 ExternalDocs externalDocs() default @ExternalDocs; 442 443 /** 444 * Synonym for {@link #format()}. 445 * 446 * @return The annotation value. 447 */ 448 String f() default ""; 449 450 /** 451 * <mk>format</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 452 * 453 * <p> 454 * The extending format for the previously mentioned <a class="doclink" href="https://swagger.io/specification/v2#parameterType">parameter type</a>. 455 * 456 * <p> 457 * Static strings are defined in {@link FormatType}. 458 * 459 * <h5 class='section'>Examples:</h5> 460 * <p class='bjava'> 461 * <jc>// Used on parameter</jc> 462 * <ja>@RestPut</ja> 463 * <jk>public void</jk> setAge( 464 * <ja>@Content</ja> <ja>@Schema</ja>(type=<js>"integer"</js>, format=<js>"int32"</js>) String <jv>input</jv> 465 * ) {...} 466 * </p> 467 * 468 * <h5 class='section'>Used for:</h5> 469 * <ul class='spaced-list'> 470 * <li> 471 * Server-side schema-based parsing. 472 * <li> 473 * Server-side generated Swagger documentation. 474 * <li> 475 * Client-side schema-based serializing. 476 * </ul> 477 * 478 * <ul class='values'> 479 * <li> 480 * <js>"int32"</js> - Signed 32 bits. 481 * <br>Only valid with type <js>"integer"</js>. 482 * <li> 483 * <js>"int64"</js> - Signed 64 bits. 484 * <br>Only valid with type <js>"integer"</js>. 485 * <li> 486 * <js>"float"</js> - 32-bit floating point number. 487 * <br>Only valid with type <js>"number"</js>. 488 * <li> 489 * <js>"double"</js> - 64-bit floating point number. 490 * <br>Only valid with type <js>"number"</js>. 491 * <li> 492 * <js>"byte"</js> - BASE-64 encoded characters. 493 * <br>Only valid with type <js>"string"</js>. 494 * <br>Parameters of type POJO convertible from string are converted after the string has been decoded. 495 * <li> 496 * <js>"binary"</js> - Hexadecimal encoded octets (e.g. <js>"00FF"</js>). 497 * <br>Only valid with type <js>"string"</js>. 498 * <br>Parameters of type POJO convertible from string are converted after the string has been decoded. 499 * <li> 500 * <js>"date"</js> - An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 full-date</a>. 501 * <br>Only valid with type <js>"string"</js>. 502 * <li> 503 * <js>"date-time"</js> - An <a href='http://xml2rfc.ietf.org/public/rfc/html/rfc3339.html#anchor14'>RFC3339 date-time</a>. 504 * <br>Only valid with type <js>"string"</js>. 505 * <li> 506 * <js>"password"</js> - Used to hint UIs the input needs to be obscured. 507 * <br>This format does not affect the serialization or parsing of the parameter. 508 * <li> 509 * <js>"uon"</js> - UON notation (e.g. <js>"(foo=bar,baz=@(qux,123))"</js>). 510 * <br>Only valid with type <js>"object"</js>. 511 * <br>If not specified, then the input is interpreted as plain-text and is converted to a POJO directly. 512 * </ul> 513 * 514 * <h5 class='section'>Notes:</h5><ul> 515 * <li class='note'> 516 * The format is plain text. 517 * </ul> 518 * 519 * <h5 class='section'>See Also:</h5><ul> 520 * <li class='extlink'><a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a> 521 * </ul> 522 * 523 * @return The annotation value. 524 */ 525 String format() default ""; 526 527 /** 528 * Specifies that schema information for this part should not be shown in the generated Swagger documentation. 529 * 530 * @return The annotation value. 531 */ 532 boolean ignore() default false; 533 534 /** 535 * <mk>items</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 536 * 537 * <p> 538 * Describes the type of items in the array. 539 * 540 * <p> 541 * Required if <c>type</c> is <js>"array"</js>. 542 * <br>Can only be used if <c>type</c> is <js>"array"</js>. 543 * 544 * <h5 class='section'>Used for:</h5> 545 * <ul class='spaced-list'> 546 * <li> 547 * Server-side schema-based parsing and parsing validation. 548 * <li> 549 * Server-side generated Swagger documentation. 550 * <li> 551 * Client-side schema-based serializing and serializing validation. 552 * </ul> 553 * 554 * @return The annotation value. 555 */ 556 Items items() default @Items; 557 558 /** 559 * Synonym for {@link #maximum()}. 560 * 561 * @return The annotation value. 562 */ 563 String max() default ""; 564 565 /** 566 * Synonym for {@link #maxItems()}. 567 * 568 * @return The annotation value. 569 */ 570 long maxi() default -1; 571 572 /** 573 * <mk>maximum</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 574 * 575 * <p> 576 * Defines the maximum value for a parameter of numeric types. 577 * <br>The value must be a valid JSON number. 578 * 579 * <p> 580 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 581 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 582 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 583 * 584 * <p> 585 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 586 * 587 * <h5 class='section'>Used for:</h5> 588 * <ul class='spaced-list'> 589 * <li> 590 * Server-side schema-based parsing validation. 591 * <li> 592 * Server-side generated Swagger documentation. 593 * <li> 594 * Client-side schema-based serializing validation. 595 * </ul> 596 * 597 * @return The annotation value. 598 */ 599 String maximum() default ""; 600 601 /** 602 * <mk>maxItems</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 603 * 604 * <p> 605 * An array or collection is valid if its size is less than, or equal to, the value of this keyword. 606 * 607 * <p> 608 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 609 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 610 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 611 * 612 * <p> 613 * Only allowed for the following types: <js>"array"</js>. 614 * 615 * <h5 class='section'>Used for:</h5> 616 * <ul class='spaced-list'> 617 * <li> 618 * Server-side schema-based parsing validation. 619 * <li> 620 * Server-side generated Swagger documentation. 621 * <li> 622 * Client-side schema-based serializing validation. 623 * </ul> 624 * 625 * @return The annotation value. 626 */ 627 long maxItems() default -1; 628 629 /** 630 * Synonym for {@link #maxLength()}. 631 * 632 * @return The annotation value. 633 */ 634 long maxl() default -1; 635 636 /** 637 * <mk>maxLength</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 638 * 639 * <p> 640 * A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword. 641 * <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>. 642 * <br>The value <c>-1</c> is always ignored. 643 * 644 * <p> 645 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 646 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 647 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 648 * 649 * <p> 650 * Only allowed for the following types: <js>"string"</js>. 651 * 652 * <h5 class='section'>Used for:</h5> 653 * <ul class='spaced-list'> 654 * <li> 655 * Server-side schema-based parsing validation. 656 * <li> 657 * Server-side generated Swagger documentation. 658 * <li> 659 * Client-side schema-based serializing validation. 660 * </ul> 661 * 662 * @return The annotation value. 663 */ 664 long maxLength() default -1; 665 666 /** 667 * Synonym for {@link #maxProperties()}. 668 * 669 * @return The annotation value. 670 */ 671 long maxp() default -1; 672 673 /** 674 * <mk>maxProperties</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 675 * 676 * <h5 class='section'>Notes:</h5><ul> 677 * <li class='note'> 678 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 679 * <br>Multiple lines are concatenated with newlines. 680 * </ul> 681 * 682 * @return The annotation value. 683 */ 684 long maxProperties() default -1; 685 686 /** 687 * Synonym for {@link #minimum()}. 688 * 689 * @return The annotation value. 690 */ 691 String min() default ""; 692 693 /** 694 * Synonym for {@link #minItems()}. 695 * 696 * @return The annotation value. 697 */ 698 long mini() default -1; 699 700 /** 701 * <mk>minimum</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 702 * 703 * <p> 704 * Defines the minimum value for a parameter of numeric types. 705 * <br>The value must be a valid JSON number. 706 * 707 * <p> 708 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 709 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 710 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 711 * 712 * <p> 713 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 714 * 715 * <h5 class='section'>Used for:</h5> 716 * <ul class='spaced-list'> 717 * <li> 718 * Server-side schema-based parsing validation. 719 * <li> 720 * Server-side generated Swagger documentation. 721 * <li> 722 * Client-side schema-based serializing validation. 723 * </ul> 724 * 725 * @return The annotation value. 726 */ 727 String minimum() default ""; 728 729 /** 730 * <mk>minItems</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 731 * 732 * <p> 733 * An array or collection is valid if its size is greater than, or equal to, the value of this keyword. 734 * 735 * <p> 736 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 737 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 738 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 739 * 740 * <p> 741 * Only allowed for the following types: <js>"array"</js>. 742 * 743 * <h5 class='section'>Used for:</h5> 744 * <ul class='spaced-list'> 745 * <li> 746 * Server-side schema-based parsing validation. 747 * <li> 748 * Server-side generated Swagger documentation. 749 * <li> 750 * Client-side schema-based serializing validation. 751 * </ul> 752 * 753 * @return The annotation value. 754 */ 755 long minItems() default -1; 756 757 /** 758 * Synonym for {@link #minLength()}. 759 * 760 * @return The annotation value. 761 */ 762 long minl() default -1; 763 764 /** 765 * <mk>minLength</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 766 * 767 * <p> 768 * A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword. 769 * <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>. 770 * <br>The value <c>-1</c> is always ignored. 771 * 772 * <p> 773 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 774 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 775 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 776 * 777 * <p> 778 * Only allowed for the following types: <js>"string"</js>. 779 * 780 * <h5 class='section'>Used for:</h5> 781 * <ul class='spaced-list'> 782 * <li> 783 * Server-side schema-based parsing validation. 784 * <li> 785 * Server-side generated Swagger documentation. 786 * <li> 787 * Client-side schema-based serializing validation. 788 * </ul> 789 * 790 * @return The annotation value. 791 */ 792 long minLength() default -1; 793 794 /** 795 * Synonym for {@link #minProperties()}. 796 * 797 * @return The annotation value. 798 */ 799 long minp() default -1; 800 801 /** 802 * <mk>minProperties</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 803 * 804 * <h5 class='section'>Notes:</h5><ul> 805 * <li class='note'> 806 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 807 * <br>Multiple lines are concatenated with newlines. 808 * </ul> 809 * 810 * @return The annotation value. 811 */ 812 long minProperties() default -1; 813 814 /** 815 * Synonym for {@link #multipleOf()}. 816 * 817 * @return The annotation value. 818 */ 819 String mo() default ""; 820 821 /** 822 * <mk>multipleOf</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 823 * 824 * <p> 825 * A numeric instance is valid if the result of the division of the instance by this keyword's value is an integer. 826 * <br>The value must be a valid JSON number. 827 * 828 * <p> 829 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 830 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 831 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 832 * 833 * <p> 834 * Only allowed for the following types: <js>"integer"</js>, <js>"number"</js>. 835 * 836 * <h5 class='section'>Used for:</h5> 837 * <ul class='spaced-list'> 838 * <li> 839 * Server-side schema-based parsing validation. 840 * <li> 841 * Server-side generated Swagger documentation. 842 * <li> 843 * Client-side schema-based serializing validation. 844 * </ul> 845 * 846 * @return The annotation value. 847 */ 848 String multipleOf() default ""; 849 850 /** 851 * Dynamically apply this annotation to the specified classes/methods/fields. 852 * 853 * <p> 854 * Used in conjunction with {@link org.apache.juneau.BeanContext.Builder#applyAnnotations(Class...)} to dynamically apply an annotation to an existing class/method/field. 855 * It is ignored when the annotation is applied directly to classes/methods/fields. 856 * 857 * <h5 class='section'>Valid patterns:</h5> 858 * <ul class='spaced-list'> 859 * <li>Classes: 860 * <ul> 861 * <li>Fully qualified: 862 * <ul> 863 * <li><js>"com.foo.MyClass"</js> 864 * </ul> 865 * <li>Fully qualified inner class: 866 * <ul> 867 * <li><js>"com.foo.MyClass$Inner1$Inner2"</js> 868 * </ul> 869 * <li>Simple: 870 * <ul> 871 * <li><js>"MyClass"</js> 872 * </ul> 873 * <li>Simple inner: 874 * <ul> 875 * <li><js>"MyClass$Inner1$Inner2"</js> 876 * <li><js>"Inner1$Inner2"</js> 877 * <li><js>"Inner2"</js> 878 * </ul> 879 * </ul> 880 * <li>Methods: 881 * <ul> 882 * <li>Fully qualified with args: 883 * <ul> 884 * <li><js>"com.foo.MyClass.myMethod(String,int)"</js> 885 * <li><js>"com.foo.MyClass.myMethod(java.lang.String,int)"</js> 886 * <li><js>"com.foo.MyClass.myMethod()"</js> 887 * </ul> 888 * <li>Fully qualified: 889 * <ul> 890 * <li><js>"com.foo.MyClass.myMethod"</js> 891 * </ul> 892 * <li>Simple with args: 893 * <ul> 894 * <li><js>"MyClass.myMethod(String,int)"</js> 895 * <li><js>"MyClass.myMethod(java.lang.String,int)"</js> 896 * <li><js>"MyClass.myMethod()"</js> 897 * </ul> 898 * <li>Simple: 899 * <ul> 900 * <li><js>"MyClass.myMethod"</js> 901 * </ul> 902 * <li>Simple inner class: 903 * <ul> 904 * <li><js>"MyClass$Inner1$Inner2.myMethod"</js> 905 * <li><js>"Inner1$Inner2.myMethod"</js> 906 * <li><js>"Inner2.myMethod"</js> 907 * </ul> 908 * </ul> 909 * <li>Fields: 910 * <ul> 911 * <li>Fully qualified: 912 * <ul> 913 * <li><js>"com.foo.MyClass.myField"</js> 914 * </ul> 915 * <li>Simple: 916 * <ul> 917 * <li><js>"MyClass.myField"</js> 918 * </ul> 919 * <li>Simple inner class: 920 * <ul> 921 * <li><js>"MyClass$Inner1$Inner2.myField"</js> 922 * <li><js>"Inner1$Inner2.myField"</js> 923 * <li><js>"Inner2.myField"</js> 924 * </ul> 925 * </ul> 926 * <li>A comma-delimited list of anything on this list. 927 * </ul> 928 * 929 * <h5 class='section'>See Also:</h5><ul> 930 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 931 * </ul> 932 * 933 * @return The annotation value. 934 */ 935 String[] on() default {}; 936 937 /** 938 * Dynamically apply this annotation to the specified classes. 939 * 940 * <p> 941 * Identical to {@link #on()} except allows you to specify class objects instead of a strings. 942 * 943 * <h5 class='section'>See Also:</h5><ul> 944 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/DynamicallyAppliedAnnotations">Dynamically Applied Annotations</a> 945 * </ul> 946 * 947 * @return The annotation value. 948 */ 949 Class<?>[] onClass() default {}; 950 951 /** 952 * Synonym for {@link #pattern()}. 953 * 954 * @return The annotation value. 955 */ 956 String p() default ""; 957 958 /** 959 * <mk>pattern</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 960 * 961 * <p> 962 * A string input is valid if it matches the specified regular expression pattern. 963 * 964 * <p> 965 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 966 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 967 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 968 * 969 * <h5 class='section'>Example:</h5> 970 * <p class='bjava'> 971 * <ja>@RestPut</ja> 972 * <jk>public void</jk> doPut(<ja>@Content</ja> <ja>@Schema</ja>(pattern=<js>"/\\w+\\.\\d+/"</js>) String <jv>input</jv>) {...} 973 * </p> 974 * 975 * <p> 976 * Only allowed for the following types: <js>"string"</js>. 977 * 978 * <h5 class='section'>Used for:</h5> 979 * <ul class='spaced-list'> 980 * <li> 981 * Server-side schema-based parsing validation. 982 * <li> 983 * Server-side generated Swagger documentation. 984 * <li> 985 * Client-side schema-based serializing validation. 986 * </ul> 987 * 988 * @return The annotation value. 989 */ 990 String pattern() default ""; 991 992 /** 993 * <mk>properties</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 994 * 995 * <h5 class='section'>Notes:</h5><ul> 996 * <li class='note'> 997 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 998 * <br>Multiple lines are concatenated with newlines. 999 * </ul> 1000 * 1001 * @return The annotation value. 1002 */ 1003 String[] properties() default {}; 1004 1005 /** 1006 * Synonym for {@link #required()}. 1007 * 1008 * @return The annotation value. 1009 */ 1010 boolean r() default false; 1011 1012 /** 1013 * <mk>readOnly</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 1014 * 1015 * <h5 class='section'>Notes:</h5><ul> 1016 * <li class='note'> 1017 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 1018 * <br>Multiple lines are concatenated with newlines. 1019 * </ul> 1020 * 1021 * @return The annotation value. 1022 */ 1023 boolean readOnly() default false; 1024 1025 /** 1026 * <mk>required</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 1027 * 1028 * <p> 1029 * Determines whether the parameter is mandatory. 1030 * 1031 * <p> 1032 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 1033 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 1034 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 1035 * 1036 * <h5 class='section'>Examples:</h5> 1037 * <p class='bjava'> 1038 * <jc>// Used on parameter</jc> 1039 * <ja>@RestPost</ja> 1040 * <jk>public void</jk> addPet( 1041 * <ja>@Content</ja> <ja>@Schema</ja>(required=<jk>true</jk>) Pet <jv>input</jv> 1042 * ) {...} 1043 * </p> 1044 * <p class='bjava'> 1045 * <jc>// Used on class</jc> 1046 * <ja>@RestPost</ja> 1047 * <jk>public void</jk> addPet(Pet <jv>input</jv>) {...} 1048 * 1049 * <ja>@Content</ja>(required=<jk>true</jk>) 1050 * <jk>public class</jk> Pet {...} 1051 * </p> 1052 * 1053 * <h5 class='section'>Used for:</h5> 1054 * <ul class='spaced-list'> 1055 * <li> 1056 * Server-side schema-based parsing validation. 1057 * <li> 1058 * Server-side generated Swagger documentation. 1059 * <li> 1060 * Client-side schema-based serializing validation. 1061 * </ul> 1062 * 1063 * @return The annotation value. 1064 */ 1065 boolean required() default false; 1066 1067 /** 1068 * Synonym for {@link #readOnly()}. 1069 * 1070 * @return The annotation value. 1071 */ 1072 boolean ro() default false; 1073 1074 /** 1075 * Synonym for {@link #skipIfEmpty()}. 1076 * 1077 * @return The annotation value. 1078 */ 1079 boolean sie() default false; 1080 1081 /** 1082 * Skips this value during serialization if it's an empty string or empty collection/array. 1083 * 1084 * <p> 1085 * Note that <jk>null</jk> values are already ignored. 1086 * 1087 * <h5 class='section'>Used for:</h5> 1088 * <ul class='spaced-list'> 1089 * <li> 1090 * Client-side schema-based serializing. 1091 * </ul> 1092 * 1093 * @return The annotation value. 1094 */ 1095 boolean skipIfEmpty() default false; 1096 1097 /** 1098 * Synonym for {@link #type()}. 1099 * 1100 * @return The annotation value. 1101 */ 1102 String t() default ""; 1103 1104 /** 1105 * <mk>title</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 1106 * 1107 * <h5 class='section'>Notes:</h5><ul> 1108 * <li class='note'> 1109 * The format is plain text. 1110 * </ul> 1111 * 1112 * @return The annotation value. 1113 */ 1114 String title() default ""; 1115 1116 /** 1117 * <mk>type</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 1118 * 1119 * <p> 1120 * The type of the parameter. 1121 * 1122 * <h5 class='section'>Examples:</h5> 1123 * <p class='bjava'> 1124 * <jc>// Used on parameter</jc> 1125 * <ja>@RestPost</ja> 1126 * <jk>public void</jk> addPet( 1127 * <ja>@Content</ja> <ja>@Schema</ja>(type=<js>"object"</js>) Pet <jv>input</jv> 1128 * ) {...} 1129 * </p> 1130 * <p class='bjava'> 1131 * <jc>// Used on class</jc> 1132 * <ja>@RestPost</ja> 1133 * <jk>public void</jk> addPet(Pet <jv>input</jv>) {...} 1134 * 1135 * <ja>@Content</ja> <ja>@Schema</ja>(type=<js>"object"</js>) 1136 * <jk>public class</jk> Pet {...} 1137 * </p> 1138 * 1139 * <h5 class='section'>Used for:</h5> 1140 * <ul class='spaced-list'> 1141 * <li> 1142 * Server-side schema-based parsing. 1143 * <li> 1144 * Server-side generated Swagger documentation. 1145 * <li> 1146 * Client-side schema-based serializing. 1147 * </ul> 1148 * 1149 * <ul class='values spaced-list'> 1150 * <li> 1151 * <js>"string"</js> 1152 * <br>Parameter must be a string or a POJO convertible from a string. 1153 * <li> 1154 * <js>"number"</js> 1155 * <br>Parameter must be a number primitive or number object. 1156 * <br>If parameter is <c>Object</c>, creates either a <c>Float</c> or <c>Double</c> depending on the size of the number. 1157 * <li> 1158 * <js>"integer"</js> 1159 * <br>Parameter must be a integer/long primitive or integer/long object. 1160 * <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. 1161 * <li> 1162 * <js>"boolean"</js> 1163 * <br>Parameter must be a boolean primitive or object. 1164 * <li> 1165 * <js>"array"</js> 1166 * <br>Parameter must be an array or collection. 1167 * <br>Elements must be strings or POJOs convertible from strings. 1168 * <br>If parameter is <c>Object</c>, creates an {@link JsonList}. 1169 * <li> 1170 * <js>"object"</js> 1171 * <br>Parameter must be a map or bean. 1172 * <br>If parameter is <c>Object</c>, creates an {@link JsonMap}. 1173 * <br>Note that this is an extension of the OpenAPI schema as Juneau allows for arbitrarily-complex POJOs to be serialized as HTTP parts. 1174 * <li> 1175 * <js>"file"</js> 1176 * <br>This type is currently not supported. 1177 * </ul> 1178 * 1179 * <h5 class='section'>Notes:</h5><ul> 1180 * <li class='note'>Static strings are defined in {@link ParameterType}. 1181 * </ul> 1182 * 1183 * <h5 class='section'>See Also:</h5><ul> 1184 * <li class='extlink'><a class="doclink" href="https://swagger.io/specification#dataTypes">Swagger Data Types</a> 1185 * </ul> 1186 * 1187 * @return The annotation value. 1188 */ 1189 String type() default ""; 1190 1191 /** 1192 * Synonym for {@link #uniqueItems()}. 1193 * 1194 * @return The annotation value. 1195 */ 1196 boolean ui() default false; 1197 1198 /** 1199 * <mk>uniqueItems</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 1200 * 1201 * <p> 1202 * If <jk>true</jk> the input validates successfully if all of its elements are unique. 1203 * 1204 * <p> 1205 * If validation fails during serialization or parsing, the part serializer/parser will throw a {@link SchemaValidationException}. 1206 * <br>On the client-side, this gets converted to a <c>RestCallException</c> which is thrown before the connection is made. 1207 * <br>On the server-side, this gets converted to a <c>BadRequest</c> (400). 1208 * 1209 * <p> 1210 * If the parameter type is a subclass of {@link Set}, this validation is skipped (since a set can only contain unique items anyway). 1211 * <br>Otherwise, the collection or array is checked for duplicate items. 1212 * 1213 * <p> 1214 * Only allowed for the following types: <js>"array"</js>. 1215 * 1216 * <h5 class='section'>Used for:</h5> 1217 * <ul class='spaced-list'> 1218 * <li> 1219 * Server-side schema-based parsing validation. 1220 * <li> 1221 * Server-side generated Swagger documentation. 1222 * <li> 1223 * Client-side schema-based serializing validation. 1224 * </ul> 1225 * 1226 * @return The annotation value. 1227 */ 1228 boolean uniqueItems() default false; 1229 1230 /** 1231 * <mk>xml</mk> field of the <a class="doclink" href="https://swagger.io/specification/v2#schemaObject">Swagger Schema Object</a>. 1232 * 1233 * <h5 class='section'>Notes:</h5><ul> 1234 * <li class='note'> 1235 * The format is a <a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauBeanSwagger2">juneau-bean-swagger-v2</a> object. 1236 * <br>Multiple lines are concatenated with newlines. 1237 * </ul> 1238 * 1239 * @return The annotation value. 1240 */ 1241 String[] xml() default {}; 1242}