use of io.syndesis.server.api.generator.ProvidedApiTemplate 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.ProvidedApiTemplate 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);
}
use of io.syndesis.server.api.generator.ProvidedApiTemplate in project syndesis by syndesisio.
the class ApiGeneratorHelper method generateIntegrationFrom.
public static APIIntegration generateIntegrationFrom(final APIFormData apiFormData, final DataManager dataManager, final APIGenerator apiGenerator) {
Connection apiProviderConnection = dataManager.fetch(Connection.class, API_PROVIDER_CONNECTION_ID);
if (apiProviderConnection == null) {
throw new IllegalStateException("Cannot find api-provider connection with id: " + API_PROVIDER_CONNECTION_ID);
}
final String spec = getSpec(apiFormData);
if (!apiProviderConnection.getConnector().isPresent()) {
final Connector apiProviderConnector = dataManager.fetch(Connector.class, apiProviderConnection.getConnectorId());
apiProviderConnection = new Connection.Builder().createFrom(apiProviderConnection).connector(apiProviderConnector).build();
}
final ProvidedApiTemplate template = new ProvidedApiTemplate(apiProviderConnection, API_PROVIDER_START_ACTION_ID, API_PROVIDER_END_ACTION_ID);
return apiGenerator.generateIntegration(spec, template);
}
Aggregations