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.json;
014
015import static org.apache.juneau.collections.JsonMap.*;
016
017import java.lang.annotation.*;
018import java.lang.reflect.*;
019import java.nio.charset.*;
020import java.util.*;
021import java.util.concurrent.*;
022
023import org.apache.juneau.*;
024import org.apache.juneau.annotation.*;
025import org.apache.juneau.collections.*;
026import org.apache.juneau.internal.*;
027import org.apache.juneau.jsonschema.*;
028import org.apache.juneau.utils.*;
029
030/**
031 * Serializes POJO metadata to HTTP responses as JSON-Schema.
032 *
033 * <h5 class='topic'>Media types</h5>
034 *
035 * Handles <c>Accept</c> types:  <bc>application/json+schema, text/json+schema</bc>
036 * <p>
037 * Produces <c>Content-Type</c> types:  <bc>application/json</bc>
038 *
039 * <h5 class='topic'>Description</h5>
040 *
041 * Produces the JSON-schema for the JSON produced by the {@link JsonSerializer} class with the same properties.
042 *
043 * <h5 class='section'>Notes:</h5><ul>
044 *    <li class='note'>This class is thread safe and reusable.
045 * </ul>
046 *
047 * <h5 class='section'>See Also:</h5><ul>
048 *    <li class='link'><a class="doclink" href="../../../../index.html#jm.JsonDetails">JSON Details</a>
049
050 * </ul>
051 */
052public class JsonSchemaSerializer extends JsonSerializer implements JsonSchemaMetaProvider {
053
054   //-------------------------------------------------------------------------------------------------------------------
055   // Static
056   //-------------------------------------------------------------------------------------------------------------------
057
058   /** Default serializer, all default settings.*/
059   public static final JsonSchemaSerializer DEFAULT = new JsonSchemaSerializer(create());
060
061   /** Default serializer, all default settings.*/
062   public static final JsonSchemaSerializer DEFAULT_READABLE = new Readable(create());
063
064   /** Default serializer, single quotes, simple mode. */
065   public static final JsonSchemaSerializer DEFAULT_SIMPLE = new Simple(create());
066
067   /** Default serializer, single quotes, simple mode, with whitespace. */
068   public static final JsonSchemaSerializer DEFAULT_SIMPLE_READABLE = new SimpleReadable(create());
069
070   /**
071    * Creates a new builder for this object.
072    *
073    * @return A new builder.
074    */
075   public static Builder create() {
076      return new Builder();
077   }
078
079   //-------------------------------------------------------------------------------------------------------------------
080   // Static subclasses
081   //-------------------------------------------------------------------------------------------------------------------
082
083   /** Default serializer, with whitespace. */
084   public static class Readable extends JsonSchemaSerializer {
085
086      /**
087       * Constructor.
088       *
089       * @param builder The builder for this object.
090       */
091      public Readable(Builder builder) {
092         super(builder.useWhitespace());
093      }
094   }
095
096   /** Default serializer, single quotes, simple mode. */
097   public static class Simple extends JsonSchemaSerializer {
098
099      /**
100       * Constructor.
101       *
102       * @param builder The builder for this object.
103       */
104      public Simple(Builder builder) {
105         super(builder.simpleAttrs().quoteChar('\''));
106      }
107   }
108
109   /** Default serializer, single quotes, simple mode, with whitespace. */
110   public static class SimpleReadable extends JsonSchemaSerializer {
111
112      /**
113       * Constructor.
114       *
115       * @param builder The builder for this object.
116       */
117      public SimpleReadable(Builder builder) {
118         super(builder.simpleAttrs().quoteChar('\'').useWhitespace());
119      }
120   }
121
122   //-------------------------------------------------------------------------------------------------------------------
123   // Builder
124   //-------------------------------------------------------------------------------------------------------------------
125
126   /**
127    * Builder class.
128    */
129   @FluentSetters
130   public static class Builder extends JsonSerializer.Builder {
131
132      private static final Cache<HashKey,JsonSchemaSerializer> CACHE = Cache.of(HashKey.class, JsonSchemaSerializer.class).build();
133
134      JsonSchemaGenerator.Builder generatorBuilder;
135
136      /**
137       * Constructor, default settings.
138       */
139      protected Builder() {
140         super();
141         produces("application/json");
142         accept("application/json+schema,text/json+schema");
143         generatorBuilder = JsonSchemaGenerator.create().beanContext(beanContext());
144      }
145
146      /**
147       * Copy constructor.
148       *
149       * @param copyFrom The bean to copy from.
150       */
151      protected Builder(JsonSchemaSerializer copyFrom) {
152         super(copyFrom);
153         generatorBuilder = copyFrom.generator.copy().beanContext(beanContext());
154      }
155
156      /**
157       * Copy constructor.
158       *
159       * @param copyFrom The builder to copy from.
160       */
161      protected Builder(Builder copyFrom) {
162         super(copyFrom);
163         generatorBuilder = copyFrom.generatorBuilder.copy().beanContext(beanContext());
164      }
165
166      @Override /* Context.Builder */
167      public Builder copy() {
168         return new Builder(this);
169      }
170
171      @Override /* Context.Builder */
172      public JsonSchemaSerializer build() {
173         return cache(CACHE).build(JsonSchemaSerializer.class);
174      }
175
176      @Override /* Context.Builder */
177      public HashKey hashKey() {
178         return HashKey.of(
179            super.hashKey(),
180            generatorBuilder.hashKey()
181         );
182      }
183
184      //-----------------------------------------------------------------------------------------------------------------
185      // Properties
186      //-----------------------------------------------------------------------------------------------------------------
187
188      /**
189       * <i><l>JsonSchemaSerializer</l> configuration property:&emsp;</i>  Add descriptions.
190       *
191       * <p>
192       * Identifies which categories of types that descriptions should be automatically added to generated schemas.
193       * <p>
194       * The description is the result of calling {@link ClassMeta#getFullName()}.
195       *
196       * <h5 class='section'>See Also:</h5><ul>
197       *    <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#addDescriptionsTo(TypeCategory...)}
198       * </ul>
199       *
200       * @param values
201       *    The values to add to this setting.
202       *    <br>The default is an empty string.
203       * @return This object.
204       */
205      @FluentSetter
206      public Builder addDescriptionsTo(TypeCategory...values) {
207         generatorBuilder.addDescriptionsTo(values);
208         return this;
209      }
210
211      /**
212       * <i><l>JsonSchemaSerializer</l> configuration property:&emsp;</i>  Add examples.
213       *
214       * <p>
215       * Identifies which categories of types that examples should be automatically added to generated schemas.
216       * <p>
217       * The examples come from calling {@link ClassMeta#getExample(BeanSession,JsonParserSession)} which in turn gets examples
218       * from the following:
219       * <ul class='javatree'>
220       *    <li class='ja'>{@link Example}
221       *    <li class='ja'>{@link Marshalled#example() Marshalled(example)}
222       * </ul>
223       *
224       * <h5 class='section'>See Also:</h5><ul>
225       *    <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#addExamplesTo(TypeCategory...)}
226       * </ul>
227       *
228       * @param values
229       *    The values to add to this setting.
230       *    <br>The default is an empty string.
231       * @return This object.
232       */
233      @FluentSetter
234      public Builder addExamplesTo(TypeCategory...values) {
235         generatorBuilder.addExamplesTo(values);
236         return this;
237      }
238
239      /**
240       * <i><l>JsonSchemaSerializer</l> configuration property:&emsp;</i>  Allow nested descriptions.
241       *
242       * <p>
243       * Identifies whether nested descriptions are allowed in schema definitions.
244       *
245       * <h5 class='section'>See Also:</h5><ul>
246       *    <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#allowNestedDescriptions()}
247       * </ul>
248       *
249       * @return This object.
250       */
251      @FluentSetter
252      public Builder allowNestedDescriptions() {
253         generatorBuilder.allowNestedDescriptions();
254         return this;
255      }
256
257      /**
258       * <i><l>JsonSchemaSerializer</l> configuration property:&emsp;</i>  Allow nested examples.
259       *
260       * <p>
261       * Identifies whether nested examples are allowed in schema definitions.
262       *
263       * <h5 class='section'>See Also:</h5><ul>
264       *    <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#allowNestedExamples()}
265       * </ul>
266       *
267       * @return This object.
268       */
269      @FluentSetter
270      public Builder allowNestedExamples() {
271         generatorBuilder.allowNestedExamples();
272         return this;
273      }
274
275      /**
276       * <i><l>JsonSchemaSerializer</l> configuration property:&emsp;</i>  Schema definition mapper.
277       *
278       * <p>
279       * Interface to use for converting Bean classes to definition IDs and URIs.
280       * <p>
281       * Used primarily for defining common definition sections for beans in Swagger JSON.
282       * <p>
283       * This setting is ignored if {@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#useBeanDefs()} is not enabled.
284       *
285       * <h5 class='section'>See Also:</h5><ul>
286       *    <li class='jm'>{@link org.apache.juneau.jsonschema.JsonSchemaGenerator.Builder#beanDefMapper(Class)}
287       * </ul>
288       *
289       * @param value
290       *    The new value for this property.
291       *    <br>The default is {@link org.apache.juneau.jsonschema.BasicBeanDefMapper}.
292       * @return This object.
293       */
294      @FluentSetter
295      public Builder beanDefMapper(Class<? extends BeanDefMapper> value) {
296         generatorBuilder.beanDefMapper(value);
297         return this;
298      }
299
300      /**
301       * <i><l>JsonSchemaSerializer</l> configuration property:&emsp;</i>  Use bean definitions.
302       *
303       * <p>
304       * When enabled, schemas on beans will be serialized as the following:
305       * <p class='bjson'>
306       *    {
307       *       type: <js>'object'</js>,
308       *       <js>'$ref'</js>: <js>'#/definitions/TypeId'</js>
309       *    }
310       * </p>
311       *
312       * @return This object.
313       */
314      @FluentSetter
315      public Builder useBeanDefs() {
316         generatorBuilder.useBeanDefs();
317         return this;
318      }
319
320      // <FluentSetters>
321
322      @Override /* GENERATED - org.apache.juneau.Context.Builder */
323      public Builder annotations(Annotation...values) {
324         super.annotations(values);
325         return this;
326      }
327
328      @Override /* GENERATED - org.apache.juneau.Context.Builder */
329      public Builder apply(AnnotationWorkList work) {
330         super.apply(work);
331         return this;
332      }
333
334      @Override /* GENERATED - org.apache.juneau.Context.Builder */
335      public Builder applyAnnotations(java.lang.Class<?>...fromClasses) {
336         super.applyAnnotations(fromClasses);
337         return this;
338      }
339
340      @Override /* GENERATED - org.apache.juneau.Context.Builder */
341      public Builder applyAnnotations(Method...fromMethods) {
342         super.applyAnnotations(fromMethods);
343         return this;
344      }
345
346      @Override /* GENERATED - org.apache.juneau.Context.Builder */
347      public Builder cache(Cache<HashKey,? extends org.apache.juneau.Context> value) {
348         super.cache(value);
349         return this;
350      }
351
352      @Override /* GENERATED - org.apache.juneau.Context.Builder */
353      public Builder debug() {
354         super.debug();
355         return this;
356      }
357
358      @Override /* GENERATED - org.apache.juneau.Context.Builder */
359      public Builder debug(boolean value) {
360         super.debug(value);
361         return this;
362      }
363
364      @Override /* GENERATED - org.apache.juneau.Context.Builder */
365      public Builder impl(Context value) {
366         super.impl(value);
367         return this;
368      }
369
370      @Override /* GENERATED - org.apache.juneau.Context.Builder */
371      public Builder type(Class<? extends org.apache.juneau.Context> value) {
372         super.type(value);
373         return this;
374      }
375
376      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
377      public Builder beanClassVisibility(Visibility value) {
378         super.beanClassVisibility(value);
379         return this;
380      }
381
382      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
383      public Builder beanConstructorVisibility(Visibility value) {
384         super.beanConstructorVisibility(value);
385         return this;
386      }
387
388      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
389      public Builder beanContext(BeanContext value) {
390         super.beanContext(value);
391         return this;
392      }
393
394      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
395      public Builder beanContext(BeanContext.Builder value) {
396         super.beanContext(value);
397         return this;
398      }
399
400      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
401      public Builder beanDictionary(java.lang.Class<?>...values) {
402         super.beanDictionary(values);
403         return this;
404      }
405
406      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
407      public Builder beanFieldVisibility(Visibility value) {
408         super.beanFieldVisibility(value);
409         return this;
410      }
411
412      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
413      public Builder beanInterceptor(Class<?> on, Class<? extends org.apache.juneau.swap.BeanInterceptor<?>> value) {
414         super.beanInterceptor(on, value);
415         return this;
416      }
417
418      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
419      public Builder beanMapPutReturnsOldValue() {
420         super.beanMapPutReturnsOldValue();
421         return this;
422      }
423
424      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
425      public Builder beanMethodVisibility(Visibility value) {
426         super.beanMethodVisibility(value);
427         return this;
428      }
429
430      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
431      public Builder beanProperties(Map<String,Object> values) {
432         super.beanProperties(values);
433         return this;
434      }
435
436      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
437      public Builder beanProperties(Class<?> beanClass, String properties) {
438         super.beanProperties(beanClass, properties);
439         return this;
440      }
441
442      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
443      public Builder beanProperties(String beanClassName, String properties) {
444         super.beanProperties(beanClassName, properties);
445         return this;
446      }
447
448      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
449      public Builder beanPropertiesExcludes(Map<String,Object> values) {
450         super.beanPropertiesExcludes(values);
451         return this;
452      }
453
454      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
455      public Builder beanPropertiesExcludes(Class<?> beanClass, String properties) {
456         super.beanPropertiesExcludes(beanClass, properties);
457         return this;
458      }
459
460      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
461      public Builder beanPropertiesExcludes(String beanClassName, String properties) {
462         super.beanPropertiesExcludes(beanClassName, properties);
463         return this;
464      }
465
466      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
467      public Builder beanPropertiesReadOnly(Map<String,Object> values) {
468         super.beanPropertiesReadOnly(values);
469         return this;
470      }
471
472      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
473      public Builder beanPropertiesReadOnly(Class<?> beanClass, String properties) {
474         super.beanPropertiesReadOnly(beanClass, properties);
475         return this;
476      }
477
478      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
479      public Builder beanPropertiesReadOnly(String beanClassName, String properties) {
480         super.beanPropertiesReadOnly(beanClassName, properties);
481         return this;
482      }
483
484      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
485      public Builder beanPropertiesWriteOnly(Map<String,Object> values) {
486         super.beanPropertiesWriteOnly(values);
487         return this;
488      }
489
490      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
491      public Builder beanPropertiesWriteOnly(Class<?> beanClass, String properties) {
492         super.beanPropertiesWriteOnly(beanClass, properties);
493         return this;
494      }
495
496      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
497      public Builder beanPropertiesWriteOnly(String beanClassName, String properties) {
498         super.beanPropertiesWriteOnly(beanClassName, properties);
499         return this;
500      }
501
502      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
503      public Builder beansRequireDefaultConstructor() {
504         super.beansRequireDefaultConstructor();
505         return this;
506      }
507
508      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
509      public Builder beansRequireSerializable() {
510         super.beansRequireSerializable();
511         return this;
512      }
513
514      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
515      public Builder beansRequireSettersForGetters() {
516         super.beansRequireSettersForGetters();
517         return this;
518      }
519
520      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
521      public Builder dictionaryOn(Class<?> on, java.lang.Class<?>...values) {
522         super.dictionaryOn(on, values);
523         return this;
524      }
525
526      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
527      public Builder disableBeansRequireSomeProperties() {
528         super.disableBeansRequireSomeProperties();
529         return this;
530      }
531
532      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
533      public Builder disableIgnoreMissingSetters() {
534         super.disableIgnoreMissingSetters();
535         return this;
536      }
537
538      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
539      public Builder disableIgnoreTransientFields() {
540         super.disableIgnoreTransientFields();
541         return this;
542      }
543
544      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
545      public Builder disableIgnoreUnknownNullBeanProperties() {
546         super.disableIgnoreUnknownNullBeanProperties();
547         return this;
548      }
549
550      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
551      public Builder disableInterfaceProxies() {
552         super.disableInterfaceProxies();
553         return this;
554      }
555
556      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
557      public <T> Builder example(Class<T> pojoClass, T o) {
558         super.example(pojoClass, o);
559         return this;
560      }
561
562      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
563      public <T> Builder example(Class<T> pojoClass, String json) {
564         super.example(pojoClass, json);
565         return this;
566      }
567
568      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
569      public Builder findFluentSetters() {
570         super.findFluentSetters();
571         return this;
572      }
573
574      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
575      public Builder findFluentSetters(Class<?> on) {
576         super.findFluentSetters(on);
577         return this;
578      }
579
580      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
581      public Builder ignoreInvocationExceptionsOnGetters() {
582         super.ignoreInvocationExceptionsOnGetters();
583         return this;
584      }
585
586      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
587      public Builder ignoreInvocationExceptionsOnSetters() {
588         super.ignoreInvocationExceptionsOnSetters();
589         return this;
590      }
591
592      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
593      public Builder ignoreUnknownBeanProperties() {
594         super.ignoreUnknownBeanProperties();
595         return this;
596      }
597
598      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
599      public Builder ignoreUnknownEnumValues() {
600         super.ignoreUnknownEnumValues();
601         return this;
602      }
603
604      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
605      public Builder implClass(Class<?> interfaceClass, Class<?> implClass) {
606         super.implClass(interfaceClass, implClass);
607         return this;
608      }
609
610      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
611      public Builder implClasses(Map<Class<?>,Class<?>> values) {
612         super.implClasses(values);
613         return this;
614      }
615
616      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
617      public Builder interfaceClass(Class<?> on, Class<?> value) {
618         super.interfaceClass(on, value);
619         return this;
620      }
621
622      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
623      public Builder interfaces(java.lang.Class<?>...value) {
624         super.interfaces(value);
625         return this;
626      }
627
628      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
629      public Builder locale(Locale value) {
630         super.locale(value);
631         return this;
632      }
633
634      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
635      public Builder mediaType(MediaType value) {
636         super.mediaType(value);
637         return this;
638      }
639
640      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
641      public Builder notBeanClasses(java.lang.Class<?>...values) {
642         super.notBeanClasses(values);
643         return this;
644      }
645
646      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
647      public Builder notBeanPackages(String...values) {
648         super.notBeanPackages(values);
649         return this;
650      }
651
652      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
653      public Builder propertyNamer(Class<? extends org.apache.juneau.PropertyNamer> value) {
654         super.propertyNamer(value);
655         return this;
656      }
657
658      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
659      public Builder propertyNamer(Class<?> on, Class<? extends org.apache.juneau.PropertyNamer> value) {
660         super.propertyNamer(on, value);
661         return this;
662      }
663
664      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
665      public Builder sortProperties() {
666         super.sortProperties();
667         return this;
668      }
669
670      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
671      public Builder sortProperties(java.lang.Class<?>...on) {
672         super.sortProperties(on);
673         return this;
674      }
675
676      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
677      public Builder stopClass(Class<?> on, Class<?> value) {
678         super.stopClass(on, value);
679         return this;
680      }
681
682      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
683      public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction) {
684         super.swap(normalClass, swappedClass, swapFunction);
685         return this;
686      }
687
688      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
689      public <T, S> Builder swap(Class<T> normalClass, Class<S> swappedClass, ThrowingFunction<T,S> swapFunction, ThrowingFunction<S,T> unswapFunction) {
690         super.swap(normalClass, swappedClass, swapFunction, unswapFunction);
691         return this;
692      }
693
694      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
695      public Builder swaps(java.lang.Class<?>...values) {
696         super.swaps(values);
697         return this;
698      }
699
700      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
701      public Builder timeZone(TimeZone value) {
702         super.timeZone(value);
703         return this;
704      }
705
706      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
707      public Builder typeName(Class<?> on, String value) {
708         super.typeName(on, value);
709         return this;
710      }
711
712      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
713      public Builder typePropertyName(String value) {
714         super.typePropertyName(value);
715         return this;
716      }
717
718      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
719      public Builder typePropertyName(Class<?> on, String value) {
720         super.typePropertyName(on, value);
721         return this;
722      }
723
724      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
725      public Builder useEnumNames() {
726         super.useEnumNames();
727         return this;
728      }
729
730      @Override /* GENERATED - org.apache.juneau.BeanContextable.Builder */
731      public Builder useJavaBeanIntrospector() {
732         super.useJavaBeanIntrospector();
733         return this;
734      }
735
736      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
737      public Builder detectRecursions() {
738         super.detectRecursions();
739         return this;
740      }
741
742      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
743      public Builder detectRecursions(boolean value) {
744         super.detectRecursions(value);
745         return this;
746      }
747
748      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
749      public Builder ignoreRecursions() {
750         super.ignoreRecursions();
751         return this;
752      }
753
754      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
755      public Builder ignoreRecursions(boolean value) {
756         super.ignoreRecursions(value);
757         return this;
758      }
759
760      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
761      public Builder initialDepth(int value) {
762         super.initialDepth(value);
763         return this;
764      }
765
766      @Override /* GENERATED - org.apache.juneau.BeanTraverseContext.Builder */
767      public Builder maxDepth(int value) {
768         super.maxDepth(value);
769         return this;
770      }
771
772      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
773      public Builder accept(String value) {
774         super.accept(value);
775         return this;
776      }
777
778      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
779      public Builder addBeanTypes() {
780         super.addBeanTypes();
781         return this;
782      }
783
784      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
785      public Builder addBeanTypes(boolean value) {
786         super.addBeanTypes(value);
787         return this;
788      }
789
790      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
791      public Builder addRootType() {
792         super.addRootType();
793         return this;
794      }
795
796      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
797      public Builder addRootType(boolean value) {
798         super.addRootType(value);
799         return this;
800      }
801
802      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
803      public Builder keepNullProperties() {
804         super.keepNullProperties();
805         return this;
806      }
807
808      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
809      public Builder keepNullProperties(boolean value) {
810         super.keepNullProperties(value);
811         return this;
812      }
813
814      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
815      public Builder listener(Class<? extends org.apache.juneau.serializer.SerializerListener> value) {
816         super.listener(value);
817         return this;
818      }
819
820      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
821      public Builder produces(String value) {
822         super.produces(value);
823         return this;
824      }
825
826      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
827      public Builder sortCollections() {
828         super.sortCollections();
829         return this;
830      }
831
832      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
833      public Builder sortCollections(boolean value) {
834         super.sortCollections(value);
835         return this;
836      }
837
838      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
839      public Builder sortMaps() {
840         super.sortMaps();
841         return this;
842      }
843
844      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
845      public Builder sortMaps(boolean value) {
846         super.sortMaps(value);
847         return this;
848      }
849
850      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
851      public Builder trimEmptyCollections() {
852         super.trimEmptyCollections();
853         return this;
854      }
855
856      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
857      public Builder trimEmptyCollections(boolean value) {
858         super.trimEmptyCollections(value);
859         return this;
860      }
861
862      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
863      public Builder trimEmptyMaps() {
864         super.trimEmptyMaps();
865         return this;
866      }
867
868      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
869      public Builder trimEmptyMaps(boolean value) {
870         super.trimEmptyMaps(value);
871         return this;
872      }
873
874      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
875      public Builder trimStrings() {
876         super.trimStrings();
877         return this;
878      }
879
880      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
881      public Builder trimStrings(boolean value) {
882         super.trimStrings(value);
883         return this;
884      }
885
886      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
887      public Builder uriContext(UriContext value) {
888         super.uriContext(value);
889         return this;
890      }
891
892      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
893      public Builder uriRelativity(UriRelativity value) {
894         super.uriRelativity(value);
895         return this;
896      }
897
898      @Override /* GENERATED - org.apache.juneau.serializer.Serializer.Builder */
899      public Builder uriResolution(UriResolution value) {
900         super.uriResolution(value);
901         return this;
902      }
903
904      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
905      public Builder fileCharset(Charset value) {
906         super.fileCharset(value);
907         return this;
908      }
909
910      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
911      public Builder maxIndent(int value) {
912         super.maxIndent(value);
913         return this;
914      }
915
916      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
917      public Builder quoteChar(char value) {
918         super.quoteChar(value);
919         return this;
920      }
921
922      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
923      public Builder quoteCharOverride(char value) {
924         super.quoteCharOverride(value);
925         return this;
926      }
927
928      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
929      public Builder sq() {
930         super.sq();
931         return this;
932      }
933
934      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
935      public Builder streamCharset(Charset value) {
936         super.streamCharset(value);
937         return this;
938      }
939
940      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
941      public Builder useWhitespace() {
942         super.useWhitespace();
943         return this;
944      }
945
946      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
947      public Builder useWhitespace(boolean value) {
948         super.useWhitespace(value);
949         return this;
950      }
951
952      @Override /* GENERATED - org.apache.juneau.serializer.WriterSerializer.Builder */
953      public Builder ws() {
954         super.ws();
955         return this;
956      }
957
958      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
959      public Builder addBeanTypesJson() {
960         super.addBeanTypesJson();
961         return this;
962      }
963
964      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
965      public Builder addBeanTypesJson(boolean value) {
966         super.addBeanTypesJson(value);
967         return this;
968      }
969
970      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
971      public Builder escapeSolidus() {
972         super.escapeSolidus();
973         return this;
974      }
975
976      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
977      public Builder escapeSolidus(boolean value) {
978         super.escapeSolidus(value);
979         return this;
980      }
981
982      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
983      public Builder simpleAttrs() {
984         super.simpleAttrs();
985         return this;
986      }
987
988      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
989      public Builder simpleAttrs(boolean value) {
990         super.simpleAttrs(value);
991         return this;
992      }
993
994      @Override /* GENERATED - org.apache.juneau.json.JsonSerializer.Builder */
995      public Builder json5() {
996         super.json5();
997         return this;
998      }
999
1000      // </FluentSetters>
1001   }
1002
1003   //-------------------------------------------------------------------------------------------------------------------
1004   // Instance
1005   //-------------------------------------------------------------------------------------------------------------------
1006
1007   final JsonSchemaGenerator generator;
1008
1009   private final Map<ClassMeta<?>,JsonSchemaClassMeta> jsonSchemaClassMetas = new ConcurrentHashMap<>();
1010   private final Map<BeanPropertyMeta,JsonSchemaBeanPropertyMeta> jsonSchemaBeanPropertyMetas = new ConcurrentHashMap<>();
1011
1012   /**
1013    * Constructor.
1014    *
1015    * @param builder The builder for this object.
1016    */
1017   public JsonSchemaSerializer(Builder builder) {
1018      super(builder.detectRecursions().ignoreRecursions());
1019
1020      generator = builder.generatorBuilder.build();
1021   }
1022
1023   @Override /* Context */
1024   public Builder copy() {
1025      return new Builder(this);
1026   }
1027
1028   @Override /* Context */
1029   public JsonSchemaSerializerSession.Builder createSession() {
1030      return JsonSchemaSerializerSession.create(this);
1031   }
1032
1033   @Override /* Context */
1034   public JsonSchemaSerializerSession getSession() {
1035      return createSession().build();
1036   }
1037
1038   JsonSchemaGenerator getGenerator() {
1039      return generator;
1040   }
1041
1042   //-----------------------------------------------------------------------------------------------------------------
1043   // Extended metadata
1044   //-----------------------------------------------------------------------------------------------------------------
1045
1046   @Override /* JsonSchemaMetaProvider */
1047   public JsonSchemaClassMeta getJsonSchemaClassMeta(ClassMeta<?> cm) {
1048      JsonSchemaClassMeta m = jsonSchemaClassMetas.get(cm);
1049      if (m == null) {
1050         m = new JsonSchemaClassMeta(cm, this);
1051         jsonSchemaClassMetas.put(cm, m);
1052      }
1053      return m;
1054   }
1055
1056   @Override /* JsonSchemaMetaProvider */
1057   public JsonSchemaBeanPropertyMeta getJsonSchemaBeanPropertyMeta(BeanPropertyMeta bpm) {
1058      JsonSchemaBeanPropertyMeta m = jsonSchemaBeanPropertyMetas.get(bpm);
1059      if (m == null) {
1060         m = new JsonSchemaBeanPropertyMeta(bpm.getDelegateFor(), this);
1061         jsonSchemaBeanPropertyMetas.put(bpm, m);
1062      }
1063      return m;
1064   }
1065
1066   //-----------------------------------------------------------------------------------------------------------------
1067   // Other methods
1068   //-----------------------------------------------------------------------------------------------------------------
1069
1070   @Override /* Context */
1071   protected JsonMap properties() {
1072      return filteredMap("generator", generator);
1073   }
1074}