Search in sources :

Example 1 with AttributeCollector

use of com.github.victools.jsonschema.generator.impl.AttributeCollector in project jsonschema-generator by victools.

the class CustomEnumDefinitionProvider method provideCustomSchemaDefinition.

@Override
public CustomDefinition provideCustomSchemaDefinition(ResolvedType javaType, SchemaGenerationContext context) {
    Object[] enumConstants = javaType.getErasedType().getEnumConstants();
    if (enumConstants == null || enumConstants.length == 0) {
        return null;
    }
    List<?> serializedJsonValues = null;
    if (this.checkForJsonValueAnnotatedMethod) {
        serializedJsonValues = this.getSerializedValuesFromJsonValue(javaType, enumConstants, context);
    }
    if (serializedJsonValues == null && this.checkForJsonPropertyAnnotations) {
        serializedJsonValues = this.getSerializedValuesFromJsonProperty(javaType, enumConstants);
    }
    if (serializedJsonValues == null) {
        return null;
    }
    ObjectNode customNode = context.getGeneratorConfig().createObjectNode().put(context.getKeyword(SchemaKeyword.TAG_TYPE), context.getKeyword(SchemaKeyword.TAG_TYPE_STRING));
    AttributeCollector standardAttributeCollector = new AttributeCollector(context.getGeneratorConfig().getObjectMapper());
    standardAttributeCollector.setEnum(customNode, serializedJsonValues, context);
    return new CustomDefinition(customNode);
}
Also used : AttributeCollector(com.github.victools.jsonschema.generator.impl.AttributeCollector) CustomDefinition(com.github.victools.jsonschema.generator.CustomDefinition) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CustomDefinition (com.github.victools.jsonschema.generator.CustomDefinition)1 AttributeCollector (com.github.victools.jsonschema.generator.impl.AttributeCollector)1