@Override public List<String> getPaths(final String kind, final String type, final String specification, final Optional<byte[]> exemplar) { final ObjectSchema schema; try { 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; }
@Override public List<String> getPaths(final String kind, final String type, final String specification, final Optional<byte[]> exemplar) { final ObjectSchema schema; try { 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; }
private JsonSchema getPropertySchema(BeanProperty writer) { return ((ObjectSchema) getSchema()).getProperties().get(writer.getName()); }
private JsonSchema getPropertySchema(BeanProperty writer) { return ((ObjectSchema) getSchema()).getProperties().get(writer.getName()); }
private void objectExample(StringBuilder sb, int maxlength, String indent, JsonSchema schema, Map<String, JsonSchema> refs, Set<String> followed, Set<String> referenced, String id) { sb.append("{"); if (referenced.contains(id)) { shortId(sb, schema); } ObjectSchema os = schema.asObjectSchema(); if (os.getProperties().isEmpty()) { AdditionalProperties additionalProperties = os.getAdditionalProperties(); if (additionalProperties instanceof SchemaAdditionalProperties) { sb.append("\n").append(indent).append(" ").append("abc").append(": "); example(sb, maxlength, indent + " ", ((SchemaAdditionalProperties) additionalProperties).getJsonSchema(), refs, followed, referenced); sb.append(", ..."); } } Map<String, JsonSchema> props = new TreeMap<>(os.getProperties()); for (Entry<String, JsonSchema> entry : props.entrySet()) { sb.append("\n").append(indent).append(" ").append(entry.getKey()).append(": "); example(sb, maxlength, indent + " ", entry.getValue(), refs, followed, referenced); sb.append(","); } sb.append("\n").append(indent).append("}"); }
/* default */ static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Entry<String, JsonSchema> entry : properties.entrySet()) { final JsonSchema subschema = entry.getValue(); String path; final String key = entry.getKey(); if (context == null) { path = key; } else { path = context + "." + key; } if (subschema.isValueTypeSchema()) { paths.add(path); } else if (subschema.isObjectSchema()) { fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties()); } } }
static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) { for (final Entry<String, JsonSchema> entry : properties.entrySet()) { final JsonSchema subschema = entry.getValue(); String path; final String key = entry.getKey(); if (context == null) { path = key; } else { path = context + "." + key; } if (subschema.isValueTypeSchema()) { paths.add(path); } else if (subschema.isObjectSchema()) { fetchPaths(path, paths, ((ObjectSchema) subschema).getProperties()); } } }
@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"); }
@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"); }
enrichedProperties.put(SalesforceEndpointConfig.SOBJECT_EXT_ID_NAME, .flatMap(s -> s.getProperties().entrySet().stream()).filter(e -> isIdLookup(e.getValue()))// .map(SalesforceMetadataRetrieval::createFieldPairPropertyFromSchemaEntry).collect(Collectors.toList()));
protected boolean _equals(ObjectSchema that) { return equals(getAdditionalProperties(), that.getAdditionalProperties()) && equals(getDependencies(), that.getDependencies()) && equals(getPatternProperties(), that.getPatternProperties()) && equals(getProperties(), that.getProperties()) && super._equals(that); }
protected boolean _equals(ObjectSchema that) { return equals(getAdditionalProperties(), that.getAdditionalProperties()) && equals(getDependencies(), that.getDependencies()) && equals(getPatternProperties(), that.getPatternProperties()) && equals(getProperties(), that.getProperties()) && super._equals(that); }
private void findRefs(JsonSchema schema, Map<String, JsonSchema> refs, Set<String> referenced) { addRef(schema, refs); if (schema instanceof ReferenceSchema) { referenced.add(schema.get$ref()); } else if (schema.isArraySchema()) { ArraySchema as = schema.asArraySchema(); if (as.getItems() != null) { if (as.getItems().isSingleItems()) { findRefs(as.getItems().asSingleItems().getSchema(), refs, referenced); } else if (as.getItems().isArrayItems()) { ArrayItems items = as.getItems().asArrayItems(); for (JsonSchema item : items.getJsonSchemas()) { findRefs(item, refs, referenced); } } else { throw new UnsupportedOperationException(as.getItems().toString()); } } } else if (schema.isObjectSchema()) { ObjectSchema os = schema.asObjectSchema(); for (JsonSchema value : os.getProperties().values()) { findRefs(value, refs, referenced); } } }
for (Entry<String, JsonSchema> obj : objSchema.getProperties().entrySet()) { String key = obj.getKey(); recurseObjectAndSetField(objectClass, pObject, obj, key);
objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); primitive.setDefault(property.getDefaultValue()); objectSchema.getProperties().put(property.getName(), primitive); } else { propertySchema.set$ref("#/schemas/" + type); propertySchema.setRequired(property.getMinOccurs() > 0); objectSchema.getProperties().put(propertySchema.getTitle(), propertySchema);
objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); primitive.setDefault(property.getDefaultValue()); objectSchema.getProperties().put(property.getName(), primitive); } else { propertySchema.set$ref("#/schemas/" + type); propertySchema.setRequired(property.getMinOccurs() > 0); objectSchema.getProperties().put(propertySchema.getTitle(), propertySchema);
objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); primitive.setDefault(property.getDefaultValue()); objectSchema.getProperties().put(property.getName(), primitive); } else { propertySchema.set$ref("#/schemas/" + type); propertySchema.setRequired(property.getMinOccurs() > 0); objectSchema.getProperties().put(propertySchema.getTitle(), propertySchema);
objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); primitive.setDefault(property.getDefaultValue()); objectSchema.getProperties().put(property.getName(), primitive); } else { propertySchema.set$ref("#/schemas/" + type); propertySchema.setRequired(property.getMinOccurs() > 0); objectSchema.getProperties().put(propertySchema.getTitle(), propertySchema);
objectSchema.getProperties().put(array.getTitle(), array); } else if (isPrimitiveType(type)) { SimpleTypeSchema primitive = generatePrimitiveSchema(property); primitive.setDefault(property.getDefaultValue()); objectSchema.getProperties().put(property.getName(), primitive); } else { propertySchema.set$ref("#/schemas/" + type); propertySchema.setRequired(property.getMinOccurs() > 0); objectSchema.getProperties().put(propertySchema.getTitle(), propertySchema);