use of io.syndesis.common.model.ResourceIdentifier in project syndesis by syndesisio.
the class OpenApiCustomizer method customize.
@Override
public Integration customize(IntegrationDeployment deployment, Integration integration, EnumSet<Exposure> exposure) {
IntegrationSpec.Builder spec = new IntegrationSpec.Builder();
if (integration.getSpec() != null) {
spec = spec.from(integration.getSpec());
}
// assuming that we have a single swagger definition for the moment
Optional<ResourceIdentifier> rid = deployment.getSpec().getResources().stream().filter(Kind.OpenApi::sameAs).findFirst();
if (!rid.isPresent()) {
return integration;
}
final ResourceIdentifier openApiResource = rid.get();
final Optional<String> maybeOpenApiResourceId = openApiResource.getId();
if (!maybeOpenApiResourceId.isPresent()) {
return integration;
}
final String openApiResourceId = maybeOpenApiResourceId.get();
Optional<OpenApi> res = resourceManager.loadOpenApiDefinition(openApiResourceId);
if (!res.isPresent()) {
return integration;
}
try {
spec.addResources(generateOpenAPIResource(res.get()));
spec.addSources(generateOpenAPIRestDSL(res.get()));
spec.addSources(generateOpenAPIRestEndpoint());
} catch (Exception e) {
throw new IllegalStateException(e);
}
integration.setSpec(spec.build());
return integration;
}
use of io.syndesis.common.model.ResourceIdentifier in project syndesis by syndesisio.
the class ProjectGenerator method addRestDefinition.
private void addRestDefinition(TarArchiveOutputStream tos, Integration integration) throws IOException {
// assuming that we have a single swagger definition for the moment
Optional<ResourceIdentifier> rid = integration.getResources().stream().filter(Kind.OpenApi::sameAs).findFirst();
if (!rid.isPresent()) {
return;
}
final ResourceIdentifier openApiResource = rid.get();
final Optional<String> maybeOpenApiResourceId = openApiResource.getId();
if (!maybeOpenApiResourceId.isPresent()) {
return;
}
final String openApiResourceId = maybeOpenApiResourceId.get();
Optional<OpenApi> res = resourceManager.loadOpenApiDefinition(openApiResourceId);
if (!res.isPresent()) {
return;
}
final byte[] openApiBytes = res.get().getDocument();
final Document openApiDoc = Library.readDocumentFromJSONString(new String(openApiBytes, StandardCharsets.UTF_8));
if (!(openApiDoc instanceof OasDocument)) {
throw new IllegalArgumentException(String.format("Unsupported OpenAPI document type: %s - %s", openApiDoc.getClass(), openApiDoc.getDocumentType()));
}
final StringBuilder code = new StringBuilder();
RestDslGenerator.toAppendable((OasDocument) openApiDoc).withClassName("RestRoute").withPackageName("io.syndesis.example").withoutSourceCodeTimestamps().generate(code);
addTarEntry(tos, "src/main/java/io/syndesis/example/RestRoute.java", code.toString().getBytes(StandardCharsets.UTF_8));
addTarEntry(tos, "src/main/java/io/syndesis/example/RestRouteConfiguration.java", ProjectGeneratorHelper.generate(integration, restRoutesMustache));
addTarEntry(tos, "src/main/resources/openapi.json", openApiBytes);
}
use of io.syndesis.common.model.ResourceIdentifier in project syndesis by syndesisio.
the class IntegrationSupportHandler method addResourcesToExport.
private void addResourcesToExport(final JsonDB export, final Integration integration) {
for (ResourceIdentifier resourceIdentifier : integration.getResources()) {
if (resourceIdentifier.getKind() == Kind.OpenApi) {
final Optional<OpenApi> openApiResource = resourceManager.loadOpenApiDefinition(resourceIdentifier.getId().get());
openApiResource.ifPresent(openApi -> addModelToExport(export, openApi));
}
}
}
use of io.syndesis.common.model.ResourceIdentifier in project syndesis by syndesisio.
the class ApiIntegrationUpdateITCase method shouldUpdateApiIntegrationViaApiGenerator.
@Test
public void shouldUpdateApiIntegrationViaApiGenerator() throws IOException {
final MultiValueMap<Object, Object> update = specification("/io/syndesis/server/runtime/updated-test-swagger.json");
update.add("integration", integration(existing));
final ResponseEntity<Integration> updateResponse = put("/api/v1/apis/generator", update, Integration.class, tokenRule.validToken(), HttpStatus.ACCEPTED, MULTIPART);
final Integration updated = updateResponse.getBody();
existing.getId().get();
// not present in updated-test-swagger.json
assertThat(updated.findFlowBy(operationIdEquals("fetch-task"))).isNotPresent();
// new operation added in updated-test-swagger.json
assertThat(updated.findFlowBy(operationIdEquals("count-tasks"))).isPresent();
// modified in updated-test-swagger.json
assertThat(updated.findFlowBy(operationIdEquals("create-task"))).hasValueSatisfying(flow -> {
final List<Step> steps = flow.getSteps();
assertThat(steps).hasSize(3);
assertThat(flow.findStepById("log-step")).isPresent();
final Step firstStep = steps.get(0);
final DataShape outputDataShape = firstStep.outputDataShape().get();
final String outputSpecification = outputDataShape.getSpecification();
assertThat(outputSpecification).contains("debug", "task");
});
final List<ResourceIdentifier> resources = updated.getResources();
assertThat(resources).hasSize(1);
final ResourceIdentifier openApiResource = resources.get(0);
assertThat(openApiResource.getKind()).isEqualTo(Kind.OpenApi);
final OpenApi openApi = resourceManager.loadOpenApiDefinition(openApiResource.getId().get()).get();
final String givenJson = getResourceAsText("io/syndesis/server/runtime/updated-test-swagger.json");
assertThatJson(new String(openApi.getDocument(), StandardCharsets.UTF_8)).whenIgnoringPaths("$..operationId").isEqualTo(givenJson);
}
Aggregations