1   /*
2    * SPDX-FileCopyrightText: none
3    * SPDX-License-Identifier: CC0-1.0
4    */
5   
6   package gov.nist.secauto.metaschema.schemagen.json.impl;
7   
8   import com.fasterxml.jackson.databind.node.ObjectNode;
9   
10  import gov.nist.secauto.metaschema.core.model.IFlagDefinition;
11  import gov.nist.secauto.metaschema.schemagen.json.IDataTypeJsonSchema;
12  import gov.nist.secauto.metaschema.schemagen.json.IDefinitionJsonSchema;
13  import gov.nist.secauto.metaschema.schemagen.json.IJsonGenerationState;
14  
15  import java.util.Map;
16  
17  import edu.umd.cs.findbugs.annotations.NonNull;
18  
19  public class FlagDefinitionJsonSchema
20      extends AbstractDefinitionJsonSchema<IFlagDefinition> {
21    @NonNull
22    private final IKey key;
23  
24    public FlagDefinitionJsonSchema(@NonNull IFlagDefinition definition, @NonNull IJsonGenerationState state) {
25      super(definition);
26      this.key = IKey.of(definition);
27      state.getDataTypeSchemaForDefinition(definition);
28    }
29  
30    @Override
31    protected String generateDefinitionName(IJsonGenerationState state) {
32      return state.getTypeNameForDefinition(getDefinition(), null);
33    }
34  
35    @Override
36    protected void generateBody(
37        IJsonGenerationState state,
38        ObjectNode obj) {
39      IFlagDefinition definition = getDefinition();
40      IDataTypeJsonSchema schema = state.getDataTypeSchemaForDefinition(definition);
41      schema.generateSchemaOrRef(obj, state);
42    }
43  
44    @Override
45    public void gatherDefinitions(
46        @NonNull Map<IKey, IDefinitionJsonSchema<?>> gatheredDefinitions,
47        @NonNull IJsonGenerationState state) {
48      super.gatherDefinitions(gatheredDefinitions, state);
49  
50      IDataTypeJsonSchema schema = state.getDataTypeSchemaForDefinition(getDefinition());
51      if (schema instanceof IDefinitionJsonSchema) {
52        ((IDefinitionJsonSchema<?>) schema).gatherDefinitions(gatheredDefinitions, state);
53      }
54    }
55  
56    @Override
57    public IKey getKey() {
58      return key;
59    }
60  }