Search in sources :

Example 11 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.

the class OpenApiGenerator method determineSummaryFrom.

private static ActionsSummary determineSummaryFrom(final List<OasPathItem> paths) {
    if (paths == null || paths.isEmpty()) {
        return new ActionsSummary.Builder().build();
    }
    final AtomicInteger total = new AtomicInteger(0);
    final Map<String, Integer> tagCounts = // 
    paths.stream().flatMap(// 
    p -> OasModelHelper.getOperationMap(p).values().stream()).peek(// 
    o -> total.incrementAndGet()).flatMap(// 
    o -> OasModelHelper.sanitizeTags(o.tags)).collect(// 
    Collectors.groupingBy(// 
    Function.identity(), // 
    Collectors.reducing(0, (e) -> 1, Integer::sum)));
    return // 
    new ActionsSummary.Builder().totalActions(// 
    total.intValue()).actionCountByTags(// 
    tagCounts).build();
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ActionsSummary(io.syndesis.common.model.action.ActionsSummary)

Example 12 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.

the class Oas30DataShapeGeneratorHelper method getOperationParameters.

static List<Oas30Parameter> getOperationParameters(Oas30Document openApiDoc, Oas30Operation operation) {
    final List<Oas30Parameter> operationParameters = getParameters(openApiDoc, operation);
    OasPathItem parent = ofNullable(operation.parent()).filter(OasPathItem.class::isInstance).map(OasPathItem.class::cast).orElse(null);
    final List<Oas30Parameter> pathParameters = getParameters(openApiDoc, parent);
    operationParameters.addAll(pathParameters);
    return operationParameters.stream().distinct().collect(Collectors.toList());
}
Also used : Oas30Parameter(io.apicurio.datamodels.openapi.v3.models.Oas30Parameter) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)

Example 13 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.

the class Oas20DataShapeGeneratorHelper method getOperationParameters.

static List<Oas20Parameter> getOperationParameters(Oas20Document openApiDoc, Oas20Operation operation) {
    final List<Oas20Parameter> operationParameters = Oas20ModelHelper.getParameters(operation);
    OasPathItem parent = ofNullable(operation.parent()).filter(OasPathItem.class::isInstance).map(OasPathItem.class::cast).orElse(null);
    final List<Oas20Parameter> pathParameters = Oas20ModelHelper.getParameters(parent);
    operationParameters.addAll(pathParameters);
    final List<Oas20ParameterDefinition> globalParameters = ofNullable(openApiDoc.parameters).map(Oas20ParameterDefinitions::getItems).orElse(Collections.emptyList());
    operationParameters.addAll(globalParameters);
    return operationParameters;
}
Also used : OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Oas20ParameterDefinition(io.apicurio.datamodels.openapi.v2.models.Oas20ParameterDefinition) Oas20Parameter(io.apicurio.datamodels.openapi.v2.models.Oas20Parameter)

Example 14 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.

the class Oas30ValidationRules method validateUnsupportedLinksFeature.

/**
 * OpenAPI 3.x adds links feature which is not supported at the moment. Add warning when links are specified
 * either as component or in an individual response object as all links will be ignored.
 * @param info the info holding the OpenAPI document.
 * @return info with maybe a warning added due to the unsupported feature.
 */
static OpenApiModelInfo validateUnsupportedLinksFeature(OpenApiModelInfo info) {
    if (info.getModel() == null) {
        return info;
    }
    final Oas30Document openApiDoc = info.getV3Model();
    final OpenApiModelInfo.Builder withWarnings = new OpenApiModelInfo.Builder().createFrom(info);
    if (openApiDoc.components != null && openApiDoc.components.links != null && !openApiDoc.components.links.isEmpty()) {
        withWarnings.addWarning(new Violation.Builder().error("unsupported-links-feature").message("Links component is not supported yet. This part of the OpenAPI specification will be ignored.").build());
    }
    final List<OasPathItem> paths = OasModelHelper.getPathItems(info.getModel().paths);
    for (final OasPathItem pathEntry : paths) {
        for (final Map.Entry<String, OasOperation> operationEntry : OasModelHelper.getOperationMap(pathEntry).entrySet()) {
            if (operationEntry.getValue().responses == null) {
                continue;
            }
            // Check links usage on responses
            List<Oas30Response> responses = operationEntry.getValue().responses.getResponses().stream().filter(Oas30Response.class::isInstance).map(Oas30Response.class::cast).collect(Collectors.toList());
            for (final Oas30Response responseEntry : responses) {
                if (responseEntry.links != null && !responseEntry.links.isEmpty()) {
                    final String message = "Operation " + operationEntry.getKey().toUpperCase(Locale.US) + " " + pathEntry.getPath() + " uses unsupported links feature. All links will be ignored.";
                    withWarnings.addWarning(// 
                    new Violation.Builder().property(// 
                    "").error(// 
                    "unsupported-links-feature").message(// 
                    message).build());
                }
            }
        }
    }
    return withWarnings.build();
}
Also used : Violation(io.syndesis.common.model.Violation) OasOperation(io.apicurio.datamodels.openapi.models.OasOperation) OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Map(java.util.Map) Oas30Response(io.apicurio.datamodels.openapi.v3.models.Oas30Response)

