Search in sources :

Example 1 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings in project syndesis by syndesisio.

the class BaseSwaggerConnectorGenerator method info.

@Override
public final ConnectorSummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
    final SwaggerModelInfo swaggerInfo = parseSpecification(connectorSettings, true);
    try {
        // No matter if the validation fails, try to process the swagger
        final Connector connector = basicConnector(connectorTemplate, connectorSettings);
        final Map<String, Path> paths = swaggerInfo.getModel().getPaths();
        final AtomicInteger total = new AtomicInteger(0);
        final Map<String, Integer> tagCounts = // 
        paths.entrySet().stream().flatMap(// 
        p -> p.getValue().getOperations().stream()).peek(// 
        o -> total.incrementAndGet()).flatMap(// 
        o -> o.getTags().stream().distinct()).collect(// 
        Collectors.groupingBy(// 
        Function.identity(), // 
        Collectors.reducing(0, (e) -> 1, Integer::sum)));
        final ActionsSummary actionsSummary = // 
        new ActionsSummary.Builder().totalActions(// 
        total.intValue()).actionCountByTags(// 
        tagCounts).build();
        return new ConnectorSummary.Builder().createFrom(connector).actionsSummary(actionsSummary).errors(swaggerInfo.getErrors()).warnings(swaggerInfo.getWarnings()).build();
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") final Exception ex) {
        if (!swaggerInfo.getErrors().isEmpty()) {
            // Just log and return the validation errors if any
            LOG.error("An error occurred while trying to create a swagger connector", ex);
            return new ConnectorSummary.Builder().errors(swaggerInfo.getErrors()).warnings(swaggerInfo.getWarnings()).build();
        }
        throw SyndesisServerException.launderThrowable("An error occurred while trying to create a swagger connector", ex);
    }
}
Also used : Path(io.swagger.models.Path) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) SwaggerHelper(io.syndesis.server.connector.generator.swagger.util.SwaggerHelper) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) ActionComparator(io.syndesis.server.connector.generator.util.ActionComparator) Action(io.syndesis.common.model.action.Action) Swagger(io.swagger.models.Swagger) AbstractSerializableParameter(io.swagger.models.parameters.AbstractSerializableParameter) LoggerFactory(org.slf4j.LoggerFactory) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) PropertyValue(io.syndesis.common.model.connection.ConfigurationProperty.PropertyValue) Function(java.util.function.Function) ArrayList(java.util.ArrayList) RefParameter(io.swagger.models.parameters.RefParameter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Path(io.swagger.models.Path) Map(java.util.Map) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) URI(java.net.URI) Operation(io.swagger.models.Operation) JsonSchemaHelper(io.syndesis.server.connector.generator.swagger.util.JsonSchemaHelper) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) StringUtils.trimToNull(org.apache.commons.lang3.StringUtils.trimToNull) Logger(org.slf4j.Logger) BodyParameter(io.swagger.models.parameters.BodyParameter) ConnectorGenerator(io.syndesis.server.connector.generator.ConnectorGenerator) DataShape(io.syndesis.common.model.DataShape) Optional.ofNullable(java.util.Optional.ofNullable) Connector(io.syndesis.common.model.connection.Connector) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Parameter(io.swagger.models.parameters.Parameter) Collectors(java.util.stream.Collectors) Info(io.swagger.models.Info) DataShapeKinds(io.syndesis.common.model.DataShapeKinds) List(java.util.List) OperationDescription(io.syndesis.server.connector.generator.swagger.util.OperationDescription) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) Entry(java.util.Map.Entry) Optional(java.util.Optional) HttpMethod(io.swagger.models.HttpMethod) Collections(java.util.Collections) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) Connector(io.syndesis.common.model.connection.Connector) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) SyndesisServerException(io.syndesis.common.util.SyndesisServerException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings in project syndesis by syndesisio.

the class BaseSwaggerConnectorGeneratorTest method shouldProvideInfoFromPetstoreSwagger.

@Test
public void shouldProvideInfoFromPetstoreSwagger() throws IOException {
    final String specification = resource("/swagger/petstore.swagger.json");
    final ConnectorSettings connectorSettings = // 
    new ConnectorSettings.Builder().putConfiguredProperty("specification", // 
    specification).build();
    final ConnectorSummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings);
    final ActionsSummary actionsSummary = new ActionsSummary.Builder().totalActions(20).putActionCountByTag("store", 4).putActionCountByTag("user", 8).putActionCountByTag("pet", 8).build();
    final ConnectorSummary expected = // 
    new ConnectorSummary.Builder().name(// 
    "Swagger Petstore").actionsSummary(// 
    actionsSummary).build();
    assertThat(summary).isEqualToIgnoringGivenFields(expected, "icon", "description", "properties", "warnings");
    assertThat(summary.getIcon()).startsWith("data:image");
    assertThat(summary.getDescription()).startsWith("This is a sample server Petstore server");
    assertThat(summary.getProperties().keySet()).contains("host", "basePath", "authenticationType", "clientId", "clientSecret", "accessToken", "authorizationEndpoint", "specification");
}
Also used : ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Example 3 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings in project syndesis by syndesisio.

