@Override public void customize(ComponentProxyComponent component, Map<String, Object> options) { final List<Processor> beforeConsumers = new ArrayList<>(2); if (outputDataShape != null && outputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA && outputDataShape.getSpecification() != null) { try { final JsonNode schema = READER.readTree(outputDataShape.getSpecification()); Set<String> properties = SimpleJsonSchemaInspector.getProperties(schema); Set<String> extraneousProperties = new HashSet<>(properties); extraneousProperties.removeAll(Arrays.asList("parameters", "body")); if (!properties.isEmpty() && extraneousProperties.isEmpty()) { beforeConsumers.add(new HttpRequestWrapperProcessor(schema)); } } catch (IOException e) { throw new RuntimeCamelException(e); } } // removes all non Syndesis.* headers, this is so the headers that might // influence HTTP components in the flow after this connector don't // interpret them, for instance the `Host` header is particularly // troublesome beforeConsumers.add((e) -> e.getIn().removeHeaders("*", "Syndesis.*")); component.setBeforeConsumer(Pipeline.newInstance(context, beforeConsumers)); }
DataShape instance = (DataShape) object; if ((bits & 0x1L) == 0) { putAllMetadata(instance.getMetadata()); bits |= 0x1L; DataShapeKinds kindValue = instance.getKind(); if (kindValue != null) { kind(kindValue); String nameValue = instance.getName(); if (nameValue != null) { name(nameValue); Optional<byte[]> exemplarOptional = instance.getExemplar(); if (exemplarOptional.isPresent()) { exemplar(exemplarOptional); String descriptionValue = instance.getDescription(); if (descriptionValue != null) { description(descriptionValue); String specificationValue = instance.getSpecification(); if (specificationValue != null) { specification(specificationValue); String typeValue = instance.getType(); if (typeValue != null) { type(typeValue);
public UnmarshallProcessor(final DataShape dataShape) { if (dataShape.getKind() == DataShapeKinds.JAVA) { type = camelContext.getClassResolver().resolveClass(dataShape.getType()); if (type == null) { throw new IllegalArgumentException("The specified class for shape `" + dataShape + "` cannot be found"); } } else { type = null; } }
@Test public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException { final Operation swaggerOperation = swagger.getPaths().get(path).getOperationMap().get(operation); final DataShape shape = generator.createShapeFromRequest(json, swagger, swaggerOperation); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA); softly.assertThat(shape.getName()).isEqualTo("Request"); softly.assertThat(shape.getDescription()).isEqualTo("API request payload"); softly.assertThat(shape.getExemplar()).isNotPresent(); softly.assertAll(); final String expectedSpecification; try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/" + schemaset)) { expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8); } final String specification = shape.getSpecification(); assertThat(specification).isXmlEqualTo(expectedSpecification); }
@Override public boolean canHandle(Step step) { if (StepKind.template != step.getStepKind()) { return false; } Action action = step.getAction().orElse(null); if (action == null) { return false; } DataShape inputDataShape = action.getInputDataShape().orElse(null); if (inputDataShape == null) { return false; } return DataShapeKinds.JSON_SCHEMA == inputDataShape.getKind(); }
@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 = Json.reader().forType(ObjectSchema.class).readValue(metadata.inputShape.getSpecification() ); assertThat(inSchema).isEqualTo(oneOf); assertThat(inSchema.get$schema()).isEqualTo(JsonUtils.SCHEMA4); }
@Test public void shouldGenerateAtlasmapSchemaSetForUpdatePetRequest() throws IOException { final Operation swaggerOperation = swagger.getPaths().get(path).getOperationMap().get(operation); final DataShape shape = generator.createShapeFromRequest(json, swagger, swaggerOperation); final SoftAssertions softly = new SoftAssertions(); softly.assertThat(shape.getKind()).isEqualTo(DataShapeKinds.XML_SCHEMA); softly.assertThat(shape.getName()).isEqualTo("Request"); softly.assertThat(shape.getDescription()).isEqualTo("API request payload"); softly.assertThat(shape.getExemplar()).isNotPresent(); softly.assertAll(); final String expectedSpecification; try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/" + schemaset)) { expectedSpecification = IOUtils.toString(in, StandardCharsets.UTF_8); } final String specification = shape.getSpecification(); assertThat(specification).isXmlEqualTo(expectedSpecification); }
@Override public void customize(ComponentProxyComponent component, Map<String, Object> options) { if (inputDataShape != null && inputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA && inputDataShape.getSpecification() != null) { try { final JsonNode schema = READER.readTree(inputDataShape.getSpecification()); Set<String> properties = SimpleJsonSchemaInspector.getProperties(schema); Set<String> extraneousProperties = new HashSet<>(properties); extraneousProperties.removeAll(Arrays.asList("parameters", "body")); if (!properties.isEmpty() && extraneousProperties.isEmpty()) { component.setBeforeProducer(new HttpRequestUnwrapperProcessor(schema)); } } catch (IOException e) { throw new RuntimeCamelException(e); } } try { consumeOption(this.context, options, HTTP_RESPONSE_CODE_PROPERTY, Integer.class, code -> component.setAfterProducer(statusCodeUpdater(code)) ); } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) { throw new IllegalArgumentException(e); } }
@Override public void customize(ComponentProxyComponent component, Map<String, Object> options) { final List<Processor> beforeConsumers = new ArrayList<>(); beforeConsumers.add(e -> e.getIn().removeHeader(Exchange.HTTP_URI)); if (outputDataShape != null && outputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA && outputDataShape.getSpecification() != null) { try { final JsonNode schema = READER.readTree(outputDataShape.getSpecification()); if (Optional.of(SCHEMA_ID).equals(SimpleJsonSchemaInspector.getId(schema))) { Set<String> properties = SimpleJsonSchemaInspector.getProperties(schema); // check that the schema contains the right properties if (!properties.contains("parameters")) { throw new IllegalArgumentException("JsonSchema does not define parameters property"); } if (!properties.contains("body")) { throw new IllegalArgumentException("JsonSchema does not define body property"); } beforeConsumers.add(new HttpRequestWrapperProcessor(schema)); } } catch (IOException e) { throw new RuntimeCamelException(e); } } component.setBeforeConsumer(Pipeline.newInstance(camelContext, beforeConsumers)); // Unconditionally we remove output in 7.1 release component.setAfterConsumer(this::removeOutput); }
@Test public void shouldGenerateValidInputSchemasets() { final DataShape input = generator.createShapeFromRequest(json, swagger, operation); if (input.getKind() != DataShapeKinds.XML_SCHEMA) { return; } final String inputSpecification = input.getSpecification(); final ValidationResult result = VALIDATOR.validateInstance(source(inputSpecification)); assertThat(result.isValid())// .as("Non valid input XML schemaset was generated for specification: %s, operation: %s, errors: %s", specification, operation.getOperationId(), StreamSupport.stream(result.getProblems().spliterator(), false).map(ValidationProblem::toString)// .collect(Collectors.joining("\n")))// .isTrue(); }
@Test public void shouldGenerateValidInputSchemasets() { final DataShape input = generator.createShapeFromRequest(json, swagger, operation); if (input.getKind() != DataShapeKinds.XML_SCHEMA) { return; } final String inputSpecification = input.getSpecification(); final ValidationResult result = VALIDATOR.validateInstance(source(inputSpecification)); assertThat(result.isValid())// .as("Non valid input XML schemaset was generated for specification: %s, operation: %s, errors: %s", specification, operation.getOperationId(), StreamSupport.stream(result.getProblems().spliterator(), false).map(ValidationProblem::toString)// .collect(Collectors.joining("\n")))// .isTrue(); }
@Test public void shouldGenerateValidOutputSchemasets() throws IOException { final DataShape output = generator.createShapeFromResponse(json, swagger, operation); if (output.getKind() != DataShapeKinds.XML_SCHEMA) { return; } final Validator validator = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/atlas-xml-schemaset-model-v2.xsd")) { validator.setSchemaSource(new StreamSource(in)); final String outputSpecification = output.getSpecification(); final ValidationResult result = validator.validateInstance(source(outputSpecification)); assertThat(result.isValid())// .as("Non valid output XML schemaset was generated for specification: %s, operation: %s, errors: %s", specification, operation.getOperationId(), StreamSupport.stream(result.getProblems().spliterator(), false).map(ValidationProblem::toString)// .collect(Collectors.joining("\n")))// .isTrue(); } }
@Test public void shouldGenerateValidOutputSchemasets() throws IOException { final DataShape output = generator.createShapeFromResponse(json, swagger, operation); if (output.getKind() != DataShapeKinds.XML_SCHEMA) { return; } final Validator validator = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); try (InputStream in = UnifiedXmlDataShapeGenerator.class.getResourceAsStream("/swagger/atlas-xml-schemaset-model-v2.xsd")) { validator.setSchemaSource(new StreamSource(in)); final String outputSpecification = output.getSpecification(); final ValidationResult result = validator.validateInstance(source(outputSpecification)); assertThat(result.isValid())// .as("Non valid output XML schemaset was generated for specification: %s, operation: %s, errors: %s", specification, operation.getOperationId(), StreamSupport.stream(result.getProblems().spliterator(), false).map(ValidationProblem::toString)// .collect(Collectors.joining("\n")))// .isTrue(); } }
.isEqualToIgnoringGivenFields(expectedInputDataShape, "specification"); if (generatedInputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA) { assertThat(reformatJson(generatedInputDataShape.getSpecification())) .as("Input data shape specification for action with id: " + actionId + " differ") .isEqualTo(reformatJson(expectedInputDataShape.getSpecification())); } else { assertThat(c14Xml(generatedInputDataShape.getSpecification())) .as("Input data shape specification for action with id: " + actionId + " differ") .isEqualTo(c14Xml(expectedInputDataShape.getSpecification())); .isEqualToIgnoringGivenFields(expectedOutputDataShape, "specification"); if (generatedOutputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA) { assertThat(reformatJson(generatedOutputDataShape.getSpecification())) .as("Output data shape specification for action with id: " + actionId + " differ") .isEqualTo(reformatJson(expectedOutputDataShape.getSpecification())); } else { assertThat(c14Xml(generatedOutputDataShape.getSpecification())) .as("Output data shape specification for action with id: " + actionId + " differ") .isEqualTo(c14Xml(expectedOutputDataShape.getSpecification()));
.isEqualToIgnoringGivenFields(expectedInputDataShape, "specification"); if (generatedInputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA) { assertThat(reformatJson(generatedInputDataShape.getSpecification())) .as("Input data shape specification for action with id: " + actionId + " differ") .isEqualTo(reformatJson(expectedInputDataShape.getSpecification())); } else { assertThat(c14Xml(generatedInputDataShape.getSpecification())) .as("Input data shape specification for action with id: " + actionId + " differ") .isEqualTo(c14Xml(expectedInputDataShape.getSpecification())); .isEqualToIgnoringGivenFields(expectedOutputDataShape, "specification"); if (generatedOutputDataShape.getKind() == DataShapeKinds.JSON_SCHEMA) { assertThat(reformatJson(generatedOutputDataShape.getSpecification())) .as("Output data shape specification for action with id: " + actionId + " differ") .isEqualTo(reformatJson(expectedOutputDataShape.getSpecification())); } else { assertThat(c14Xml(generatedOutputDataShape.getSpecification())) .as("Output data shape specification for action with id: " + actionId + " differ") .isEqualTo(c14Xml(expectedOutputDataShape.getSpecification()));