Example usage for com.fasterxml.jackson.module.jsonSchema.types ArraySchema setItemsSchema

List of usage examples for com.fasterxml.jackson.module.jsonSchema.types ArraySchema setItemsSchema

Introduction

In this page you can find the example usage for com.fasterxml.jackson.module.jsonSchema.types ArraySchema setItemsSchema.

Prototype

public void setItemsSchema(JsonSchema jsonSchema) 

Source Link

Usage

From source file:com.phoenixnap.oss.ramlapisync.naming.SchemaHelper.java

private static JsonSchema extractSchemaInternal(Type clazz, Type genericType, String responseDescription,
        JavaDocStore javaDocStore, ObjectMapper m) throws JsonMappingException {
    SchemaFactoryWrapper visitor = new SchemaFactoryWrapper();
    if (genericType != null) {
        try {/*  w  w w.  j  a  va  2  s .  c  o m*/
            m.acceptJsonFormatVisitor(m.constructType(genericType), visitor);
        } catch (Exception ex) {
            logger.error("Unable to add JSON visitor for " + genericType.toString());
        }
    }
    try {
        m.acceptJsonFormatVisitor(m.constructType(clazz), visitor);
    } catch (Exception ex) {
        logger.error("Unable to add JSON visitor for " + clazz.toString());
    }

    JsonSchema jsonSchema = visitor.finalSchema();
    if (jsonSchema instanceof ObjectSchema && javaDocStore != null) {
        ObjectSchema objectSchema = (ObjectSchema) jsonSchema;
        if (objectSchema.getProperties() != null) {
            for (Entry<String, JsonSchema> cSchema : objectSchema.getProperties().entrySet()) {
                JavaDocEntry javaDocEntry = javaDocStore.getJavaDoc(cSchema.getKey());
                if (javaDocEntry != null && StringUtils.hasText(javaDocEntry.getComment())) {
                    cSchema.getValue().setDescription(javaDocEntry.getComment());
                }
            }
        }
    } else if (jsonSchema instanceof ValueTypeSchema && StringUtils.hasText(responseDescription)) {
        ValueTypeSchema valueTypeSchema = (ValueTypeSchema) jsonSchema;
        valueTypeSchema.setDescription(responseDescription);
    } else if (jsonSchema instanceof ArraySchema && genericType != null) {
        ArraySchema arraySchema = (ArraySchema) jsonSchema;
        arraySchema.setItemsSchema(extractSchemaInternal(genericType, TypeHelper.inferGenericType(genericType),
                responseDescription, javaDocStore, m));

    }
    return jsonSchema;
}