下面列出了com.fasterxml.jackson.databind.jsonFormatVisitors.JsonFormatTypes#com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static String newPatchSpecification(Integer operationNumber) {
final JsonSchemaFactory factory = new JsonSchemaFactory();
final ObjectSchema patchSchema = factory.objectSchema();
patchSchema.set$schema("http://json-schema.org/schema#");
patchSchema.setTitle("Patch");
patchSchema.putProperty("id", factory.stringSchema());
for (int i = 1; i <= operationNumber; i++) {
final ObjectSchema operation = factory.objectSchema();
operation.putProperty("op", factory.stringSchema());
operation.putProperty("path", factory.stringSchema());
operation.putProperty("value", factory.stringSchema());
patchSchema.putProperty(String.valueOf(i), operation);
}
final String schema;
try {
schema = JsonUtils.writer().writeValueAsString(patchSchema);
} catch (JsonProcessingException e) {
throw new SyndesisServerException(e);
}
return schema;
}
private SyndesisMetadata genReadToShape(ODataMetadata odataMetadata, Map<String, List<PropertyPair>> enrichedProperties) {
//
// Need to add a KEY_PREDICATE to the json schema to allow identification
// of the entity to be patched.
//
ObjectSchema entityInSchema = createEntitySchema();
entityInSchema.putProperty(KEY_PREDICATE, factory.stringSchema());
DataShape.Builder inDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.JSON_SCHEMA)
.type(entityInSchema.getTitle())
.name("Entity Properties")
.specification(serializeSpecification(entityInSchema));
ObjectSchema entityOutSchema = createEntitySchema();
populateEntitySchema(odataMetadata, entityOutSchema);
DataShape.Builder outDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.JSON_SCHEMA)
.type(entityOutSchema.getTitle());
applyEntitySchemaSpecification(entityOutSchema, outDataShapeBuilder);
return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder);
}
private SyndesisMetadata genCreateDataShape(ODataMetadata odataMetadata,
Map<String, List<PropertyPair>> enrichedProperties) {
ObjectSchema entitySchema = createEntitySchema();
populateEntitySchema(odataMetadata, entitySchema);
DataShape.Builder inDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.NONE)
.type(entitySchema.getTitle());
DataShape.Builder outDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.NONE)
.type(entitySchema.getTitle());
if (! entitySchema.getProperties().isEmpty()) {
applyEntitySchemaSpecification(entitySchema, inDataShapeBuilder);
applyEntitySchemaSpecification(entitySchema, outDataShapeBuilder);
}
return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder);
}
private SyndesisMetadata genDeleteDataShape(Map<String, List<PropertyPair>> enrichedProperties,
String actionId) {
//
// Need to add a KEY_PREDICATE to the json schema to allow identification
// of the entity to be patched.
//
ObjectSchema entitySchema = createEntitySchema();
entitySchema.putProperty(KEY_PREDICATE, factory.stringSchema());
DataShape.Builder inDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.JSON_SCHEMA)
.type(entitySchema.getTitle())
.name("Entity Properties")
.specification(serializeSpecification(entitySchema));
DataShape.Builder outDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.JSON_INSTANCE)
.description("OData " + actionId)
.name(actionId);
return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder);
}
private static Map<String, JsonSchema> checkShape(DataShape dataShape, Class<? extends ContainerTypeSchema> expectedShapeClass) throws IOException, JsonParseException, JsonMappingException {
assertNotNull(dataShape);
assertEquals(DataShapeKinds.JSON_SCHEMA, dataShape.getKind());
assertNotNull(dataShape.getSpecification());
ContainerTypeSchema schema = JsonUtils.copyObjectMapperConfiguration().readValue(
dataShape.getSpecification(), expectedShapeClass);
Map<String, JsonSchema> propSchemaMap = null;
if (schema instanceof ArraySchema) {
propSchemaMap = ((ArraySchema) schema).getItems().asSingleItems().getSchema().asObjectSchema().getProperties();
} else if (schema instanceof ObjectSchema) {
propSchemaMap = ((ObjectSchema) schema).getProperties();
}
assertNotNull(propSchemaMap);
return propSchemaMap;
}
private static void checkTestServerSchemaMap(Map<String, JsonSchema> schemaMap) {
JsonSchema descSchema = schemaMap.get("Description");
JsonSchema specSchema = schemaMap.get("Specification");
assertNotNull(descSchema);
assertNotNull(schemaMap.get("ID"));
assertNotNull(schemaMap.get("Name"));
assertNotNull(specSchema);
JsonFormatTypes descType = descSchema.getType();
assertNotNull(descType);
assertEquals(JsonFormatTypes.STRING, descType);
assertEquals(false, descSchema.getRequired());
JsonFormatTypes specType = specSchema.getType();
assertNotNull(specType);
assertEquals(JsonFormatTypes.OBJECT, specType);
assertEquals(false, specSchema.getRequired());
assertThat(specSchema).isInstanceOf(ObjectSchema.class);
ObjectSchema specObjSchema = specSchema.asObjectSchema();
assertEquals(4, specObjSchema.getProperties().size());
}
public static JsonSchema createSchema(String range, String majorDimension, boolean split, String ... columnNames) {
ObjectSchema spec = new ObjectSchema();
spec.setTitle("VALUE_RANGE");
spec.putProperty("spreadsheetId", new JsonSchemaFactory().stringSchema());
RangeCoordinate coordinate = RangeCoordinate.fromRange(range);
if (ObjectHelper.equal(RangeCoordinate.DIMENSION_ROWS, majorDimension)) {
createSchemaFromRowDimension(spec, coordinate, columnNames);
} else if (ObjectHelper.equal(RangeCoordinate.DIMENSION_COLUMNS, majorDimension)) {
createSchemaFromColumnDimension(spec, coordinate);
}
if (split) {
spec.set$schema(JSON_SCHEMA_ORG_SCHEMA);
return spec;
} else {
ArraySchema arraySpec = new ArraySchema();
arraySpec.set$schema(JSON_SCHEMA_ORG_SCHEMA);
arraySpec.setItemsSchema(spec);
return arraySpec;
}
}
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;
}
public SalesforceMetadataRetrievalTest() {
final Map<String, JsonSchema> objectProperties = new HashMap<>();
objectProperties.put("simpleProperty", new StringSchema());
objectProperties.put("anotherProperty", new NumberSchema());
final StringSchema uniqueProperty1 = new StringSchema();
uniqueProperty1.setDescription("idLookup,autoNumber");
uniqueProperty1.setTitle("Unique property 1");
final StringSchema uniqueProperty2 = new StringSchema();
uniqueProperty2.setDescription("calculated,idLookup");
uniqueProperty2.setTitle("Unique property 2");
objectProperties.put("uniqueProperty1", uniqueProperty1);
objectProperties.put("uniqueProperty2", uniqueProperty2);
final ObjectSchema objectSchema = new ObjectSchema();
objectSchema.setId("urn:jsonschema:org:apache:camel:component:salesforce:dto:SimpleObject");
objectSchema.setProperties(objectProperties);
payload = new ObjectSchema();
payload.setOneOf(Collections.singleton(objectSchema));
}
@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.getProperties()).containsKey("sObjectName");
final List<PropertyPair> values = metadata.getProperties().get("sObjectName");
assertThat(values).containsOnly(new PropertyPair("Object1", "Object1 Label"),
new PropertyPair("Object2", "Object2 Label"));
}
public static String buildFilterJsonSpecification(String filter) {
final JsonSchemaFactory factory = new JsonSchemaFactory();
final ObjectSchema builderIn = new ObjectSchema();
List<String> parameters = FilterUtil.extractParameters(filter);
builderIn.setTitle("Filter parameters");
for(String param:parameters){
builderIn.putProperty(param,factory.stringSchema());
}
String jsonSpecification = null;
try {
jsonSpecification = MAPPER.writeValueAsString(builderIn);
} catch (JsonProcessingException e) {
LOGGER.error("Issue while processing filter parameters", e);
}
return jsonSpecification;
}
static void fetchPaths(final String context, final List<String> paths, final Map<String, JsonSchema> properties) {
for (final Map.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, subschema.asObjectSchema().getProperties());
} else if (subschema.isArraySchema()) {
COLLECTION_PATHS.stream().map(p -> path + "." + p).forEach(paths::add);
ObjectSchema itemSchema = getItemSchema(subschema.asArraySchema());
if (itemSchema != null) {
fetchPaths(path + ARRAY_CONTEXT, paths, itemSchema.getProperties());
}
}
}
}
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);
}
}
}
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("}");
}
@Before
public void setUp() throws Exception {
expectedCommandSchemaString = "command-schema";
commandSchema = new ObjectSchema();
when(jsonSchemaGenerator.generateSchema(any(Class.class))).thenReturn(commandSchema);
when(objectMapper.writeValueAsString(commandSchema)).thenReturn(expectedCommandSchemaString);
testSubject = new CommandController(commandGateway, objectMapper, jsonSchemaGenerator);
testSubject.setBeanClassLoader(this.getClass().getClassLoader());
}
public HttpRequestWrapperProcessorTest() {
final ObjectSchema parameters = new ObjectSchema();
parameters.putProperty("param1", JsonSchema.minimalForFormat(JsonFormatTypes.STRING));
parameters.putProperty("param2", JsonSchema.minimalForFormat(JsonFormatTypes.STRING));
schema.putProperty("parameters", parameters);
final ObjectSchema body = new ObjectSchema();
body.putProperty("body1", JsonSchema.minimalForFormat(JsonFormatTypes.STRING));
body.putProperty("body2", JsonSchema.minimalForFormat(JsonFormatTypes.STRING));
schema.putProperty("body", body);
}
private void populateEntitySchema(ODataMetadata odataMetadata, ObjectSchema entitySchema) {
if (! odataMetadata.hasEntityProperties()) {
return;
}
for (PropertyMetadata entityProperty : odataMetadata.getEntityProperties()) {
schemaFor(entityProperty, entitySchema);
}
}
private void schemaFor(PropertyMetadata propertyMetadata, ObjectSchema parentSchema) {
JsonSchema schema;
TypeClass type = propertyMetadata.getType();
switch (type) {
case STRING:
schema = factory.stringSchema();
break;
case BOOLEAN:
schema = factory.booleanSchema();
break;
case NUMBER:
schema = factory.numberSchema();
break;
case OBJECT:
ObjectSchema objectSchema = factory.objectSchema();
Set<PropertyMetadata> childProperties = propertyMetadata.getChilldProperties();
if (childProperties != null) {
for (PropertyMetadata childProperty : childProperties) {
schemaFor(childProperty, objectSchema);
}
}
schema = objectSchema;
break;
default:
schema = factory.anySchema();
break;
}
if (propertyMetadata.isArray()) {
ArraySchema arraySchema = factory.arraySchema();
arraySchema.setItemsSchema(schema);
schema = arraySchema;
}
schema.setRequired(propertyMetadata.isRequired());
// Use #putOptionalProperty() as it does not override required flag
parentSchema.putOptionalProperty(propertyMetadata.getName(), schema);
}
private SyndesisMetadata genReadFromDataShape(ODataMetadata odataMetadata,
Map<String, Object> basicProperties,
Map<String, List<PropertyPair>> enrichedProperties) {
ObjectSchema entitySchema = createEntitySchema();
DataShape.Builder inDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.NONE);
DataShape.Builder outDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.NONE)
.type(entitySchema.getTitle());
populateEntitySchema(odataMetadata, entitySchema);
//
// If a key predicate is used then only one entity is expected to be returned
// hence an array schema is not required.
//
Object keyPredicate = ConnectorOptions.extractOption(basicProperties, KEY_PREDICATE);
boolean isSplit = isSplit(basicProperties);
if (! entitySchema.getProperties().isEmpty()) {
if (ObjectHelper.isNotEmpty(keyPredicate) || isSplit) {
//
// A split will mean that the schema is no longer an array schema
//
applyEntitySchemaSpecification(entitySchema, outDataShapeBuilder);
} else {
ArraySchema collectionSchema = new ArraySchema();
collectionSchema.set$schema(JSON_SCHEMA_URI);
collectionSchema.setItemsSchema(entitySchema);
applyEntitySchemaSpecification(collectionSchema, outDataShapeBuilder);
}
}
return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder);
}
private SyndesisMetadata genPatchDataShape(ODataMetadata odataMetadata,
Map<String, List<PropertyPair>> enrichedProperties,
String actionId) {
ObjectSchema entitySchema = createEntitySchema();
populateEntitySchema(odataMetadata, entitySchema);
//
// Need to add a KEY_PREDICATE to the json schema to allow identification
// of the entity to be patched.
//
entitySchema.putProperty(KEY_PREDICATE, factory.stringSchema());
DataShape.Builder inDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.NONE)
.type(entitySchema.getTitle())
.name("Entity Properties");
if (! entitySchema.getProperties().isEmpty()) {
applyEntitySchemaSpecification(entitySchema, inDataShapeBuilder);
}
DataShape.Builder outDataShapeBuilder = new DataShape.Builder()
.kind(DataShapeKinds.JSON_INSTANCE)
.description("OData " + actionId)
.name(actionId);
return createSyndesisMetadata(enrichedProperties, inDataShapeBuilder, outDataShapeBuilder);
}
@Test
public void testCreateMetaDataRetrieval() throws Exception {
CamelContext context = new DefaultCamelContext();
ODataMetaDataRetrieval retrieval = new ODataMetaDataRetrieval();
String resourcePath = "Products";
Map<String, Object> parameters = new HashMap<>();
parameters.put(SERVICE_URI, defaultTestServer.servicePlainUri());
parameters.put(RESOURCE_PATH, resourcePath);
String componentId = "odata";
String actionId = "io.syndesis:" + Methods.CREATE.actionIdentifierRoot();
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());
//
// The method names are important for collecting prior
// to the filling in of the integration step (values such as resource etc...)
//
List<PropertyPair> resourcePaths = properties.get(RESOURCE_PATH);
assertNotNull(resourcePaths);
assertFalse(resourcePaths.isEmpty());
PropertyPair pair = resourcePaths.get(0);
assertNotNull(pair);
assertEquals(resourcePath, pair.getValue());
//
// Both data shapes are defined after the integration step has
// been populated and should be dynamic json-schema based
// on the contents of the OData Edm metadata object.
//
checkTestServerSchemaMap(checkShape(metadata.inputShape, ObjectSchema.class));
checkTestServerSchemaMap(checkShape(metadata.outputShape, ObjectSchema.class));
}
@Test
public void testDeleteMetaDataRetrieval() throws Exception {
CamelContext context = new DefaultCamelContext();
ODataMetaDataRetrieval retrieval = new ODataMetaDataRetrieval();
String resourcePath = "Products";
Map<String, Object> parameters = new HashMap<>();
parameters.put(SERVICE_URI, defaultTestServer.servicePlainUri());
parameters.put(RESOURCE_PATH, resourcePath);
String componentId = "odata";
String actionId = "io.syndesis:" + Methods.DELETE.actionIdentifierRoot();
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());
//
// The method names are important for collecting prior
// to the filling in of the integration step (values such as resource etc...)
//
List<PropertyPair> resourcePaths = properties.get(RESOURCE_PATH);
assertNotNull(resourcePaths);
assertFalse(resourcePaths.isEmpty());
PropertyPair pair = resourcePaths.get(0);
assertNotNull(pair);
assertEquals(resourcePath, pair.getValue());
DataShape inputShape = metadata.inputShape;
Map<String, JsonSchema> schemaMap = checkShape(inputShape, ObjectSchema.class);
assertNotNull(schemaMap.get(KEY_PREDICATE));
DataShape outputShape = metadata.outputShape;
assertEquals(DataShapeKinds.JSON_INSTANCE, outputShape.getKind());
}
@Test
public void testUpdateMetaDataRetrieval() throws Exception {
CamelContext context = new DefaultCamelContext();
ODataMetaDataRetrieval retrieval = new ODataMetaDataRetrieval();
String resourcePath = "Products";
Map<String, Object> parameters = new HashMap<>();
parameters.put(SERVICE_URI, defaultTestServer.servicePlainUri());
parameters.put(RESOURCE_PATH, resourcePath);
String componentId = "odata";
String actionId = "io.syndesis:" + Methods.PATCH.actionIdentifierRoot();
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());
//
// The method names are important for collecting prior
// to the filling in of the integration step (values such as resource etc...)
//
List<PropertyPair> resourcePaths = properties.get(RESOURCE_PATH);
assertNotNull(resourcePaths);
assertFalse(resourcePaths.isEmpty());
PropertyPair pair = resourcePaths.get(0);
assertNotNull(pair);
assertEquals(resourcePath, pair.getValue());
DataShape inputShape = metadata.inputShape;
Map<String, JsonSchema> schemaMap = checkShape(inputShape, ObjectSchema.class);
checkTestServerSchemaMap(schemaMap);
assertNotNull(schemaMap.get(KEY_PREDICATE));
DataShape outputShape = metadata.outputShape;
assertEquals(DataShapeKinds.JSON_INSTANCE, outputShape.getKind());
}
@Test
public void testReadToMetaDataRetrieval() throws Exception {
CamelContext context = new DefaultCamelContext();
ODataMetaDataRetrieval retrieval = new ODataMetaDataRetrieval();
String resourcePath = "Products";
Map<String, Object> parameters = new HashMap<>();
parameters.put(SERVICE_URI, defaultTestServer.servicePlainUri());
parameters.put(RESOURCE_PATH, resourcePath);
String componentId = "odata";
String actionId = "io.syndesis:" + Methods.READ.actionIdentifierRoot() + HYPHEN + TO;
SyndesisMetadata metadata = retrieval.fetch(context, componentId, actionId, parameters);
assertNotNull(metadata);
Map<String, List<PropertyPair>> properties = metadata.getProperties();
assertFalse(properties.isEmpty());
//
// The method names are important for collecting prior
// to the filling in of the integration step (values such as resource etc...)
//
List<PropertyPair> resourcePaths = properties.get(RESOURCE_PATH);
assertNotNull(resourcePaths);
assertFalse(resourcePaths.isEmpty());
PropertyPair pair = resourcePaths.get(0);
assertNotNull(pair);
assertEquals(resourcePath, pair.getValue());
DataShape inputShape = metadata.inputShape;
Map<String, JsonSchema> schemaMap = checkShape(inputShape, ObjectSchema.class);
assertNotNull(schemaMap.get(KEY_PREDICATE));
DataShape outputShape = metadata.outputShape;
assertEquals(DataShapeKinds.JSON_SCHEMA, outputShape.getKind());
}
static ObjectSchema inputOutputSchemaFor(final Set<ObjectSchema> schemasToConsider, final String objectName) {
for (final ObjectSchema schema : schemasToConsider) {
if (schema.getId().contains(":" + objectName)) {
return adaptSchema(schema);
}
}
throw new IllegalArgumentException("Unable to find object schema for: " + objectName);
}
static PropertyPair nameAndTitlePropertyPairOf(final ObjectSchema schema) {
final String id = schema.getId();
final String objectName = id.substring(id.lastIndexOf(':') + 1);
final String objectLabel = schema.getTitle();
return new PropertyPair(objectName, objectLabel);
}
static ObjectSchema objectSchemaFrom(final ObjectSchema schema) {
if (schema.getOneOf().isEmpty()) {
return schema;
}
return (ObjectSchema) schema.getOneOf().stream().filter(ObjectSchema.class::isInstance)
.filter(SalesforceMetadataRetrieval::isObjectSchema).findFirst().orElseThrow(
() -> new IllegalStateException("The resulting schema does not contain an non query records object schema in `oneOf`"));
}
static ObjectSchema schemaPayload(final MetaData metadata) {
final Object payload = metadata.getPayload();
if (payload instanceof ObjectSchema) {
return (ObjectSchema) payload;
}
if (payload instanceof JsonNode) {
return convertSalesforceGlobalObjectJsonToSchema((JsonNode) payload);
}
throw new IllegalArgumentException("Unsupported metadata payload: " + payload);
}
@Test
public void shouldAdaptObjectMetadataForSchema() throws IOException {
final Map<String, Object> properties = new HashMap<>();
properties.put("sObjectName", "SimpleObject");
final SyndesisMetadata metadata = adapter.adapt(null, null, null, properties,
MetaDataBuilder.on(CONTEXT).withAttribute("scope", "object").withPayload(payload).build());
assertThat(metadata.inputShape).isSameAs(metadata.inputShape);
final Object oneOf = payload.getOneOf().iterator().next();
final ObjectSchema inSchema = io.syndesis.common.util.json.JsonUtils.reader().forType(ObjectSchema.class).readValue(metadata.inputShape.getSpecification() );
assertThat(inSchema).isEqualTo(oneOf);
assertThat(inSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4);
}
ObjectSchema simpleObjectSchema(final String name, final String label) {
final ObjectSchema objectSchema = new ObjectSchema();
objectSchema.setId(JsonUtils.DEFAULT_ID_PREFIX + ":" + name);
objectSchema.setTitle(label);
return objectSchema;
}