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.jsonschema.annotation; 014 015import static java.lang.annotation.ElementType.*; 016import static java.lang.annotation.RetentionPolicy.*; 017 018import java.lang.annotation.*; 019 020import org.apache.juneau.*; 021import org.apache.juneau.annotation.*; 022import org.apache.juneau.jsonschema.*; 023 024/** 025 * Annotation for specifying config properties defined in {@link JsonSchemaGenerator}. 026 * 027 * <p> 028 * Used primarily for specifying bean configuration properties on REST classes and methods. 029 */ 030@Documented 031@Target({TYPE,METHOD}) 032@Retention(RUNTIME) 033@Inherited 034@PropertyStoreApply(JsonSchemaConfigApply.class) 035public @interface JsonSchemaConfig { 036 037 /** 038 * Optional rank for this config. 039 * 040 * <p> 041 * Can be used to override default ordering and application of config annotations. 042 */ 043 int rank() default 0; 044 045 //------------------------------------------------------------------------------------------------------------------- 046 // JsonSchemaGenerator 047 //------------------------------------------------------------------------------------------------------------------- 048 049 /** 050 * Configuration property: Add descriptions to types. 051 * 052 * <p> 053 * Identifies which categories of types that descriptions should be automatically added to generated schemas. 054 * 055 * <p> 056 * The description is the result of calling {@link ClassMeta#getFullName()}. 057 * 058 * <ul class='notes'> 059 * <li> 060 * The format is a comma-delimited list of any of the following values: 061 * <ul class='doctree'> 062 * <li><js>"BEAN"</js> 063 * <li><js>"COLLECTION"</js> 064 * <li><js>"ARRAY"</js> 065 * <li><js>"MAP"</js> 066 * <li><js>"STRING"</js> 067 * <li><js>"NUMBER"</js> 068 * <li><js>"BOOLEAN"</js> 069 * <li><js>"ANY"</js> 070 * <li><js>"OTHER"</js> 071 * </ul> 072 * <li> 073 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 074 * </ul> 075 * 076 * <ul class='seealso'> 077 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_addDescriptionsTo} 078 * </ul> 079 */ 080 String addDescriptionsTo() default ""; 081 082 /** 083 * Configuration property: Add examples. 084 * 085 * <p> 086 * Identifies which categories of types that examples should be automatically added to generated schemas. 087 * <p> 088 * The examples come from calling {@link ClassMeta#getExample(BeanSession)} which in turn gets examples 089 * from the following: 090 * <ul class='javatree'> 091 * <li class='ja'>{@link Example} 092 * <li class='jf'>{@link BeanContext#BEAN_examples} 093 * </ul> 094 * 095 * <ul class='notes'> 096 * <li> 097 * The format is a comma-delimited list of any of the following values: 098 * <ul class='doctree'> 099 * <li><js>"BEAN"</js> 100 * <li><js>"COLLECTION"</js> 101 * <li><js>"ARRAY"</js> 102 * <li><js>"MAP"</js> 103 * <li><js>"STRING"</js> 104 * <li><js>"NUMBER"</js> 105 * <li><js>"BOOLEAN"</js> 106 * <li><js>"ANY"</js> 107 * <li><js>"OTHER"</js> 108 * </ul> 109 * <li> 110 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 111 * </ul> 112 * 113 * <ul class='seealso'> 114 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_addDescriptionsTo} 115 * </ul> 116 */ 117 String addExamplesTo() default ""; 118 119 /** 120 * Configuration property: Allow nested descriptions. 121 * 122 * <p> 123 * Identifies whether nested descriptions are allowed in schema definitions. 124 * 125 * <ul class='notes'> 126 * <li> 127 * Possible values: 128 * <ul> 129 * <li><js>"true"</js> 130 * <li><js>"false"</js> (default) 131 * </ul> 132 * <li> 133 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 134 * </ul> 135 * 136 * <ul class='seealso'> 137 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_allowNestedDescriptions} 138 * </ul> 139 */ 140 String allowNestedDescriptions() default ""; 141 142 /** 143 * Configuration property: Allow nested examples. 144 * 145 * <p> 146 * Identifies whether nested examples are allowed in schema definitions. 147 * 148 * <ul class='notes'> 149 * <li> 150 * Possible values: 151 * <ul> 152 * <li><js>"true"</js> 153 * <li><js>"false"</js> (default) 154 * </ul> 155 * <li> 156 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 157 * </ul> 158 * 159 * <ul class='seealso'> 160 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_allowNestedExamples} 161 * </ul> 162 */ 163 String allowNestedExamples() default ""; 164 165 /** 166 * Dynamically applies {@link Schema @Schema} annotations to specified classes/methods/fields. 167 * 168 * <p> 169 * Provides an alternate approach for applying annotations using {@link Schema#on() @Schema.on} to specify the names 170 * to apply the annotation to. 171 * 172 * <ul class='seealso'> 173 * <li class='link'>{@doc juneau-marshall.DynamicallyAppliedAnnotations} 174 * </ul> 175 */ 176 Schema[] applySchema() default {}; 177 178 /** 179 * Configuration property: Bean schema definition mapper. 180 * 181 * <p> 182 * Interface to use for converting Bean classes to definition IDs and URIs. 183 * 184 * <p> 185 * Used primarily for defining common definition sections for beans in Swagger JSON. 186 * 187 * <ul class='notes'> 188 * <li> 189 * This setting is ignored if {@link JsonSchemaGenerator#JSONSCHEMA_useBeanDefs} is not enabled. 190 * </ul> 191 * 192 * <ul class='seealso'> 193 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_beanDefMapper} 194 * </ul> 195 */ 196 Class<? extends BeanDefMapper> beanDefMapper() default BeanDefMapper.Null.class; 197 198 /** 199 * Configuration property: Default schemas. 200 * 201 * <p> 202 * Allows you to override or provide custom schema information for particular class types. 203 * 204 * <ul class='notes'> 205 * <li> 206 * Keys are the class. 207 * <br>Values are Simple-JSON objects. 208 * <li> 209 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 210 * </ul> 211 * 212 * <ul class='seealso'> 213 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_defaultSchemas} 214 * </ul> 215 */ 216 CS[] defaultSchemas() default {}; 217 218 /** 219 * Configuration property: Ignore types from schema definitions. 220 * 221 * <p> 222 * Defines class name patterns that should be ignored when generating schema definitions in the generated 223 * Swagger documentation. 224 * 225 * <ul class='notes'> 226 * <li> 227 * Format: Comma-delimited list of patterns 228 * <li> 229 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 230 * </ul> 231 * 232 * <ul class='seealso'> 233 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_ignoreTypes} 234 * </ul> 235 */ 236 String ignoreTypes() default ""; 237 238 /** 239 * Configuration property: Use bean definitions. 240 * 241 * <p> 242 * When enabled, schemas on beans will be serialized as the following: 243 * <p class='bcode w800'> 244 * { 245 * type: <js>'object'</js>, 246 * <js>'$ref'</js>: <js>'#/definitions/TypeId'</js> 247 * } 248 * </p> 249 * 250 * <p> 251 * The definitions can then be retrieved from the session using {@link JsonSchemaGeneratorSession#getBeanDefs()}. 252 * 253 * <p> 254 * Definitions can also be added programmatically using {@link JsonSchemaGeneratorSession#addBeanDef(String, ObjectMap)}. 255 * 256 * <ul class='notes'> 257 * <li> 258 * Possible values: 259 * <ul> 260 * <li><js>"true"</js> 261 * <li><js>"false"</js> (default) 262 * </ul> 263 * <li> 264 * Supports {@doc DefaultSvlVariables} (e.g. <js>"$C{myConfigVar}"</js>). 265 * </ul> 266 * 267 * <ul class='seealso'> 268 * <li class='jf'>{@link JsonSchemaGenerator#JSONSCHEMA_useBeanDefs} 269 * </ul> 270 */ 271 String useBeanDefs() default ""; 272}