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