Search in sources :

Example 1 with APISummary

use of io.syndesis.common.model.api.APISummary in project syndesis by syndesisio.

the class OpenApiConnectorGenerator method info.

@Override
public final APISummary info(final ConnectorTemplate connectorTemplate, final ConnectorSettings connectorSettings) {
    final OpenApiModelInfo modelInfo = parseSpecification(connectorSettings, APIValidationContext.CONSUMED_API);
    final OasDocument model = modelInfo.getModel();
    if (model == null) {
        final APISummary.Builder summaryBuilder = new APISummary.Builder().errors(modelInfo.getErrors()).warnings(modelInfo.getWarnings());
        if (modelInfo.getResolvedSpecification() != null) {
            summaryBuilder.putConfiguredProperty(SPECIFICATION, modelInfo.getResolvedSpecification());
        }
        return summaryBuilder.build();
    }
    // No matter if the validation fails, try to process the swagger
    final Connector connector = basicConnector(connectorTemplate, connectorSettings);
    final OasPaths paths = model.paths;
    final AtomicInteger total = new AtomicInteger(0);
    final Map<String, Integer> tagCounts;
    if (paths == null) {
        tagCounts = Collections.emptyMap();
    } else {
        tagCounts = OasModelHelper.getPathItems(paths).stream().flatMap(p -> OasModelHelper.getOperationMap(p).values().stream()).peek(o -> total.incrementAndGet()).flatMap(o -> OasModelHelper.sanitizeTags(o.tags).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 APISummary.Builder.createFrom(connector).actionsSummary(actionsSummary).errors(modelInfo.getErrors()).warnings(modelInfo.getWarnings()).putAllConfiguredProperties(connectorSettings.getConfiguredProperties()).putConfiguredProperty(SPECIFICATION, modelInfo.getResolvedSpecification()).build();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) Action(io.syndesis.common.model.action.Action) SpecificationOptimizer(io.syndesis.server.api.generator.openapi.util.SpecificationOptimizer) OperationDescription(io.syndesis.server.api.generator.openapi.util.OperationDescription) HashMap(java.util.HashMap) ConfigurationProperty(io.syndesis.common.model.connection.ConfigurationProperty) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Info(io.apicurio.datamodels.core.models.common.Info) OpenApiModelParser(io.syndesis.server.api.generator.openapi.util.OpenApiModelParser) Oas20Operation(io.apicurio.datamodels.openapi.v2.models.Oas20Operation) ArrayList(java.util.ArrayList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Oas20ParameterGenerator(io.syndesis.server.api.generator.openapi.v2.Oas20ParameterGenerator) Map(java.util.Map) OasModelHelper(io.syndesis.server.api.generator.openapi.util.OasModelHelper) ConnectorTemplate(io.syndesis.common.model.connection.ConnectorTemplate) URI(java.net.URI) APIValidationContext(io.syndesis.server.api.generator.APIValidationContext) Oas20DescriptorGenerator(io.syndesis.server.api.generator.openapi.v2.Oas20DescriptorGenerator) APISummary(io.syndesis.common.model.api.APISummary) Oas30PropertyGenerators(io.syndesis.server.api.generator.openapi.v3.Oas30PropertyGenerators) Optional.ofNullable(java.util.Optional.ofNullable) Oas30ParameterGenerator(io.syndesis.server.api.generator.openapi.v3.Oas30ParameterGenerator) OasOperation(io.apicurio.datamodels.openapi.models.OasOperation) Connector(io.syndesis.common.model.connection.Connector) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) ConnectorGenerator(io.syndesis.server.api.generator.ConnectorGenerator) UUID(java.util.UUID) OasPaths(io.apicurio.datamodels.openapi.models.OasPaths) ActionComparator(io.syndesis.server.api.generator.util.ActionComparator) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) Oas30DescriptorGenerator(io.syndesis.server.api.generator.openapi.v3.Oas30DescriptorGenerator) List(java.util.List) Extension(io.apicurio.datamodels.core.models.Extension) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Optional(java.util.Optional) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) Collections(java.util.Collections) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) Oas20PropertyGenerators(io.syndesis.server.api.generator.openapi.v2.Oas20PropertyGenerators) Connector(io.syndesis.common.model.connection.Connector) OasPaths(io.apicurio.datamodels.openapi.models.OasPaths) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) APISummary(io.syndesis.common.model.api.APISummary) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 2 with APISummary

use of io.syndesis.common.model.api.APISummary in project syndesis by syndesisio.

the class OpenApiGenerator method info.

@Override
public APISummary info(final String specification, final APIValidationContext validation) {
    final OpenApiModelInfo modelInfo = OpenApiModelParser.parse(specification, validation);
    final OasDocument model = modelInfo.getModel();
    if (model == null) {
        return new APISummary.Builder().errors(modelInfo.getErrors()).warnings(modelInfo.getWarnings()).build();
    }
    final OasPaths paths = model.paths;
    final ActionsSummary actionsSummary = determineSummaryFrom(OasModelHelper.getPathItems(paths));
    final Info info = model.info;
    final String title = Optional.ofNullable(info).map(i -> i.title).orElse("unspecified");
    final String description = Optional.ofNullable(info).map(i -> i.description).orElse("unspecified");
    return // 
    new APISummary.Builder().name(// 
    title).description(// 
    description).actionsSummary(// 
    actionsSummary).errors(// 
    modelInfo.getErrors()).warnings(// 
    modelInfo.getWarnings()).putConfiguredProperty("specification", modelInfo.getResolvedSpecification()).build();
}
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) APISummary(io.syndesis.common.model.api.APISummary) OasPaths(io.apicurio.datamodels.openapi.models.OasPaths) ActionsSummary(io.syndesis.common.model.action.ActionsSummary) Info(io.apicurio.datamodels.core.models.common.Info)

Example 3 with APISummary

use of io.syndesis.common.model.api.APISummary in project syndesis by syndesisio.

the class OpenApiConnectorGeneratorTest method shouldNotProvideAuthenticationPropertiesWithMultipleSecurityDefinitionsMatching.

@Test
public void shouldNotProvideAuthenticationPropertiesWithMultipleSecurityDefinitionsMatching() {
    final Oas20Document openApiDoc = new Oas20Document();
    openApiDoc.securityDefinitions = openApiDoc.createSecurityDefinitions();
    Oas20SecurityScheme scheme1 = openApiDoc.securityDefinitions.createSecurityScheme("one");
    scheme1.in = "query";
    scheme1.type = "apiKey";
    Oas20SecurityScheme scheme2 = openApiDoc.securityDefinitions.createSecurityScheme("two");
    scheme2.in = "header";
    scheme2.type = "apiKey";
    openApiDoc.securityDefinitions.addSecurityScheme("one", scheme1);
    openApiDoc.securityDefinitions.addSecurityScheme("two", scheme2);
    final String specification = Library.writeDocumentToJSONString(openApiDoc);
    final ConnectorSettings connectorSettings = new ConnectorSettings.Builder().putConfiguredProperty("specification", specification).build();
    final APISummary summary = generator.info(ApiConnectorTemplate.SWAGGER_TEMPLATE, connectorSettings);
    assertThat(summary.getProperties().keySet()).containsOnly("authenticationType", "basePath", "host", "specification");
}
Also used : APISummary(io.syndesis.common.model.api.APISummary) Oas20Document(io.apicurio.datamodels.openapi.v2.models.Oas20Document) Oas20SecurityScheme(io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme) ConnectorSettings(io.syndesis.common.model.connection.ConnectorSettings) Test(org.junit.Test)

Example 4 with APISummary

use of io.syndesis.common.model.api.APISummary in project syndesis by syndesisio.

the class OpenApiGeneratorTest method infoShouldHandleNullPaths.

@Test
public void infoShouldHandleNullPaths() {
    final OpenApiGenerator generator = new OpenApiGenerator();
    final APISummary summary = generator.info("{\"swagger\": \"2.0\"}", APIValidationContext.NONE);
    assertThat(summary).isNotNull();
    assertThat(summary.getErrors()).isEmpty();
    assertThat(summary.getWarnings()).isEmpty();
}
Also used : APISummary(io.syndesis.common.model.api.APISummary) Test(org.junit.Test)

Example 5 with APISummary

use of io.syndesis.common.model.api.APISummary in project syndesis by syndesisio.

the class OpenApiGeneratorTest method infoShouldHandleNullSpecifications.

@Test
public void infoShouldHandleNullSpecifications() {
    final OpenApiGenerator generator = new OpenApiGenerator();
    final APISummary summary = generator.info(null, APIValidationContext.NONE);
    assertThat(summary).isNotNull();
    assertThat(summary.getErrors()).hasSize(1).allSatisfy(v -> assertThat(v.message()).startsWith("Unable to resolve OpenAPI document from"));
    assertThat(summary.getWarnings()).isEmpty();
}
Also used : APISummary(io.syndesis.common.model.api.APISummary) Test(org.junit.Test)

Aggregations

APISummary (io.syndesis.common.model.api.APISummary)18 Test (org.junit.Test)14 ConnectorSettings (io.syndesis.common.model.connection.ConnectorSettings)12 ActionsSummary (io.syndesis.common.model.action.ActionsSummary)5 ConfigurationProperty (io.syndesis.common.model.connection.ConfigurationProperty)5 Connector (io.syndesis.common.model.connection.Connector)4 ConnectorTemplate (io.syndesis.common.model.connection.ConnectorTemplate)4 ConnectorGenerator (io.syndesis.server.api.generator.ConnectorGenerator)4 List (java.util.List)4 ConnectorAction (io.syndesis.common.model.action.ConnectorAction)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 Info (io.apicurio.datamodels.core.models.common.Info)2 OasDocument (io.apicurio.datamodels.openapi.models.OasDocument)2 OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)2 OasPaths (io.apicurio.datamodels.openapi.models.OasPaths)2 Oas20Document (io.apicurio.datamodels.openapi.v2.models.Oas20Document)2 Oas20SecurityScheme (io.apicurio.datamodels.openapi.v2.models.Oas20SecurityScheme)2