use of io.syndesis.server.api.generator.APIIntegration in project syndesis by syndesisio.
the class OpenApiGeneratorTest method testEmptyOperationSummary.
@Test
public void testEmptyOperationSummary() throws IOException {
final ProvidedApiTemplate template = new ProvidedApiTemplate(dummyConnection(), "fromAction", "toAction");
final String specification = TestHelper.resource("/openapi/v2/empty-summary.json");
final OpenApiGenerator generator = new OpenApiGenerator();
final APIIntegration apiIntegration = generator.generateIntegration(specification, template);
assertThat(apiIntegration).isNotNull();
assertThat(apiIntegration.getIntegration().getFlows()).hasSize(3);
final List<Flow> flows = apiIntegration.getIntegration().getFlows();
assertThat(flows).filteredOn(operationIdEquals("operation-1")).first().hasFieldOrPropertyWithValue("description", Optional.of("GET /hi")).hasFieldOrPropertyWithValue("name", "Receiving GET request on /hi");
assertThat(flows).filteredOn(operationIdEquals("operation-2")).first().hasFieldOrPropertyWithValue("description", Optional.of("POST /hi")).hasFieldOrPropertyWithValue("name", "post operation");
assertThat(flows).filteredOn(operationIdEquals("operation-3")).first().hasFieldOrPropertyWithValue("description", Optional.of("PUT /hi")).hasFieldOrPropertyWithValue("name", "Receiving PUT request on /hi");
}
use of io.syndesis.server.api.generator.APIIntegration in project syndesis by syndesisio.
the class IntegrationSpecificationHandler method update.
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Operation(description = "For an integration that is generated from a specification updates it so it conforms to the updated specification")
@RequestBody(content = @Content(mediaType = "multipart/form-data", schema = @Schema(implementation = ApiHandler.APIFormData.class)), description = "Next revision of the specification")
public void update(@NotNull @PathParam("id") @Parameter(required = true, example = "integration-id", description = "The ID of the integration") final String id, @NotNull @MultipartForm final ApiHandler.APIFormData apiFormData) {
final Integration existing = integrationHandler.getIntegration(id);
final APIIntegration apiIntegration = ApiGeneratorHelper.generateIntegrationUpdateFrom(existing, apiFormData, dataManager, apiGenerator);
final Integration givenIntegration = apiIntegration.getIntegration();
final Integration updated = ApiGeneratorHelper.updateFlowsAndStartAndEndDataShapes(existing, givenIntegration);
final OpenApi existingApiSpecification = ApiGeneratorHelper.specificationFrom(resourceManager, existing).orElse(null);
if (Objects.equals(existing.getFlows(), updated.getFlows()) && Objects.equals(existingApiSpecification, apiIntegration.getSpec())) {
// no changes were made to the flows or to the specification
return;
}
// store the OpenAPI resource, we keep the old one as it might
// be referenced from Integration's stored in IntegrationDeployent's
// this gives us a rollback mechanism
dataManager.store(apiIntegration.getSpec(), OpenApi.class);
// perform the regular update
integrationHandler.update(id, updated);
}
use of io.syndesis.server.api.generator.APIIntegration in project syndesis by syndesisio.
the class IntegrationSpecificationHandlerTest method shouldStoreUpdatedSpecificationForNonFlowChanges.
@Test
public void shouldStoreUpdatedSpecificationForNonFlowChanges() {
final Step step = new Step.Builder().action(new ConnectorAction.Builder().descriptor(new ConnectorDescriptor.Builder().build()).build()).build();
final Integration integration = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").addSteps(step, step).build()).build();
final byte[] updatedSpecificationDocument = "updated specification".getBytes(StandardCharsets.UTF_8);
final OpenApi updatedSpecification = new OpenApi.Builder().document(updatedSpecificationDocument).build();
final APIIntegration updatedApiIntegration = new APIIntegration(integration, updatedSpecification);
when(dataManager.fetch(Connection.class, "api-provider")).thenReturn(new Connection.Builder().connectorId("api-provider-connector").build());
when(dataManager.fetch(Connector.class, "api-provider-connector")).thenReturn(new Connector.Builder().build());
when(dataManager.fetch(Integration.class, "integration-1")).thenReturn(integration);
when(encryptionSupport.encrypt(integration)).thenReturn(integration);
when(apiGenerator.generateIntegration(any(String.class), any(ProvidedApiTemplate.class))).thenReturn(updatedApiIntegration);
when(apiGenerator.updateFlowExcerpts(any(Integration.class))).then(ctx -> ctx.getArguments()[0]);
final APIFormData openApiUpdate = new APIFormData();
openApiUpdate.setSpecification(new ByteArrayInputStream(updatedSpecificationDocument));
handler.update("integration-1", openApiUpdate);
verify(dataManager).store(updatedSpecification, OpenApi.class);
verify(dataManager).update(ArgumentMatchers.<Integration>argThat(v -> {
assertThat(v).isEqualToIgnoringGivenFields(integration, "version", "updatedAt");
assertThat(v.getVersion()).isEqualTo(2);
return true;
}));
}
use of io.syndesis.server.api.generator.APIIntegration in project syndesis by syndesisio.
the class IntegrationSpecificationHandlerTest method shouldPerformUpdatesBasedOnNewSpecification.
@Test
public void shouldPerformUpdatesBasedOnNewSpecification() {
final Integration existing = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow1").build()).build();
final Integration given = new Integration.Builder().id("integration-2").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow2").build()).build();
final Integration expected = new Integration.Builder().id("integration-1").addFlow(new Flow.Builder().putMetadata(OpenApi.OPERATION_ID, "flow2").build()).build();
final OpenApi updatedSpecification = new OpenApi.Builder().build();
final APIIntegration updatedApiIntegration = new APIIntegration(given, updatedSpecification);
when(dataManager.fetch(Connection.class, "api-provider")).thenReturn(new Connection.Builder().connectorId("api-provider-connector").build());
when(dataManager.fetch(Connector.class, "api-provider-connector")).thenReturn(new Connector.Builder().build());
when(dataManager.fetch(Integration.class, "integration-1")).thenReturn(existing);
when(encryptionSupport.encrypt(expected)).thenReturn(expected);
when(apiGenerator.generateIntegration(any(String.class), any(ProvidedApiTemplate.class))).thenReturn(updatedApiIntegration);
when(apiGenerator.updateFlowExcerpts(any(Integration.class))).then(ctx -> ctx.getArguments()[0]);
final APIFormData openApiUpdate = new APIFormData();
openApiUpdate.setSpecification(new ByteArrayInputStream("updated specification".getBytes(StandardCharsets.UTF_8)));
handler.update("integration-1", openApiUpdate);
verify(dataManager).store(updatedSpecification, OpenApi.class);
verify(dataManager).update(ArgumentMatchers.<Integration>argThat(v -> {
assertThat(v).isEqualToIgnoringGivenFields(expected, "version", "updatedAt");
assertThat(v.getVersion()).isEqualTo(2);
return true;
}));
}
use of io.syndesis.server.api.generator.APIIntegration in project syndesis by syndesisio.
the class OpenApiGenerator method generateIntegration.
@Override
@SuppressWarnings({ "PMD.ExcessiveMethodLength" })
public APIIntegration generateIntegration(final String specification, final ProvidedApiTemplate template) {
final OpenApiModelInfo info = OpenApiModelParser.parse(specification, APIValidationContext.NONE);
final OasDocument openApiDoc = info.getModel();
final String name = Optional.ofNullable(openApiDoc.info).flatMap(i -> Optional.ofNullable(i.title)).orElse("Untitled");
final Integration.Builder integration = new Integration.Builder().addTag("api-provider").createdAt(System.currentTimeMillis()).name(name);
switch(info.getApiVersion()) {
case V2:
oas20FlowGenerator.generateFlows(info.getV2Model(), integration, info, template);
break;
case V3:
oas30FlowGenerator.generateFlows(info.getV3Model(), integration, info, template);
break;
default:
throw new IllegalStateException(String.format("Unable to retrieve integration flow generator for OpenAPI document type '%s'", openApiDoc.getClass()));
}
// TODO: evaluate what can be shrunk (e.g. SpecificationOptimizer#minimizeForComponent)
final byte[] updatedSpecification = Library.writeDocumentToJSONString(openApiDoc).getBytes(StandardCharsets.UTF_8);
final String apiId = KeyGenerator.createKey();
final OpenApi api = new OpenApi.Builder().id(apiId).name(name).document(updatedSpecification).putMetadata("Content-Type", getContentType(specification)).build();
integration.addResource(new ResourceIdentifier.Builder().id(apiId).kind(Kind.OpenApi).build());
return new APIIntegration(integration.build(), api);
}
Aggregations