Search in sources :

Example 26 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project apicurio-data-models by Apicurio.

the class AddPathItemCommand method execute.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#execute(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void execute(Document document) {
    LoggerCompat.info("[AddPathItemCommand] Executing.");
    OasDocument doc = (OasDocument) document;
    if (this.isNullOrUndefined(doc.paths)) {
        doc.paths = doc.createPaths();
        this._nullPathItems = true;
    }
    if (!this.isNullOrUndefined(doc.paths.getPathItem(this._newPathItemName))) {
        LoggerCompat.info("[AddPathItemCommand] PathItem with name %s already exists.", this._newPathItemName);
        this._pathItemExists = true;
    } else {
        OasPathItem pathItem = doc.paths.createPathItem(this._newPathItemName);
        Library.readNode(this._newPathItemObj, pathItem);
        doc.paths.addPathItem(this._newPathItemName, pathItem);
        this._pathItemExists = false;
    }
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)

Example 27 with OasPathItem

use of io.apicurio.datamodels.openapi.models.OasPathItem in project apicurio-data-models by Apicurio.

the class DeletePathCommand method undo.

/**
 * @see io.apicurio.datamodels.cmd.ICommand#undo(io.apicurio.datamodels.core.models.Document)
 */
@Override
public void undo(Document document) {
    LoggerCompat.info("[DeletePathCommand] Reverting.");
    OasDocument odoc = (OasDocument) document;
    OasPaths paths = odoc.paths;
    if (this.isNullOrUndefined(paths) || this.isNullOrUndefined(this._oldPath)) {
        return;
    }
    OasPathItem pathItem = paths.createPathItem(this._path);
    Library.readNode(this._oldPath, pathItem);
    paths.addPathItem(this._path, pathItem);
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) OasPaths(io.apicurio.datamodels.openapi.models.OasPaths) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)

Example 28 with OasPathItem

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

the class OasModelHelper method operationDescriptionOf.

public static OperationDescription operationDescriptionOf(final OasDocument openApiDoc, final OasOperation operation, final BiFunction<String, String, String> consumer) {
    final List<OasPathItem> pathItems = getPathItems(openApiDoc.paths);
    for (OasPathItem pathEntry : pathItems) {
        final String path = pathEntry.getPath();
        final Map<String, OasOperation> operations = getOperationMap(pathEntry);
        for (Map.Entry<String, OasOperation> operationEntry : operations.entrySet()) {
            if (operationEntry.getValue().equals(operation)) {
                final String method = operationEntry.getKey().toUpperCase(Locale.US);
                final String specifiedSummary = trimToNull(operation.summary);
                final String specifiedDescription = trimToNull(operation.description);
                final String name = ofNullable(toLiteralNull(specifiedSummary)).orElseGet(() -> method + " " + path);
                final String description = ofNullable(toLiteralNull(specifiedDescription)).orElseGet(() -> consumer.apply(method, path));
                return new OperationDescription(name, description);
            }
        }
    }
    throw new IllegalArgumentException(String.format("Unable to find operation '%s' in given paths in OpenAPI document", operation.operationId));
}
Also used : OasOperation(io.apicurio.datamodels.openapi.models.OasOperation) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 29 with OasPathItem

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

the class OpenApiConnectorGenerator method configureConnector.

