com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema Java Examples

The following examples show how to use com.fasterxml.jackson.module.jsonSchema.types.ObjectSchema. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FhirMetadataRetrieval.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: Doc.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
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("}");
}
 
Example #3
Source File: Doc.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
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);
    }
  }
}
 
Example #4
Source File: JsonSchemaInspector.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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());
            }
        }
    }
}
 
Example #5
Source File: MongoDBMetadataRetrieval.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #6
Source File: SalesforceMetadataRetrievalTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #7
Source File: SalesforceMetadataRetrievalTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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));
}
 
Example #8
Source File: SalesforceMetadataRetrieval.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: GoogleSheetsMetaDataHelper.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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;
    }
}
 
Example #10
Source File: ODataMetaDataRetrievalTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example #11
Source File: ODataMetaDataRetrievalTest.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: ODataMetaDataRetrieval.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #13
Source File: ODataMetaDataRetrieval.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #14
Source File: ODataMetaDataRetrieval.java    From syndesis with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #15
Source File: CommandControllerTest.java    From ESarch with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #16
Source File: ODataMetaDataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #17
Source File: HttpRequestWrapperProcessorTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #18
Source File: JsonSchemaInspectorTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFetchPathsWithNestedArraySchema() throws IOException {
    final ObjectSchema schema = mapper.readValue(getSchemaWithNestedArray(), ObjectSchema.class);

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

    assertThat(paths).hasSize(4);
    assertThat(paths).containsAll(Arrays.asList("Id", "PhoneNumbers.size()", "PhoneNumbers[].Name", "PhoneNumbers[].Number"));
}
 
Example #19
Source File: JsonSchemaInspectorTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldFetchPathsFromJsonSchema() throws IOException {
    final ObjectSchema schema = mapper.readValue(getSalesForceContactSchema(), ObjectSchema.class);

    final List<String> paths = new ArrayList<>();
    JsonSchemaInspector.fetchPaths(null, paths, schema.getProperties());
    assertSalesforceContactProperties(paths);
}
 
Example #20
Source File: JsonSchemaInspector.java    From syndesis with Apache License 2.0 5 votes vote down vote up
/**
 * Extract item schema from array schema. Only supports single item array schema.
 * @param arraySchema schema as array schema
 * @return the nested item schema
 */
private static ObjectSchema getItemSchema(ArraySchema arraySchema) {
    if (arraySchema.getItems().isSingleItems()) {
        return arraySchema.getItems().asSingleItems().getSchema().asObjectSchema();
    } else {
        throw new IllegalStateException("Unexpected array schema type - expected single item schema");
    }
}
 
Example #21
Source File: JsonSchemaInspector.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getPaths(final String kind, final String type, final String specification,
    final Optional<byte[]> exemplar) {
    final JsonSchema schema;
    try {
        schema = JsonSchemaUtils.reader().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", e);
        LOG.debug(specification);

        return Collections.emptyList();
    }

    String context = null;
    final List<String> paths = new ArrayList<>();
    ObjectSchema objectSchema;
    if (schema.isObjectSchema()) {
        objectSchema = schema.asObjectSchema();
    } else if (schema.isArraySchema()) {
        objectSchema = getItemSchema(schema.asArraySchema());
        // add collection specific paths
        paths.addAll(COLLECTION_PATHS);
        context = ARRAY_CONTEXT;
    } else {
        throw new IllegalStateException(String.format("Unexpected schema type %s - expected object or array schema", schema.getType()));
    }

    if (objectSchema != null) {
        final Map<String, JsonSchema> properties = objectSchema.getProperties();
        fetchPaths(context, paths, properties);
    }

    return Collections.unmodifiableList(paths);
}
 
Example #22
Source File: SalesforceMetadataRetrievalTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #23
Source File: SalesforceMetadataRetrievalTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #24
Source File: ODataMetaDataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
private void populateEntitySchema(ODataMetadata odataMetadata, ObjectSchema entitySchema) {
    if (! odataMetadata.hasEntityProperties()) {
        return;
    }

    for (PropertyMetadata entityProperty : odataMetadata.getEntityProperties()) {
        schemaFor(entityProperty, entitySchema);
    }
}
 
Example #25
Source File: SalesforceMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #26
Source File: SalesforceMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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`"));
}
 
Example #27
Source File: SalesforceMetadataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #28
Source File: ODataMetaDataRetrieval.java    From syndesis with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #29
Source File: ODataMetaDataRetrievalTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #30
Source File: ODataMetaDataRetrievalTest.java    From syndesis with Apache License 2.0 5 votes vote down vote up
@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());
}