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