final Connector configureConnector(final ConnectorTemplate connectorTemplate, final Connector connector, final ConnectorSettings connectorSettings) {
    final Connector.Builder builder = new Connector.Builder().createFrom(connector);
    final OpenApiModelInfo info = parseSpecification(connectorSettings, APIValidationContext.NONE);
    final OasDocument openApiDoc = info.getModel();
    addGlobalParameters(builder, info);
    final OasPaths paths = ofNullable(openApiDoc.paths).orElse(openApiDoc.createPaths());
    final String connectorId = connector.getId().orElseThrow(() -> new IllegalArgumentException("Missing connector identifier"));
    final List<ConnectorAction> actions = new ArrayList<>();
    final Map<String, Integer> operationIdCounts = new HashMap<>();
    for (final OasPathItem path : OasModelHelper.getPathItems(paths)) {
        final Map<String, OasOperation> operationMap = OasModelHelper.getOperationMap(path);
        for (final Map.Entry<String, OasOperation> entry : operationMap.entrySet()) {
            final OasOperation operation = entry.getValue();
            final String operationId = operation.operationId;
            if (operationId == null) {
                operation.operationId = operationIdGenerator.get();
            } else {
                // we tolerate that some operations might have the same
                // operationId, if that's the case we generate a unique
                // operationId by appending the count of the duplicates,
                // e.g. operation ids for non unique operation id "foo" will
                // be "foo", "foo1", "foo2", ... this will be reflected in
                // the Swagger specification stored in `specification`
                // property
                final Integer count = operationIdCounts.compute(operationId, (id, currentCount) -> ofNullable(currentCount).map(c -> ++c).orElse(0));
                if (count > 0) {
                    operation.operationId = operationId + count;
                }
            }
            final ConnectorDescriptor descriptor = createDescriptor(connectorId, info, operation);
            final OperationDescription description = OasModelHelper.operationDescriptionOf(openApiDoc, operation, (m, p) -> "Send " + m + " request to " + p);
            final ConnectorAction action = new ConnectorAction.Builder().id(createActionId(connectorId, operation)).name(description.name).description(description.description).pattern(Action.Pattern.To).descriptor(descriptor).tags(OasModelHelper.sanitizeTags(operation.tags).distinct()::iterator).build();
            actions.add(action);
        }
    }
    actions.sort(ActionComparator.INSTANCE);
    builder.addAllActions(actions);
    builder.putConfiguredProperty(SPECIFICATION, SpecificationOptimizer.minimizeForComponent(openApiDoc));
    return builder.build();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) Connector(io.syndesis.common.model.connection.Connector) OasOperation(io.apicurio.datamodels.openapi.models.OasOperation) HashMap(java.util.HashMap) OasPaths(io.apicurio.datamodels.openapi.models.OasPaths) ArrayList(java.util.ArrayList) OperationDescription(io.syndesis.server.api.generator.openapi.util.OperationDescription) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ConnectorDescriptor(io.syndesis.common.model.action.ConnectorDescriptor) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) ConnectorAction(io.syndesis.common.model.action.ConnectorAction) HashMap(java.util.HashMap) Map(java.util.Map)

Example 30 with OasPathItem

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

the class OpenApiValidationRules method validateOperationsGiven.

public OpenApiModelInfo validateOperationsGiven(final OpenApiModelInfo modelInfo) {
    final OasDocument openApiDoc = modelInfo.getModel();
    if (openApiDoc == null) {
        return modelInfo;
    }
    final OpenApiModelInfo.Builder withErrors = new OpenApiModelInfo.Builder().createFrom(modelInfo);
    final List<OasPathItem> paths = OasModelHelper.getPathItems(openApiDoc.paths);
    if (paths.isEmpty()) {
        withErrors.addError(new Violation.Builder().property("paths").error("missing-paths").message("No paths defined").build());
    } else if (paths.stream().allMatch(p -> OasModelHelper.getOperationMap(p).isEmpty())) {
        withErrors.addError(new Violation.Builder().property("").error("missing-operations").message("No operations defined").build());
    }
    return withErrors.build();
}
Also used : OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) Violation(io.syndesis.common.model.Violation) Violation(io.syndesis.common.model.Violation) Collection(java.util.Collection) OasOperation(io.apicurio.datamodels.openapi.models.OasOperation) Set(java.util.Set) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) SecurityScheme(io.apicurio.datamodels.core.models.common.SecurityScheme) OasSchema(io.apicurio.datamodels.openapi.models.OasSchema) List(java.util.List) Locale(java.util.Locale) Map(java.util.Map) OasModelHelper(io.syndesis.server.api.generator.openapi.util.OasModelHelper) Optional(java.util.Optional) URI(java.net.URI) OasDocument(io.apicurio.datamodels.openapi.models.OasDocument) OasResponse(io.apicurio.datamodels.openapi.models.OasResponse) Collections(java.util.Collections) APIValidationContext(io.syndesis.server.api.generator.APIValidationContext) OasPathItem(io.apicurio.datamodels.openapi.models.OasPathItem)

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