return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.JAVA)// .type("io.syndesis.connector.fhir.FhirReadMessageModel") .description("FHIR " + actionId) .name(actionId).build(), new DataShape.Builder().kind(DataShapeKinds.XML_SCHEMA)// .type(type) .description("FHIR " + type) .specification(specification) .name(type).build()); } else { return new SyndesisMetadata( enrichedProperties, new DataShape.Builder().kind(DataShapeKinds.XML_SCHEMA)// .type(type) .description("FHIR " + type) .specification(specification) .name(type).build(), new DataShape.Builder().kind(DataShapeKinds.JAVA)// .type("ca.uhn.fhir.rest.api.MethodOutcome") .description("FHIR " + actionId) .name(actionId).build());
.stepKind(StepKind.template) .action(new StepAction.Builder() .descriptor(new StepDescriptor.Builder() .kind(Kind.STEP) .inputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JSON_SCHEMA) .build()) .build()) .build())
public ConnectionActionHandlerTest() { salesforceOutputShape = new DataShape.Builder()// .kind(DataShapeKinds.JAVA).type("org.apache.camel.component.salesforce.api.dto.CreateSObjectResult")// .build(); salesforceContactShape = new DataShape.Builder()// .kind(DataShapeKinds.JSON_SCHEMA)// .type("Contact")// .name("Contact")// .description("Salesforce Contact")// .specification( "{\"type\":\"object\",\"id\":\"urn:jsonschema:org:apache:camel:component:salesforce:dto:Contact\",\"$schema\":\"http://json-schema.org/draft-04/schema#\",\"title\":\"Contact\"}")// .build(); .description("Unique field to hold the identifier value")// .build())) .inputDataShape(new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).build())// .outputDataShape(salesforceOutputShape).build();
return new DataShape.Builder()// .kind(DataShapeKinds.XML_SCHEMA)// .name("Request")// .description("API request payload")// .specification(xmlSchemaSet)// .build();
return new DataShape.Builder()// .kind(DataShapeKinds.XML_SCHEMA)// .name("Request")// .description("API request payload")// .specification(xmlSchemaSet)// .build();
.stepKind(StepKind.template) .action(new StepAction.Builder() .descriptor(new StepDescriptor.Builder() .kind(Kind.STEP) .inputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JSON_SCHEMA) .specification(inSpec) .build()) .outputDataShape(new DataShape.Builder() .kind(DataShapeKinds.JSON_SCHEMA) .specification(outSpec) .build()) .build()) .build())
new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA)// .type(inputOutputSchema.getTitle())// .name("Salesforce " + objectName)// .description("Salesforce " + objectName)// .specification(specification).build(), // new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA)// .type(inputOutputSchema.getTitle())// .name("Salesforce " + objectName)// .description("Salesforce " + objectName)// .specification(specification).build()); } catch (final JsonProcessingException e) { throw new IllegalStateException(e);
@Override public DataShape createShapeFromResponse(final ObjectNode json, final Swagger swagger, final Operation operation) { final Optional<Response> maybeResponse = findResponse(operation); if (!maybeResponse.isPresent()) { return DATA_SHAPE_NONE; } final Document document = DocumentHelper.createDocument(); final Element schemaSet = document.addElement("d:SchemaSet", SCHEMA_SET_NS); schemaSet.addNamespace(XmlSchemaHelper.XML_SCHEMA_PREFIX, XmlSchemaHelper.XML_SCHEMA_NS); final Map<String, SchemaPrefixAndElement> moreSchemas = new HashMap<>(); final Element bodySchema = createResponseBodySchema(swagger, operation, moreSchemas); if (bodySchema == null) { return DATA_SHAPE_NONE; } schemaSet.add(bodySchema.detach()); if (!moreSchemas.isEmpty()) { final Element additionalSchemas = schemaSet.addElement("d:AdditionalSchemas"); moreSchemas.values().forEach(e -> additionalSchemas.add(e.schema.detach())); } final String xmlSchemaSet = serialize(document); return new DataShape.Builder()// .name("Response")// .description("API response payload")// .kind(DataShapeKinds.XML_SCHEMA)// .specification(xmlSchemaSet)// .build(); }
@Override public DataShape createShapeFromResponse(final ObjectNode json, final Swagger swagger, final Operation operation) { final Optional<Response> maybeResponse = findResponse(operation); if (!maybeResponse.isPresent()) { return DATA_SHAPE_NONE; } final Document document = DocumentHelper.createDocument(); final Element schemaSet = document.addElement("d:SchemaSet", SCHEMA_SET_NS); schemaSet.addNamespace(XmlSchemaHelper.XML_SCHEMA_PREFIX, XmlSchemaHelper.XML_SCHEMA_NS); final Map<String, SchemaPrefixAndElement> moreSchemas = new HashMap<>(); final Element bodySchema = createResponseBodySchema(swagger, operation, moreSchemas); if (bodySchema == null) { return DATA_SHAPE_NONE; } schemaSet.add(bodySchema.detach()); if (!moreSchemas.isEmpty()) { final Element additionalSchemas = schemaSet.addElement("d:AdditionalSchemas"); moreSchemas.values().forEach(e -> additionalSchemas.add(e.schema.detach())); } final String xmlSchemaSet = XmlSchemaHelper.serialize(document); return new DataShape.Builder()// .name("Response")// .description("API response payload")// .kind(DataShapeKinds.XML_SCHEMA)// .specification(xmlSchemaSet)// .build(); }
@Test public void shouldAddWrapperProcessorIfSyndesisJsonSchemaGiven() throws Exception { final WebhookConnectorCustomizer customizer = new WebhookConnectorCustomizer(); customizer.setCamelContext(mock(CamelContext.class)); customizer.setOutputDataShape(new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).specification(SIMPLE_SCHEMA).build()); customizer.customize(component, Collections.emptyMap()); final Processor beforeConsumer = component.getBeforeConsumer(); assertThat(beforeConsumer).isInstanceOf(Pipeline.class); final Pipeline pipeline = (Pipeline) beforeConsumer; final Collection<Processor> processors = pipeline.getProcessors(); assertThat(processors).hasSize(2).anySatisfy(p -> assertThat(p).isInstanceOf(HttpRequestWrapperProcessor.class)); final HttpRequestWrapperProcessor wrapper = (HttpRequestWrapperProcessor) processors.stream().filter(p -> p instanceof HttpRequestWrapperProcessor) .findFirst().get(); assertThat(wrapper.getParameters()).containsOnly("source", "status"); final Processor removeHeader = processors.stream().filter(p -> !(p instanceof HttpRequestWrapperProcessor)).findFirst().get(); final Exchange exchange = mock(Exchange.class); final Message in = mock(Message.class); when(exchange.getIn()).thenReturn(in); removeHeader.process(exchange); verify(in).removeHeader(Exchange.HTTP_URI); }
private static DataShape unifiedJsonSchema(final ObjectNode bodySchema, final ObjectNode parametersSchema) { if (bodySchema == null && parametersSchema == null) { return DATA_SHAPE_NONE; } final ObjectNode unifiedSchema = JsonSchemaHelper.newJsonObjectSchema(); final ObjectNode properties = unifiedSchema.putObject("properties"); if (parametersSchema != null) { properties.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("parameters", parametersSchema.get("properties").get("parameters")); } if (bodySchema != null) { bodySchema.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("body", bodySchema); } return new DataShape.Builder()// .name("Request")// .description("API request payload")// .kind(DataShapeKinds.JSON_SCHEMA)// .specification(JsonSchemaHelper.serializeJson(unifiedSchema))// .build(); }
private static DataShape unifiedJsonSchema(final String name, final String description, final ObjectNode bodySchema, final ObjectNode parametersSchema) { if (bodySchema == null && parametersSchema == null) { return DATA_SHAPE_NONE; } final ObjectNode unifiedSchema = JsonSchemaHelper.newJsonObjectSchema(); unifiedSchema.put("$id", "io:syndesis:wrapped"); final ObjectNode properties = unifiedSchema.putObject("properties"); if (parametersSchema != null) { properties.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("parameters", parametersSchema.get("properties").get("parameters")); } if (bodySchema != null) { bodySchema.remove(PROPERTIES_TO_REMOVE_ON_MERGE); properties.set("body", bodySchema); } return new DataShape.Builder()// .name(name)// .description(description)// .kind(DataShapeKinds.JSON_SCHEMA)// .specification(JsonSchemaHelper.serializeJson(unifiedSchema))// .build(); }
@Override public DataShape createShapeFromResponse(final ObjectNode json, final Swagger swagger, final Operation operation) { final Optional<Response> maybeResponse = findResponse(operation); if (!maybeResponse.isPresent()) { return DATA_SHAPE_NONE; } final Response response = maybeResponse.get(); final Model responseSchema = response.getResponseSchema(); final String description = response.getDescription(); final JsonNode schema = createSchemaFromModel(json, description, responseSchema); String schemaString; try { schemaString = Json.writer().writeValueAsString(schema); } catch (final JsonProcessingException e) { throw new IllegalStateException("Unable to serialize given JSON specification in response schema: " + schema, e); } return new DataShape.Builder().kind(DataShapeKinds.JSON_SCHEMA).name("Response").description("API response payload") .specification(schemaString).build(); }
/** * Creates an immutable copy of a {@link DataShape} value. * Uses accessors to get values to initialize the new immutable instance. * If an instance is already immutable, it is returned as is. * @param instance The instance to copy * @return A copied immutable DataShape instance */ public static DataShape copyOf(DataShape instance) { if (instance instanceof ImmutableDataShape) { return (ImmutableDataShape) instance; } return new DataShape.Builder() .createFrom(instance) .build(); }
public static SyndesisMetadata of(DataShape dataShape) { ObjectHelper.notNull(dataShape, "DataShape"); return of( new DataShape.Builder().createFrom(dataShape).build(), new DataShape.Builder().createFrom(dataShape).build() ); }
private static DataShape dataShape(DataShapeKinds kind, String type) { return new DataShape.Builder().kind(kind).type(type).build(); } }