Search in sources :

Example 1 with ProvidedApiTemplate

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");
}
Also used : ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate) APIIntegration(io.syndesis.server.api.generator.APIIntegration) Flow(io.syndesis.common.model.integration.Flow) Test(org.junit.Test)

Example 2 with ProvidedApiTemplate

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);
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) OpenApi(io.syndesis.common.model.openapi.OpenApi) Action(io.syndesis.common.model.action.Action) KeyGenerator(io.syndesis.common.util.KeyGenerator) Step(io.syndesis.common.model.integration.Step) URL(java.net.URL) ResourceIdentifier(io.syndesis.common.model.ResourceIdentifier) Kind(io.syndesis.common.model.Kind) LoggerFactory(org.slf4j.LoggerFactory) Oas20FlowGenerator(io.syndesis.server.api.generator.openapi.v2.Oas20FlowGenerator) HashMap(java.util.HashMap) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Function(java.util.function.Function) Info(io.apicurio.datamodels.core.models.common.Info) OpenApiModelParser(io.syndesis.server.api.generator.openapi.util.OpenApiModelParser) APIIntegration(io.syndesis.server.api.generator.APIIntegration) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Locale(java.util.Locale) Map(java.util.Map) FlowMetadata(io.syndesis.common.model.integration.FlowMetadata) OasModelHelper(io.syndesis.server.api.generator.openapi.util.OasModelHelper) Integration(io.syndesis.common.model.integration.Integration) APIValidationContext(io.syndesis.server.api.generator.APIValidationContext) APISummary(io.syndesis.common.model.api.APISummary) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) Library(io.apicurio.datamodels.Library) Oas30FlowGenerator(io.syndesis.server.api.generator.openapi.v3.Oas30FlowGenerator) OasPaths(io.apicurio.datamodels.openapi.models.OasPaths) Collectors(java.util.stream.Collectors) Flow(io.syndesis.common.model.integration.Flow) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate) Optional(java.util.Optional) APIGenerator(io.syndesis.server.api.generator.APIGenerator) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) APIIntegration(io.syndesis.server.api.generator.APIIntegration) Integration(io.syndesis.common.model.integration.Integration) APIIntegration(io.syndesis.server.api.generator.APIIntegration) OpenApi(io.syndesis.common.model.openapi.OpenApi)

Example 3 with ProvidedApiTemplate

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);
}
Also used : Connector(io.syndesis.common.model.connection.Connector) Connection(io.syndesis.common.model.connection.Connection) ProvidedApiTemplate(io.syndesis.server.api.generator.ProvidedApiTemplate)

Aggregations

ProvidedApiTemplate (io.syndesis.server.api.generator.ProvidedApiTemplate)3 Flow (io.syndesis.common.model.integration.Flow)2 APIIntegration (io.syndesis.server.api.generator.APIIntegration)2 Library (io.apicurio.datamodels.Library)1 Info (io.apicurio.datamodels.core.models.common.Info)1 OasDocument (io.apicurio.datamodels.openapi.models.OasDocument)1 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)1 OasPaths (io.apicurio.datamodels.openapi.models.OasPaths)1 Kind (io.syndesis.common.model.Kind)1 ResourceIdentifier (io.syndesis.common.model.ResourceIdentifier)1 Action (io.syndesis.common.model.action.Action)1 ActionsSummary (io.syndesis.common.model.action.ActionsSummary)1 APISummary (io.syndesis.common.model.api.APISummary)1 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)1 Connection (io.syndesis.common.model.connection.Connection)1 Connector (io.syndesis.common.model.connection.Connector)1 FlowMetadata (io.syndesis.common.model.integration.FlowMetadata)1 Integration (io.syndesis.common.model.integration.Integration)1 Step (io.syndesis.common.model.integration.Step)1 OpenApi (io.syndesis.common.model.openapi.OpenApi)1