Example 15 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project syndesis by syndesisio.

the class Oas30ValidationRules method validateUnsupportedCallbacksFeature.

/**
 * OpenAPI 3.x adds callbacks feature which is not supported at the moment. Add warning when callbacks are specified
 * either as component or in an individual operation as all callbacks will be ignored.
 * @param info the info holding the OpenAPI document.
 * @return info with maybe a warning added due to the unsupported feature.
 */
static OpenApiModelInfo validateUnsupportedCallbacksFeature(OpenApiModelInfo info) {
    if (info.getModel() == null) {
        return info;
    }
    final Oas30Document openApiDoc = info.getV3Model();
    final OpenApiModelInfo.Builder withWarnings = new OpenApiModelInfo.Builder().createFrom(info);
    if (openApiDoc.components != null && openApiDoc.components.callbacks != null && !openApiDoc.components.callbacks.isEmpty()) {
        withWarnings.addWarning(new Violation.Builder().error("unsupported-callbacks-feature").message("Callbacks component is not supported yet. This part of the OpenAPI specification will be ignored.").build());
    }
    final List<OasPathItem> paths = OasModelHelper.getPathItems(info.getModel().paths);
    for (final OasPathItem pathEntry : paths) {
        for (final Map.Entry<String, Oas30Operation> operationEntry : Oas30ModelHelper.getOperationMap(pathEntry).entrySet()) {
            // Check callback usage on operation
            if (operationEntry.getValue().callbacks != null && !operationEntry.getValue().callbacks.isEmpty()) {
                final String message = "Operation " + operationEntry.getKey().toUpperCase(Locale.US) + " " + pathEntry.getPath() + " uses unsupported callbacks feature. All callbacks will be ignored.";
                withWarnings.addWarning(// 
                new Violation.Builder().property(// 
                "").error(// 
                "unsupported-callbacks-feature").message(// 
                message).build());
            }
        }
    }
    return withWarnings.build();
}
Also used : Violation(io.syndesis.common.model.Violation) Oas30Document(io.apicurio.datamodels.openapi.v3.models.Oas30Document) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) OpenApiModelInfo(io.syndesis.server.api.generator.openapi.OpenApiModelInfo) Oas30Operation(io.apicurio.datamodels.openapi.v3.models.Oas30Operation) Map(java.util.Map)

Aggregations

OasPathItem (io.apicurio.datamodels.openapi.models.OasPathItem)31 OasDocument (io.apicurio.datamodels.openapi.models.OasDocument)13 OasOperation (io.apicurio.datamodels.openapi.models.OasOperation)12 Map (java.util.Map)10 OasParameter (io.apicurio.datamodels.openapi.models.OasParameter)7 OasPaths (io.apicurio.datamodels.openapi.models.OasPaths)4 Violation (io.syndesis.common.model.Violation)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 OasResponse (io.apicurio.datamodels.openapi.models.OasResponse)3 OasSchema (io.apicurio.datamodels.openapi.models.OasSchema)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Citrus (com.consol.citrus.Citrus)2 CitrusSettings (com.consol.citrus.CitrusSettings)2 TestCaseRunner (com.consol.citrus.TestCaseRunner)2 CitrusAnnotations (com.consol.citrus.annotations.CitrusAnnotations)2 CitrusFramework (com.consol.citrus.annotations.CitrusFramework)2 CitrusResource (com.consol.citrus.annotations.CitrusResource)2