
com.qdesrame.openapi.diff.compare.PathDiff Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openapi-diff Show documentation
Show all versions of openapi-diff Show documentation
Utility for comparing two OpenAPI specifications.
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