com.github.elibracha.compare.PathDiff Maven / Gradle / Ivy
package com.github.elibracha.compare;
import com.github.elibracha.model.ChangedPath;
import com.github.elibracha.model.DiffContext;
import com.github.elibracha.utils.ChangedUtils;
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(PathItem left, PathItem right, DiffContext context) {
Map oldOperationMap = left.readOperationsMap();
Map newOperationMap = right.readOperationsMap();
MapKeyDiff operationsDiff =
MapKeyDiff.diff(oldOperationMap, newOperationMap);
List sharedMethods = operationsDiff.getSharedKey();
ChangedPath changedPath =
new ChangedPath(context.getUrl(), left, right, context)
.setIncreased(operationsDiff.getIncreased())
.setMissing(operationsDiff.getMissing());
for (PathItem.HttpMethod method : sharedMethods) {
Operation oldOperation = oldOperationMap.get(method);
Operation newOperation = newOperationMap.get(method);
openApiDiff
.getOperationDiff()
.diff(oldOperation, newOperation, context.copyWithMethod(method))
.ifPresent(changedPath.getChanged()::add);
}
openApiDiff
.getExtensionsDiff()
.diff(left.getExtensions(), right.getExtensions(), context)
.ifPresent(changedPath::setExtensions);
return ChangedUtils.isChanged(changedPath);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy