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();
}
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();
}
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");
}
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();
}
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();
}
Aggregations