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.collections.*; 023import org.apache.juneau.json.*; 024import org.apache.juneau.jsonschema.*; 025import org.apache.juneau.parser.*; 026 027/** 028 * Annotation for specifying config properties defined in {@link JsonSchemaGenerator}. 029 * 030 * <p> 031 * Used primarily for specifying bean configuration properties on REST classes and methods. 032 * 033 * <h5 class='section'>See Also:</h5><ul> 034 * <li class='link'><a class="doclink" href="../../../../../index.html#jm.JsonSchemaDetails">JSON-Schema Support</a> 035 * </ul> 036 */ 037@Target({TYPE,METHOD}) 038@Retention(RUNTIME) 039@Inherited 040@ContextApply(JsonSchemaConfigAnnotation.Apply.class) 041public @interface JsonSchemaConfig { 042 043 /** 044 * Optional rank for this config. 045 * 046 * <p> 047 * Can be used to override default ordering and application of config annotations. 048 * 049 * @return The annotation value. 050 */ 051 int rank() default 0; 052 053 //------------------------------------------------------------------------------------------------------------------- 054 // JsonSchemaGenerator 055 //------------------------------------------------------------------------------------------------------------------- 056 057 /** 058 * Add descriptions to types. 059 * 060 * <p> 061 * Identifies which categories of types that descriptions should be automatically added to generated schemas. 062 * 063 * <p> 064 * The description is the result of calling {@link ClassMeta#getFullName()}. 065 * 066 * <h5 class='section'>Notes:</h5><ul> 067 * <li class='note'> 068 * The format is a comma-delimited list of any of the following values: 069 * <ul class='doctree'> 070 * <li><js>"BEAN"</js> 071 * <li><js>"COLLECTION"</js> 072 * <li><js>"ARRAY"</js> 073 * <li><js>"MAP"</js> 074 * <li><js>"STRING"</js> 075 * <li><js>"NUMBER"</js> 076 * <li><js>"BOOLEAN"</js> 077 * <li><js>"ANY"</js> 078 * <li><js>"OTHER"</js> 079 * </ul> 080 * <li class='note'> 081 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 082 * </ul> 083 * 084 * <h5 class='section'>See Also:</h5><ul> 085 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#addDescriptionsTo(TypeCategory...)} 086 * </ul> 087 * 088 * @return The annotation value. 089 */ 090 String addDescriptionsTo() default ""; 091 092 /** 093 * Add examples. 094 * 095 * <p> 096 * Identifies which categories of types that examples should be automatically added to generated schemas. 097 * <p> 098 * The examples come from calling {@link ClassMeta#getExample(BeanSession,JsonParserSession)} which in turn gets examples 099 * from the following: 100 * <ul class='javatree'> 101 * <li class='ja'>{@link Example} 102 * <li class='ja'>{@link Marshalled#example() Marshalled(example)} 103 * </ul> 104 * 105 * <h5 class='section'>Notes:</h5><ul> 106 * <li class='note'> 107 * The format is a comma-delimited list of any of the following values: 108 * <ul class='doctree'> 109 * <li><js>"BEAN"</js> 110 * <li><js>"COLLECTION"</js> 111 * <li><js>"ARRAY"</js> 112 * <li><js>"MAP"</js> 113 * <li><js>"STRING"</js> 114 * <li><js>"NUMBER"</js> 115 * <li><js>"BOOLEAN"</js> 116 * <li><js>"ANY"</js> 117 * <li><js>"OTHER"</js> 118 * </ul> 119 * <li class='note'> 120 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 121 * </ul> 122 * 123 * <h5 class='section'>See Also:</h5><ul> 124 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#addDescriptionsTo(TypeCategory...)} 125 * </ul> 126 * 127 * @return The annotation value. 128 */ 129 String addExamplesTo() default ""; 130 131 /** 132 * Allow nested descriptions. 133 * 134 * <p> 135 * Identifies whether nested descriptions are allowed in schema definitions. 136 * 137 * <ul class='values'> 138 * <li><js>"true"</js> 139 * <li><js>"false"</js> (default) 140 * </ul> 141 * 142 * <h5 class='section'>Notes:</h5><ul> 143 * <li class='note'> 144 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 145 * </ul> 146 * 147 * <h5 class='section'>See Also:</h5><ul> 148 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#allowNestedDescriptions()} 149 * </ul> 150 * 151 * @return The annotation value. 152 */ 153 String allowNestedDescriptions() default ""; 154 155 /** 156 * Allow nested examples. 157 * 158 * <p> 159 * Identifies whether nested examples are allowed in schema definitions. 160 * 161 * <ul class='values'> 162 * <li><js>"true"</js> 163 * <li><js>"false"</js> (default) 164 * </ul> 165 * 166 * <h5 class='section'>Notes:</h5><ul> 167 * <li class='note'> 168 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 169 * </ul> 170 * 171 * <h5 class='section'>See Also:</h5><ul> 172 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#allowNestedExamples()} 173 * </ul> 174 * 175 * @return The annotation value. 176 */ 177 String allowNestedExamples() default ""; 178 179 /** 180 * Bean schema definition mapper. 181 * 182 * <p> 183 * Interface to use for converting Bean classes to definition IDs and URIs. 184 * 185 * <p> 186 * Used primarily for defining common definition sections for beans in Swagger JSON. 187 * 188 * <h5 class='section'>Notes:</h5><ul> 189 * <li class='note'> 190 * This setting is ignored if {@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#useBeanDefs()} is not enabled. 191 * </ul> 192 * 193 * <h5 class='section'>See Also:</h5><ul> 194 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#beanDefMapper(Class)} 195 * </ul> 196 * 197 * @return The annotation value. 198 */ 199 Class<? extends BeanDefMapper> beanDefMapper() default BeanDefMapper.Void.class; 200 201 /** 202 * Ignore types from schema definitions. 203 * 204 * <p> 205 * Defines class name patterns that should be ignored when generating schema definitions in the generated 206 * Swagger documentation. 207 * 208 * <h5 class='section'>Notes:</h5><ul> 209 * <li class='note'> 210 * Format: Comma-delimited list of patterns 211 * <li class='note'> 212 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 213 * </ul> 214 * 215 * <h5 class='section'>See Also:</h5><ul> 216 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#ignoreTypes(String...)} 217 * </ul> 218 * 219 * @return The annotation value. 220 */ 221 String ignoreTypes() default ""; 222 223 /** 224 * Use bean definitions. 225 * 226 * <p> 227 * When enabled, schemas on beans will be serialized as the following: 228 * <p class='bjson'> 229 * { 230 * type: <js>'object'</js>, 231 * <js>'$ref'</js>: <js>'#/definitions/TypeId'</js> 232 * } 233 * </p> 234 * 235 * <p> 236 * The definitions can then be retrieved from the session using {@link JsonSchemaGeneratorSession#getBeanDefs()}. 237 * 238 * <p> 239 * Definitions can also be added programmatically using {@link JsonSchemaGeneratorSession#addBeanDef(String, JsonMap)}. 240 * 241 * <ul class='values'> 242 * <li><js>"true"</js> 243 * <li><js>"false"</js> (default) 244 * </ul> 245 * 246 * <h5 class='section'>Notes:</h5><ul> 247 * <li class='note'> 248 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 249 * </ul> 250 * 251 * <h5 class='section'>See Also:</h5><ul> 252 * <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#useBeanDefs()} 253 * </ul> 254 * 255 * @return The annotation value. 256 */ 257 String useBeanDefs() default ""; 258 259 //----------------------------------------------------------------------------------------------------------------- 260 // BeanTraverseContext 261 //----------------------------------------------------------------------------------------------------------------- 262 263 /** 264 * Automatically detect POJO recursions. 265 * 266 * <p> 267 * Specifies that recursions should be checked for during traversal. 268 * 269 * <p> 270 * Recursions can occur when traversing models that aren't true trees but rather contain loops. 271 * <br>In general, unchecked recursions cause stack-overflow-errors. 272 * <br>These show up as {@link ParseException ParseExceptions} with the message <js>"Depth too deep. Stack overflow occurred."</js>. 273 * 274 * <p> 275 * The behavior when recursions are detected depends on the value for {@link org.apache.juneau.BeanTraverseContext.Builder#ignoreRecursions()}. 276 * 277 * <p> 278 * For example, if a model contains the links A->B->C->A, then the JSON generated will look like 279 * the following when <jsf>BEANTRAVERSE_ignoreRecursions</jsf> is <jk>true</jk>... 280 * 281 * <p class='bjson'> 282 * {A:{B:{C:<jk>null</jk>}}} 283 * </p> 284 * 285 * <ul class='values'> 286 * <li><js>"true"</js> 287 * <li><js>"false"</js> (default) 288 * </ul> 289 * 290 * <h5 class='section'>Notes:</h5><ul> 291 * <li class='warn'> 292 * Checking for recursion can cause a small performance penalty. 293 * <li class='note'> 294 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 295 * </ul> 296 * 297 * <h5 class='section'>See Also:</h5><ul> 298 * <li class='jm'>{@link org.apache.juneau.BeanTraverseContext.Builder#detectRecursions()} 299 * </ul> 300 * 301 * @return The annotation value. 302 */ 303 String detectRecursions() default ""; 304 305 /** 306 * Ignore recursion errors. 307 * 308 * <p> 309 * Used in conjunction with {@link org.apache.juneau.BeanTraverseContext.Builder#detectRecursions()}. 310 * <br>Setting is ignored if <jsf>BEANTRAVERSE_detectRecursions</jsf> is <js>"false"</js>. 311 * 312 * <p> 313 * If <js>"true"</js>, when we encounter the same object when traversing a tree, we set the value to <jk>null</jk>. 314 * <br>Otherwise, a {@link BeanRecursionException} is thrown with the message <js>"Recursion occurred, stack=..."</js>. 315 * 316 * <ul class='values'> 317 * <li><js>"true"</js> 318 * <li><js>"false"</js> (default) 319 * </ul> 320 * 321 * <h5 class='section'>Notes:</h5><ul> 322 * <li class='note'> 323 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 324 * </ul> 325 * 326 * <h5 class='section'>See Also:</h5><ul> 327 * <li class='jm'>{@link org.apache.juneau.BeanTraverseContext.Builder#ignoreRecursions()} 328 * </ul> 329 * 330 * @return The annotation value. 331 */ 332 String ignoreRecursions() default ""; 333 334 /** 335 * Initial depth. 336 * 337 * <p> 338 * The initial indentation level at the root. 339 * <br>Useful when constructing document fragments that need to be indented at a certain level. 340 * 341 * <h5 class='section'>Notes:</h5><ul> 342 * <li class='note'> 343 * Format: integer 344 * <li class='note'> 345 * Default value: <js>"0"</js> 346 * <li class='note'> 347 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 348 * </ul> 349 * 350 * <h5 class='section'>See Also:</h5><ul> 351 * <li class='jm'>{@link org.apache.juneau.BeanTraverseContext.Builder#initialDepth(int)} 352 * </ul> 353 * 354 * @return The annotation value. 355 */ 356 String initialDepth() default ""; 357 358 /** 359 * Max traversal depth. 360 * 361 * <p> 362 * Abort traversal if specified depth is reached in the POJO tree. 363 * <br>If this depth is exceeded, an exception is thrown. 364 * 365 * <h5 class='section'>Notes:</h5><ul> 366 * <li class='note'> 367 * Format: integer 368 * <li class='note'> 369 * Default value: <js>"100"</js> 370 * <li class='note'> 371 * Supports <a class="doclink" href="../../../../../index.html#jm.DefaultVarResolver">VarResolver.DEFAULT</a> (e.g. <js>"$C{myConfigVar}"</js>). 372 * </ul> 373 * 374 * <h5 class='section'>See Also:</h5><ul> 375 * <li class='jm'>{@link org.apache.juneau.BeanTraverseContext.Builder#maxDepth(int)} 376 * </ul> 377 * 378 * @return The annotation value. 379 */ 380 String maxDepth() default ""; 381}