1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.schemagen.json;
7   
8   import com.fasterxml.jackson.core.JsonGenerator;
9   import com.fasterxml.jackson.databind.node.JsonNodeFactory;
10  
11  import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
12  import gov.nist.secauto.metaschema.core.model.IDefinition;
13  import gov.nist.secauto.metaschema.core.model.IValuedDefinition;
14  import gov.nist.secauto.metaschema.schemagen.IGenerationState;
15  import gov.nist.secauto.metaschema.schemagen.json.IDefineableJsonSchema.IKey;
16  
17  import edu.umd.cs.findbugs.annotations.NonNull;
18  import edu.umd.cs.findbugs.annotations.Nullable;
19  
20  public interface IJsonGenerationState extends IGenerationState<JsonGenerator> {
21    /**
22     * Get the JSON schema info for the provided definition.
23     *
24     * @param <DEF>
25     *          the definition's Java type
26     * @param definition
27     *          the definition to get the schema info for
28     * @param jsonKeyFlagName
29     *          the name of the flag to use as the JSON key, or @{code null} if no
30     *          flag is used as the JSON key
31     * @param discriminatorProperty
32     *          the property name to use as the choice group discriminator,
33     *          or @{code null} if no choice group discriminator is used
34     * @param discriminatorValue
35     *          the property value to use as the choice group discriminator,
36     *          or @{code null} if no choice group discriminator is used
37     * @return the definition's schema info
38     */
39    @NonNull
40    default <DEF extends IDefinition> IDefinitionJsonSchema<DEF> getSchema(
41        @NonNull DEF definition,
42        @Nullable String jsonKeyFlagName,
43        @Nullable String discriminatorProperty,
44        @Nullable String discriminatorValue) {
45      return getSchema(IKey.of(definition, jsonKeyFlagName, discriminatorProperty, discriminatorValue));
46    }
47  
48    @NonNull
49    <DEF extends IDefinition> IDefinitionJsonSchema<DEF> getSchema(@NonNull IKey key);
50  
51    @NonNull
52    IDataTypeJsonSchema getSchema(@NonNull IDataTypeAdapter<?> datatype);
53  
54    @NonNull
55    IDataTypeJsonSchema getDataTypeSchemaForDefinition(@NonNull IValuedDefinition definition);
56  
57    @NonNull
58    JsonNodeFactory getJsonNodeFactory();
59  
60    void registerDefinitionSchema(IDefinitionJsonSchema<?> schema);
61  
62    boolean isDefinitionRegistered(IDefinitionJsonSchema<?> schema);
63  }