All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.qdesrame.openapi.diff.compare.PathDiff Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
package com.qdesrame.openapi.diff.compare;

import com.qdesrame.openapi.diff.model.ChangedPath;
import io.swagger.v3.oas.models.Operation;
import io.swagger.v3.oas.models.PathItem;

import java.util.List;
import java.util.Map;
import java.util.Optional;

public class PathDiff {
    private OpenApiDiff openApiDiff;

    public PathDiff(OpenApiDiff openApiDiff) {
        this.openApiDiff = openApiDiff;
    }

    public Optional diff(String pathUrl, Map pathParameters, PathItem left, PathItem right) {
        ChangedPath changedPath = new ChangedPath(pathUrl, left, right);

        Map oldOperationMap = left.readOperationsMap();
        Map newOperationMap = right.readOperationsMap();
        MapKeyDiff operationsDiff = MapKeyDiff.diff(oldOperationMap,
                newOperationMap);
        changedPath.setIncreased(operationsDiff.getIncreased());
        changedPath.setMissing(operationsDiff.getMissing());
        List sharedMethods = operationsDiff.getSharedKey();
        for (PathItem.HttpMethod method : sharedMethods) {
            Operation oldOperation = oldOperationMap.get(method);
            Operation newOperation = newOperationMap.get(method);
            openApiDiff.getOperationDiff().diff(pathUrl, method, pathParameters, oldOperation, newOperation).ifPresent(changedPath.getChanged()::add);
        }
        return changedPath.isDiff() ? Optional.of(changedPath) : Optional.empty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy