use of com.linkedin.restli.tools.compatibility.ResourceCompatibilityChecker in project rest.li by linkedin.
the class RestLiSnapshotCompatibilityChecker method checkCompatibility.
private CompatibilityInfoMap checkCompatibility(String prevRestModelPath, String currRestModelPath, CompatibilityLevel compatLevel, boolean isAgainstRestSpec) {
final CompatibilityInfoMap infoMap = _infoMap;
if (compatLevel == CompatibilityLevel.OFF) {
// skip check entirely.
return infoMap;
}
final Stack<Object> path = new Stack<>();
path.push("");
FileInputStream prevSnapshotFile = null;
FileInputStream currSnapshotFile = null;
try {
prevSnapshotFile = new FileInputStream(prevRestModelPath);
} catch (FileNotFoundException e) {
infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestModelPath);
}
try {
currSnapshotFile = new FileInputStream(currRestModelPath);
} catch (FileNotFoundException e) {
infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestModelPath);
}
if (prevSnapshotFile == null || currSnapshotFile == null) {
return infoMap;
}
AbstractSnapshot prevSnapshot = null;
AbstractSnapshot currSnapshot = null;
try {
if (isAgainstRestSpec) {
prevSnapshot = new RestSpec(prevSnapshotFile);
} else {
prevSnapshot = new Snapshot(prevSnapshotFile);
}
currSnapshot = new Snapshot(currSnapshotFile);
} catch (IOException e) {
infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
}
if (prevSnapshot == null || currSnapshot == null) {
return infoMap;
}
final DataSchemaResolver currResolver = createResolverFromSnapshot(currSnapshot, _resolverPath);
final DataSchemaResolver prevResolver;
if (isAgainstRestSpec) {
prevResolver = currResolver;
} else {
prevResolver = createResolverFromSnapshot(prevSnapshot, _resolverPath);
}
final ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevSnapshot.getResourceSchema(), prevResolver, currSnapshot.getResourceSchema(), currResolver);
checker.check(compatLevel);
infoMap.addAll(checker.getInfoMap());
return infoMap;
}
use of com.linkedin.restli.tools.compatibility.ResourceCompatibilityChecker in project rest.li by linkedin.
the class RestLiResourceModelCompatibilityChecker method check.
/**
* Check backwards compatibility between two idl (.restspec.json) files.
*
* @param prevRestspecPath previously existing idl file
* @param currRestspecPath current idl file
* @param compatLevel compatibility level which affects the return value
* @return true if the check result conforms the compatibility level requirement
* e.g. false if backwards compatible changes are found but the level is equivalent
*/
public boolean check(String prevRestspecPath, String currRestspecPath, CompatibilityLevel compatLevel) {
_prevRestspecPath = prevRestspecPath;
_currRestspecPath = currRestspecPath;
Stack<Object> path = new Stack<>();
path.push("");
ResourceSchema prevRec = null;
ResourceSchema currRec = null;
try {
prevRec = _codec.readResourceSchema(new FileInputStream(prevRestspecPath));
} catch (FileNotFoundException e) {
_infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_NEW, path, currRestspecPath);
} catch (IOException e) {
_infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
}
try {
currRec = _codec.readResourceSchema(new FileInputStream(currRestspecPath));
} catch (FileNotFoundException e) {
_infoMap.addRestSpecInfo(CompatibilityInfo.Type.RESOURCE_MISSING, path, prevRestspecPath);
} catch (Exception e) {
_infoMap.addRestSpecInfo(CompatibilityInfo.Type.OTHER_ERROR, path, e.getMessage());
}
if (prevRec == null || currRec == null) {
return _infoMap.isCompatible(compatLevel);
}
final DataSchemaResolver resolver;
if (_resolverPath == null) {
resolver = new DefaultDataSchemaResolver();
} else {
resolver = MultiFormatDataSchemaResolver.withBuiltinFormats(_resolverPath);
}
ResourceCompatibilityChecker checker = new ResourceCompatibilityChecker(prevRec, resolver, currRec, resolver);
boolean check = checker.check(compatLevel);
_infoMap.addAll(checker.getInfoMap());
return check;
}
Aggregations