use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.
the class SalesforceMetadataRetrieval method convertSalesforceGlobalObjectJsonToSchema.
static ObjectSchema convertSalesforceGlobalObjectJsonToSchema(final JsonNode payload) {
final Set<Object> allSchemas = new HashSet<>();
for (final JsonNode sobject : payload) {
// generate SObject schema from description
final ObjectSchema sobjectSchema = new ObjectSchema();
sobjectSchema.setId(JsonUtils.DEFAULT_ID_PREFIX + ":" + sobject.get("name").asText());
sobjectSchema.setTitle(sobject.get("label").asText());
allSchemas.add(sobjectSchema);
}
final ObjectSchema schema = new ObjectSchema();
schema.setOneOf(allSchemas);
return schema;
}
use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.
the class SalesforceMetadataRetrievalTest method shouldAdaptObjectTypesMetadataForProperties.
@Test
public void shouldAdaptObjectTypesMetadataForProperties() {
final ObjectSchema globalObjectsPayload = new ObjectSchema();
final HashSet<Object> oneOf = new HashSet<>();
oneOf.add(simpleObjectSchema("Object1", "Object1 Label"));
oneOf.add(simpleObjectSchema("Object2", "Object2 Label"));
globalObjectsPayload.setOneOf(oneOf);
final SyndesisMetadata metadata = adapter.adapt(null, null, null, NOT_USED, MetaDataBuilder.on(CONTEXT).withPayload(globalObjectsPayload).build());
assertThat(metadata.properties).containsKey("sObjectName");
final List<PropertyPair> values = metadata.properties.get("sObjectName");
assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"), new PropertyPair("Object2", "Object2 Label"));
}
use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.
the class SqlMetadataRetrieval method adaptForSql.
@SuppressWarnings({ "PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity", "PMD.ModifiedCyclomaticComplexity" })
public SyndesisMetadata adaptForSql(final String actionId, final Map<String, Object> properties, final MetaData metadata) {
final Map<String, List<PropertyPair>> enrichedProperties = new HashMap<>();
final List<PropertyPair> ppList = new ArrayList<>();
@SuppressWarnings("unchecked") final SqlStatementMetaData sqlStatementMetaData = (SqlStatementMetaData) metadata.getPayload();
if (sqlStatementMetaData != null) {
ppList.add(new PropertyPair(sqlStatementMetaData.getSqlStatement(), QUERY));
enrichedProperties.put(QUERY, ppList);
// build the input and output schemas
final ObjectSchema builderIn = new ObjectSchema();
builderIn.set$schema("http://json-schema.org/schema#");
builderIn.setTitle("SQL_PARAM_IN");
for (SqlParam inParam : sqlStatementMetaData.getInParams()) {
builderIn.putProperty(inParam.getName(), schemaFor(inParam.getJdbcType()));
}
final ObjectSchema builderOut = new ObjectSchema();
builderOut.setTitle("SQL_PARAM_OUT");
builderOut.set$schema("http://json-schema.org/schema#");
for (SqlParam outParam : sqlStatementMetaData.getOutParams()) {
builderOut.putProperty(outParam.getName(), schemaFor(outParam.getJdbcType()));
}
try {
DataShape.Builder inDataShapeBuilder = new DataShape.Builder().type(builderIn.getTitle());
if (builderIn.getProperties().isEmpty()) {
inDataShapeBuilder.kind(DataShapeKinds.NONE);
} else {
inDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA).name("SQL Parameter").description(String.format("Parameters of SQL [%s]", sqlStatementMetaData.getSqlStatement())).specification(Json.writer().writeValueAsString(builderIn));
}
DataShape.Builder outDataShapeBuilder = new DataShape.Builder().type(builderOut.getTitle());
if (builderOut.getProperties().isEmpty()) {
outDataShapeBuilder.kind(DataShapeKinds.NONE);
} else {
outDataShapeBuilder.kind(DataShapeKinds.JSON_SCHEMA).name("SQL Result").description(String.format("Result of SQL [%s]", sqlStatementMetaData.getSqlStatement())).specification(Json.writer().writeValueAsString(builderOut));
}
return new SyndesisMetadata(enrichedProperties, inDataShapeBuilder.build(), outDataShapeBuilder.build());
} catch (JsonProcessingException e) {
throw new IllegalStateException(e);
}
} else {
return new SyndesisMetadata(enrichedProperties, null, null);
}
}
use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.
the class JsonSchemaInspector method getPaths.
@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;
}
use of com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema in project syndesis by syndesisio.
the class JsonSchemaInspector method fetchPaths.
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());
}
}
}
Aggregations