001/*
002 * SPDX-FileCopyrightText: none
003 * SPDX-License-Identifier: CC0-1.0
004 */
005
006package gov.nist.secauto.metaschema.schemagen.json;
007
008import com.fasterxml.jackson.core.JsonGenerator;
009import com.fasterxml.jackson.databind.node.JsonNodeFactory;
010
011import gov.nist.secauto.metaschema.core.datatype.IDataTypeAdapter;
012import gov.nist.secauto.metaschema.core.model.IDefinition;
013import gov.nist.secauto.metaschema.core.model.IValuedDefinition;
014import gov.nist.secauto.metaschema.schemagen.IGenerationState;
015import gov.nist.secauto.metaschema.schemagen.json.IDefineableJsonSchema.IKey;
016
017import edu.umd.cs.findbugs.annotations.NonNull;
018import edu.umd.cs.findbugs.annotations.Nullable;
019
020public interface IJsonGenerationState extends IGenerationState<JsonGenerator> {
021  /**
022   * Get the JSON schema info for the provided definition.
023   *
024   * @param <DEF>
025   *          the definition's Java type
026   * @param definition
027   *          the definition to get the schema info for
028   * @param jsonKeyFlagName
029   *          the name of the flag to use as the JSON key, or @{code null} if no
030   *          flag is used as the JSON key
031   * @param discriminatorProperty
032   *          the property name to use as the choice group discriminator,
033   *          or @{code null} if no choice group discriminator is used
034   * @param discriminatorValue
035   *          the property value to use as the choice group discriminator,
036   *          or @{code null} if no choice group discriminator is used
037   * @return the definition's schema info
038   */
039  @NonNull
040  default <DEF extends IDefinition> IDefinitionJsonSchema<DEF> getSchema(
041      @NonNull DEF definition,
042      @Nullable String jsonKeyFlagName,
043      @Nullable String discriminatorProperty,
044      @Nullable String discriminatorValue) {
045    return getSchema(IKey.of(definition, jsonKeyFlagName, discriminatorProperty, discriminatorValue));
046  }
047
048  @NonNull
049  <DEF extends IDefinition> IDefinitionJsonSchema<DEF> getSchema(@NonNull IKey key);
050
051  @NonNull
052  IDataTypeJsonSchema getSchema(@NonNull IDataTypeAdapter<?> datatype);
053
054  @NonNull
055  IDataTypeJsonSchema getDataTypeSchemaForDefinition(@NonNull IValuedDefinition definition);
056
057  @NonNull
058  JsonNodeFactory getJsonNodeFactory();
059
060  void registerDefinitionSchema(IDefinitionJsonSchema<?> schema);
061
062  boolean isDefinitionRegistered(IDefinitionJsonSchema<?> schema);
063}