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.RetentionPolicy.*; 016 017import java.lang.annotation.*; 018 019import org.apache.juneau.oapi.*; 020 021/** 022 * Swagger items annotation. 023 * 024 * <p> 025 * A limited subset of JSON-Schema's items object. 026 * 027 * <p> 028 * Used to populate the auto-generated Swagger documentation and UI for server-side <ja>@RestResource</ja>-annotated classes. 029 * <br>Also used to define OpenAPI schema information for POJOs serialized through {@link OpenApiSerializer} and parsed through {@link OpenApiParser}. 030 * 031 * <h5 class='section'>Examples:</h5> 032 * <p class='bcode w800'> 033 * <jc>// Items have a specific set of enumerated string values</jc> 034 * <ja>@Query</ja>( 035 * name=<js>"status"</js>, 036 * type=<js>"array"</js>, 037 * collectionFormat=<js>"csv"</js>, 038 * items=<ja>@Items</ja>( 039 * type=<js>"string"</js>, 040 * _enum=<js>"AVAILABLE,PENDING,SOLD"</js>, 041 * _default=<js>"AVAILABLE"</js> 042 * ) 043 * ) 044 * </p> 045 * <p class='bcode w800'> 046 * <jc>// Same but defined free-form</jc> 047 * <ja>@Query</ja>( 048 * name=<js>"status"</js>, 049 * type=<js>"array"</js>, 050 * collectionFormat=<js>"csv"</js>, 051 * items=<ja>@Items</ja>({ 052 * <js>"type:'string',"</js>, 053 * <js>"enum:'AVAILABLE,PENDING,SOLD',"</js>, 054 * <js>"default:'AVAILABLE'"</js> 055 * }) 056 * ) 057 * </p> 058 * <p class='bcode w800'> 059 * <jc>// An array of arrays, the internal array being of type integer, numbers must be between 0 and 63 (inclusive)</jc> 060 * <ja>@Query</ja>( 061 * name=<js>"status"</js>, 062 * type=<js>"array"</js>, 063 * collectionFormat=<js>"csv"</js>, 064 * items=<ja>@Items</ja>( 065 * type=<js>"array"</js>, 066 * items=<ja>@SubItems</ja>( 067 * type=<js>"integer"</js>, 068 * minimum=<js>"0"</js>, 069 * maximum=<js>"63"</js> 070 * ) 071 * ) 072 * ) 073 * </p> 074 * 075 * <h5 class='section'>See Also:</h5> 076 * <ul> 077 * <li class='link'>{@doc juneau-rest-server.Swagger} 078 * <li class='extlink'>{@doc SwaggerItemsObject} 079 * </ul> 080 */ 081@Documented 082@Retention(RUNTIME) 083public @interface Items { 084 085 /** 086 * <mk>type</mk> field of the {@doc SwaggerItemsObject}. 087 * 088 * <h5 class='section'>Notes:</h5> 089 * <ul class='spaced-list'> 090 * <li> 091 * The format is a plain-text string. 092 * <li> 093 * Supports {@doc DefaultRestSvlVariables} 094 * (e.g. <js>"$L{my.localized.variable}"</js>). 095 * </ul> 096 */ 097 String type() default ""; 098 099 /** 100 * <mk>format</mk> field of the {@doc SwaggerItemsObject}. 101 * 102 * <h5 class='section'>Notes:</h5> 103 * <ul class='spaced-list'> 104 * <li> 105 * The format is a plain-text string. 106 * <li> 107 * Supports {@doc DefaultRestSvlVariables} 108 * (e.g. <js>"$L{my.localized.variable}"</js>). 109 * </ul> 110 */ 111 String format() default ""; 112 113 /** 114 * <mk>collectionFormat</mk> field of the {@doc SwaggerItemsObject}. 115 * 116 * <h5 class='section'>Notes:</h5> 117 * <ul class='spaced-list'> 118 * <li> 119 * The format is a plain-text string. 120 * <li> 121 * Supports {@doc DefaultRestSvlVariables} 122 * (e.g. <js>"$L{my.localized.variable}"</js>). 123 * </ul> 124 */ 125 String collectionFormat() default ""; 126 127 /** 128 * <mk>pattern</mk> field of the {@doc SwaggerItemsObject}. 129 * 130 * <h5 class='section'>Notes:</h5> 131 * <ul class='spaced-list'> 132 * <li> 133 * The format is a plain-text string. 134 * <li> 135 * Supports {@doc DefaultRestSvlVariables} 136 * (e.g. <js>"$L{my.localized.variable}"</js>). 137 * </ul> 138 */ 139 String pattern() default ""; 140 141 /** 142 * <mk>maximum</mk> field of the {@doc SwaggerItemsObject}. 143 * 144 * <h5 class='section'>Notes:</h5> 145 * <ul class='spaced-list'> 146 * <li> 147 * The format is a plain-text string. 148 * <li> 149 * Supports {@doc DefaultRestSvlVariables} 150 * (e.g. <js>"$L{my.localized.variable}"</js>). 151 * </ul> 152 */ 153 String maximum() default ""; 154 155 /** 156 * <mk>minimum</mk> field of the {@doc SwaggerItemsObject}. 157 * 158 * <h5 class='section'>Notes:</h5> 159 * <ul class='spaced-list'> 160 * <li> 161 * The format is a plain-text string. 162 * <li> 163 * Supports {@doc DefaultRestSvlVariables} 164 * (e.g. <js>"$L{my.localized.variable}"</js>). 165 * </ul> 166 */ 167 String minimum() default ""; 168 169 /** 170 * <mk>multipleOf</mk> field of the {@doc SwaggerItemsObject}. 171 * 172 * <h5 class='section'>Notes:</h5> 173 * <ul class='spaced-list'> 174 * <li> 175 * The format is a plain-text string. 176 * <li> 177 * Supports {@doc DefaultRestSvlVariables} 178 * (e.g. <js>"$L{my.localized.variable}"</js>). 179 * </ul> 180 */ 181 String multipleOf() default ""; 182 183 /** 184 * <mk>maxLength</mk> field of the {@doc SwaggerItemsObject}. 185 * 186 * <h5 class='section'>Notes:</h5> 187 * <ul class='spaced-list'> 188 * <li> 189 * The format is a plain-text string. 190 * <li> 191 * Supports {@doc DefaultRestSvlVariables} 192 * (e.g. <js>"$L{my.localized.variable}"</js>). 193 * </ul> 194 */ 195 long maxLength() default -1; 196 197 /** 198 * <mk>minLength</mk> field of the {@doc SwaggerItemsObject}. 199 * 200 * <h5 class='section'>Notes:</h5> 201 * <ul class='spaced-list'> 202 * <li> 203 * The format is a plain-text string. 204 * <li> 205 * Supports {@doc DefaultRestSvlVariables} 206 * (e.g. <js>"$L{my.localized.variable}"</js>). 207 * </ul> 208 */ 209 long minLength() default -1; 210 211 /** 212 * <mk>maxItems</mk> field of the {@doc SwaggerItemsObject}. 213 * 214 * <h5 class='section'>Notes:</h5> 215 * <ul class='spaced-list'> 216 * <li> 217 * The format is a plain-text string. 218 * <li> 219 * Supports {@doc DefaultRestSvlVariables} 220 * (e.g. <js>"$L{my.localized.variable}"</js>). 221 * </ul> 222 */ 223 long maxItems() default -1; 224 225 /** 226 * <mk>minItems</mk> field of the {@doc SwaggerItemsObject}. 227 * 228 * <h5 class='section'>Notes:</h5> 229 * <ul class='spaced-list'> 230 * <li> 231 * The format is a plain-text string. 232 * <li> 233 * Supports {@doc DefaultRestSvlVariables} 234 * (e.g. <js>"$L{my.localized.variable}"</js>). 235 * </ul> 236 */ 237 long minItems() default -1; 238 239 /** 240 * <mk>exclusiveMaximum</mk> field of the {@doc SwaggerItemsObject}. 241 * 242 * <h5 class='section'>Notes:</h5> 243 * <ul class='spaced-list'> 244 * <li> 245 * The format is a plain-text string. 246 * <li> 247 * Supports {@doc DefaultRestSvlVariables} 248 * (e.g. <js>"$L{my.localized.variable}"</js>). 249 * </ul> 250 */ 251 boolean exclusiveMaximum() default false; 252 253 /** 254 * <mk>exclusiveMinimum</mk> field of the {@doc SwaggerItemsObject}. 255 * 256 * <h5 class='section'>Notes:</h5> 257 * <ul class='spaced-list'> 258 * <li> 259 * The format is a plain-text string. 260 * <li> 261 * Supports {@doc DefaultRestSvlVariables} 262 * (e.g. <js>"$L{my.localized.variable}"</js>). 263 * </ul> 264 */ 265 boolean exclusiveMinimum() default false; 266 267 /** 268 * <mk>uniqueItems</mk> field of the {@doc SwaggerItemsObject}. 269 * 270 * <h5 class='section'>Notes:</h5> 271 * <ul class='spaced-list'> 272 * <li> 273 * The format is a plain-text string. 274 * <li> 275 * Supports {@doc DefaultRestSvlVariables} 276 * (e.g. <js>"$L{my.localized.variable}"</js>). 277 * </ul> 278 */ 279 boolean uniqueItems() default false; 280 281 /** 282 * <mk>default</mk> field of the {@doc SwaggerItemsObject}. 283 * 284 * <h5 class='section'>Notes:</h5> 285 * <ul class='spaced-list'> 286 * <li> 287 * The format is a plain-text string. 288 * <li> 289 * Supports {@doc DefaultRestSvlVariables} 290 * (e.g. <js>"$L{my.localized.variable}"</js>). 291 * </ul> 292 */ 293 String[] _default() default {}; 294 295 /** 296 * <mk>enum</mk> field of the {@doc SwaggerItemsObject}. 297 * 298 * <h5 class='section'>Notes:</h5> 299 * <ul class='spaced-list'> 300 * <li> 301 * The format is a plain-text string. 302 * <li> 303 * Supports {@doc DefaultRestSvlVariables} 304 * (e.g. <js>"$L{my.localized.variable}"</js>). 305 * </ul> 306 */ 307 String[] _enum() default {}; 308 309 /** 310 * <mk>$ref</mk> field of the {@doc SwaggerItemsObject}. 311 * 312 * <h5 class='section'>Notes:</h5> 313 * <ul class='spaced-list'> 314 * <li> 315 * The format is a plain-text string. 316 * <li> 317 * Supports {@doc DefaultRestSvlVariables} 318 * (e.g. <js>"$L{my.localized.variable}"</js>). 319 * </ul> 320 */ 321 String $ref() default ""; 322 323 /** 324 * <mk>items</mk> field of the {@doc SwaggerItemsObject}. 325 * 326 * <p> 327 * Describes the type of items in the array. 328 */ 329 SubItems items() default @SubItems; 330 331 /** 332 * Free-form value for the {@doc SwaggerItemsObject}. 333 * 334 * <p> 335 * This is a {@doc juneau-marshall.JsonDetails.SimplifiedJson} object that makes up the swagger information for this field. 336 * 337 * <p> 338 * The following are completely equivalent ways of defining the swagger description of an Items object: 339 * <p class='bcode w800'> 340 * <jc>// Normal</jc> 341 * <ja>@Query</ja>( 342 * name=<js>"status"</js>, 343 * type=<js>"array"</js>, 344 * items=<ja>@Items</ja>( 345 * type=<js>"string"</js>, 346 * _enum=<js>"AVAILABLE,PENDING,SOLD"</js>, 347 * _default=<js>"AVAILABLE"</js> 348 * ) 349 * ) 350 * </p> 351 * <p class='bcode w800'> 352 * <jc>// Free-form</jc> 353 * <ja>@Query</ja>( 354 * name=<js>"status"</js>, 355 * type=<js>"array"</js>, 356 * items=<ja>@Items</ja>({ 357 * <js>"type: 'string'"</js>, 358 * <js>"enum: ['AVAILABLE','PENDING','SOLD'],"</js>, 359 * <js>"default: 'AVAILABLE'"</js> 360 * }) 361 * ) 362 * </p> 363 * <p class='bcode w800'> 364 * <jc>// Free-form as part of parent</jc> 365 * <ja>@Query</ja>( 366 * name=<js>"status"</js>, 367 * api={ 368 * <js>"type:'array',"</js>, 369 * <js>"items: {"</js>, 370 * <js>"type: 'string',"</js>, 371 * <js>"enum: ['AVAILABLE','PENDING','SOLD'],"</js>, 372 * <js>"default: 'AVAILABLE'"</js>, 373 * <js>"}"</js>) 374 * } 375 * ) 376 * </p> 377 * <p class='bcode w800'> 378 * <jc>// Free-form with variables</jc> 379 * <ja>@Query</ja>( 380 * name=<js>"status"</js>, 381 * type=<js>"array"</js>, 382 * items=<ja>@Items</ja>(<js>"$L{statusItemsSwagger}"</js>) 383 * ) 384 * </p> 385 * <p class='bcode w800'> 386 * <mc>// Contents of MyResource.properties</mc> 387 * <mk>statusItemsSwagger</mk> = <mv>{ type: "string", enum: ["AVAILABLE","PENDING","SOLD"], default: "AVAILABLE" }</mv> 388 * </p> 389 * 390 * <p> 391 * The reasons why you may want to use this field include: 392 * <ul> 393 * <li>You want to pull in the entire Swagger JSON definition for this field from an external source such as a properties file. 394 * <li>You want to add extra fields to the Swagger documentation that are not officially part of the Swagger specification. 395 * </ul> 396 * 397 * <h5 class='section'>Notes:</h5> 398 * <ul class='spaced-list'> 399 * <li> 400 * 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. 401 * <li> 402 * The format is a {@doc juneau-marshall.JsonDetails.SimplifiedJson} object. 403 * <li> 404 * The leading/trailing <code>{ }</code> characters are optional. 405 * <br>The following two example are considered equivalent: 406 * <p class='bcode w800'> 407 * <ja>@Items</ja>(api=<js>"{type: 'string'}"</js>) 408 * </p> 409 * <p class='bcode w800'> 410 * <ja>@Items</ja>(api=<js>"type: 'string'"</js>) 411 * </p> 412 * <li> 413 * Multiple lines are concatenated with newlines so that you can format the value to be readable. 414 * <li> 415 * Supports {@doc DefaultRestSvlVariables} 416 * (e.g. <js>"$L{my.localized.variable}"</js>). 417 * <li> 418 * Values defined in this field supersede values pulled from the Swagger JSON file and are superseded by individual values defined on this annotation. 419 * </ul> 420 */ 421 String[] value() default {}; 422}