Example usage for com.fasterxml.jackson.module.jsonSchema.types ObjectSchema getProperties

List of usage examples for com.fasterxml.jackson.module.jsonSchema.types ObjectSchema getProperties

Introduction

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

Prototype

public Map<String, JsonSchema> getProperties() 

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  .  ja  v a  2s.co 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;
}

From source file:io.syndesis.inspector.JsonSchemaInspectorTest.java

@Test
public void shouldCollectPathsFromJsonSchema() throws IOException {
    final ObjectMapper mapper = new ObjectMapper();
    final ObjectSchema schema = mapper.readValue(
            JsonSchemaInspectorTest.class.getResourceAsStream("/salesforce.Contact.jsonschema"),
            ObjectSchema.class);

    final ArrayList<String> paths = new ArrayList<>();
    JsonSchemaInspector.fetchPaths(null, paths, schema.getProperties());

    assertThat(paths).contains("Id", "IsDeleted", "MasterRecordId", "AccountId", "LastName", "FirstName",
            "OtherAddress.latitude", "MailingAddress.city");
}

From source file:io.syndesis.inspector.JsonSchemaInspector.java

@Override
public List<String> getPaths(final String kind, final String type, final String specification,
        final Optional<byte[]> exemplar) {
    final ObjectSchema schema;
    try {//from w w  w. j a  va2 s. c om
        schema = MAPPER.readerFor(ObjectSchema.class).readValue(specification);
    } catch (final IOException e) {
        LOG.warn(
                "Unable to parse the given JSON schema, increase log level to DEBUG to see the schema being parsed");
        LOG.debug(specification);

        return Collections.emptyList();
    }

    final Map<String, JsonSchema> properties = schema.getProperties();

    final List<String> paths = new ArrayList<>();
    fetchPaths(null, paths, properties);

    return paths;
}