// *************************************************************************************************************************** | |
// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * | |
// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * | |
// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * | |
// * with the License. You may obtain a copy of the License at * | |
// * * | |
// * http://www.apache.org/licenses/LICENSE-2.0 * | |
// * * | |
// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * | |
// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * | |
// * specific language governing permissions and limitations under the License. * | |
// *************************************************************************************************************************** | |
package org.apache.juneau.jsonschema.annotation; | |
import static java.lang.annotation.RetentionPolicy.*; | |
import java.lang.annotation.*; | |
import org.apache.juneau.oapi.*; | |
/** | |
* Swagger items annotation. | |
* | |
* <p> | |
* A limited subset of JSON-Schema's items object. | |
* | |
* <p> | |
* Used to populate the auto-generated Swagger documentation and UI for server-side <ja>@Rest</ja>-annotated classes. | |
* <br>Also used to define OpenAPI schema information for POJOs serialized through {@link OpenApiSerializer} and parsed through {@link OpenApiParser}. | |
* | |
* <h5 class='section'>Examples:</h5> | |
* <p class='bcode w800'> | |
* <jc>// Items have a specific set of enumerated string values</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* type=<js>"array"</js>, | |
* collectionFormat=<js>"csv"</js>, | |
* items=<ja>@Items</ja>( | |
* type=<js>"string"</js>, | |
* _enum=<js>"AVAILABLE,PENDING,SOLD"</js>, | |
* _default=<js>"AVAILABLE"</js> | |
* ) | |
* ) | |
* </p> | |
* <p class='bcode w800'> | |
* <jc>// Same but defined free-form</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* type=<js>"array"</js>, | |
* collectionFormat=<js>"csv"</js>, | |
* items=<ja>@Items</ja>({ | |
* <js>"type:'string',"</js>, | |
* <js>"enum:'AVAILABLE,PENDING,SOLD',"</js>, | |
* <js>"default:'AVAILABLE'"</js> | |
* }) | |
* ) | |
* </p> | |
* <p class='bcode w800'> | |
* <jc>// An array of arrays, the internal array being of type integer, numbers must be between 0 and 63 (inclusive)</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* type=<js>"array"</js>, | |
* collectionFormat=<js>"csv"</js>, | |
* items=<ja>@Items</ja>( | |
* type=<js>"array"</js>, | |
* items=<ja>@SubItems</ja>( | |
* type=<js>"integer"</js>, | |
* minimum=<js>"0"</js>, | |
* maximum=<js>"63"</js> | |
* ) | |
* ) | |
* ) | |
* </p> | |
* | |
* <ul class='seealso'> | |
* <li class='link'>{@doc juneau-rest-server.Swagger} | |
* <li class='extlink'>{@doc SwaggerItemsObject} | |
* </ul> | |
*/ | |
@Documented | |
@Retention(RUNTIME) | |
public @interface Items { | |
/** | |
* <mk>type</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String type() default ""; | |
/** | |
* <mk>format</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String format() default ""; | |
/** | |
* <mk>collectionFormat</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String collectionFormat() default ""; | |
/** | |
* <mk>pattern</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String pattern() default ""; | |
/** | |
* <mk>maximum</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String maximum() default ""; | |
/** | |
* <mk>minimum</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String minimum() default ""; | |
/** | |
* <mk>multipleOf</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String multipleOf() default ""; | |
/** | |
* <mk>maxLength</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
long maxLength() default -1; | |
/** | |
* <mk>minLength</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
long minLength() default -1; | |
/** | |
* <mk>maxItems</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
long maxItems() default -1; | |
/** | |
* <mk>minItems</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
long minItems() default -1; | |
/** | |
* <mk>exclusiveMaximum</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
boolean exclusiveMaximum() default false; | |
/** | |
* <mk>exclusiveMinimum</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
boolean exclusiveMinimum() default false; | |
/** | |
* <mk>uniqueItems</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
boolean uniqueItems() default false; | |
/** | |
* <mk>default</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String[] _default() default {}; | |
/** | |
* <mk>enum</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String[] _enum() default {}; | |
/** | |
* <mk>$ref</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <ul class='notes'> | |
* <li> | |
* The format is a plain-text string. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* </ul> | |
*/ | |
String $ref() default ""; | |
/** | |
* <mk>items</mk> field of the {@doc SwaggerItemsObject}. | |
* | |
* <p> | |
* Describes the type of items in the array. | |
*/ | |
SubItems items() default @SubItems; | |
/** | |
* Free-form value for the {@doc SwaggerItemsObject}. | |
* | |
* <p> | |
* This is a {@doc SimpleJson} object that makes up the swagger information for this field. | |
* | |
* <p> | |
* The following are completely equivalent ways of defining the swagger description of an Items object: | |
* <p class='bcode w800'> | |
* <jc>// Normal</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* type=<js>"array"</js>, | |
* items=<ja>@Items</ja>( | |
* type=<js>"string"</js>, | |
* _enum=<js>"AVAILABLE,PENDING,SOLD"</js>, | |
* _default=<js>"AVAILABLE"</js> | |
* ) | |
* ) | |
* </p> | |
* <p class='bcode w800'> | |
* <jc>// Free-form</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* type=<js>"array"</js>, | |
* items=<ja>@Items</ja>({ | |
* <js>"type: 'string'"</js>, | |
* <js>"enum: ['AVAILABLE','PENDING','SOLD'],"</js>, | |
* <js>"default: 'AVAILABLE'"</js> | |
* }) | |
* ) | |
* </p> | |
* <p class='bcode w800'> | |
* <jc>// Free-form as part of parent</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* api={ | |
* <js>"type:'array',"</js>, | |
* <js>"items: {"</js>, | |
* <js>"type: 'string',"</js>, | |
* <js>"enum: ['AVAILABLE','PENDING','SOLD'],"</js>, | |
* <js>"default: 'AVAILABLE'"</js>, | |
* <js>"}"</js>) | |
* } | |
* ) | |
* </p> | |
* <p class='bcode w800'> | |
* <jc>// Free-form with variables</jc> | |
* <ja>@Query</ja>( | |
* name=<js>"status"</js>, | |
* type=<js>"array"</js>, | |
* items=<ja>@Items</ja>(<js>"$L{statusItemsSwagger}"</js>) | |
* ) | |
* </p> | |
* <p class='bcode w800'> | |
* <mc>// Contents of MyResource.properties</mc> | |
* <mk>statusItemsSwagger</mk> = <mv>{ type: "string", enum: ["AVAILABLE","PENDING","SOLD"], default: "AVAILABLE" }</mv> | |
* </p> | |
* | |
* <p> | |
* The reasons why you may want to use this field include: | |
* <ul> | |
* <li>You want to pull in the entire Swagger JSON definition for this field from an external source such as a properties file. | |
* <li>You want to add extra fields to the Swagger documentation that are not officially part of the Swagger specification. | |
* </ul> | |
* | |
* <ul class='notes'> | |
* <li> | |
* 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. | |
* <li> | |
* The format is a {@doc SimpleJson} object. | |
* <li> | |
* The leading/trailing <c>{ }</c> characters are optional. | |
* <br>The following two example are considered equivalent: | |
* <p class='bcode w800'> | |
* <ja>@Items</ja>(api=<js>"{type: 'string'}"</js>) | |
* </p> | |
* <p class='bcode w800'> | |
* <ja>@Items</ja>(api=<js>"type: 'string'"</js>) | |
* </p> | |
* <li> | |
* Multiple lines are concatenated with newlines so that you can format the value to be readable. | |
* <li> | |
* Supports {@doc DefaultRestSvlVariables} | |
* (e.g. <js>"$L{my.localized.variable}"</js>). | |
* <li> | |
* Values defined in this field supersede values pulled from the Swagger JSON file and are superseded by individual values defined on this annotation. | |
* </ul> | |
*/ | |
String[] value() default {}; | |
} |