the class BaseSwaggerConnectorGeneratorTest method shouldCreateSecurityConfigurationFromReverbSwagger.

@Test
public void shouldCreateSecurityConfigurationFromReverbSwagger() throws IOException {
    final String specification = resource("/swagger/reverb.swagger.yaml");
    final ConnectorSettings connectorSettings = // 
    new ConnectorSettings.Builder().name(// 
    "Reverb API").description(// 
    "Invokes Reverb API").icon(// 
    "fa-music").putConfiguredProperty("specification", // 
    specification).build();
    final Connector generated = generator.generate(SWAGGER_TEMPLATE, connectorSettings);
    assertThat(generated.getProperties().keySet()).contains("accessToken", "authorizationEndpoint", "tokenEndpoint", "clientId", "clientSecret");
    assertThat(generated.getProperties().get("authenticationType").getEnum()).containsExactly(new ConfigurationProperty.PropertyValue.Builder().value("oauth2").label("OAuth 2.0").build());
}
Also used : ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) Connector(io.syndesis.common.model.connection.Connector) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Example 4 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings in project syndesis by syndesisio.

the class BaseSwaggerConnectorGeneratorTest method shouldReportErrorsFromInvalidPetstoreSwagger.

@Test
public void shouldReportErrorsFromInvalidPetstoreSwagger() throws IOException {
    final String specification = resource("/swagger/invalid/invalid-scheme.petstore.swagger.json");
    final ConnectorSettings connectorSettings = // 
    new ConnectorSettings.Builder().putConfiguredProperty("specification", // 
    specification).build();
    final ConnectorSummary summary = generator.info(SWAGGER_TEMPLATE, connectorSettings);
    assertThat(summary.getErrors()).hasSize(1);
    assertThat(summary.getWarnings()).isEmpty();
}
Also used : ConnectorSummary(io.syndesis.common.model.connection.ConnectorSummary) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Example 5 with ConnectorSettings

use of io.syndesis.common.model.connection.ConnectorSettings in project syndesis by syndesisio.

the class ConnectorGeneratorTest method shouldCreateBaseConnectorsWithGivenNameAndDescription.

@Test
public void shouldCreateBaseConnectorsWithGivenNameAndDescription() {
    final ConnectorSettings settings = new ConnectorSettings.Builder().name("given-name").description("given-description").putConfiguredProperty("property2", "value2").build();
    final Connector connector = generator.baseConnectorFrom(template, settings);
    // 
    assertThat(connector).isEqualToIgnoringGivenFields(// 
    new Connector.Builder().name(// 
    "given-name").description(// 
    "given-description").connectorGroup(// 
    template.getConnectorGroup()).connectorGroupId(// 
    "template-group").properties(// 
    template.getConnectorProperties()).putConfiguredProperty("property2", "value2").build(), "id", "icon");
    assertThat(connector.getIcon()).isEqualTo("data:image/svg+xml,dummy");
}
Also used : Connector(io.syndesis.common.model.connection.Connector) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Aggregations

ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)16 Test (org.junit.Test)12 Connector (io.syndesis.common.model.connection.Connector)10 ConnectorSummary (io.syndesis.common.model.connection.ConnectorSummary)7 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)3 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)3 ConnectorGenerator (io.syndesis.server.connector.generator.ConnectorGenerator)3 ApiOperation (io.swagger.annotations.ApiOperation)2 DataShape (io.syndesis.common.model.DataShape)2 ActionsSummary (io.syndesis.common.model.action.ActionsSummary)2 IOException (java.io.IOException)2 ApiResponses (io.swagger.annotations.ApiResponses)1 HttpMethod (io.swagger.models.HttpMethod)1 Info (io.swagger.models.Info)1 Operation (io.swagger.models.Operation)1 Path (io.swagger.models.Path)1 Swagger (io.swagger.models.Swagger)1 AbstractSerializableParameter (io.swagger.models.parameters.AbstractSerializableParameter)1 BodyParameter (io.swagger.models.parameters.BodyParameter)1