use of com.linkedin.data.schema.resolver.DefaultDataSchemaResolver in project rest.li by linkedin.
the class PegasusSchemaSnapshotCompatibilityChecker method parseSchema.
private DataSchema parseSchema(File schemaFile) throws FileNotFoundException {
PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver());
parser.parse(new FileInputStream(schemaFile));
if (parser.hasError()) {
throw new RuntimeException(parser.errorMessage() + " Error while parsing file: " + schemaFile.toString());
}
List<DataSchema> topLevelDataSchemas = parser.topLevelDataSchemas();
if (topLevelDataSchemas.size() != 1) {
throw new RuntimeException("Could not parse schema : " + schemaFile.getAbsolutePath() + " The size of top level schemas is not 1.");
}
DataSchema topLevelDataSchema = topLevelDataSchemas.get(0);
if (!(topLevelDataSchema instanceof NamedDataSchema)) {
throw new RuntimeException("Invalid schema : " + schemaFile.getAbsolutePath() + ", the schema is not a named schema.");
}
return topLevelDataSchema;
}
use of com.linkedin.data.schema.resolver.DefaultDataSchemaResolver 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;
}
use of com.linkedin.data.schema.resolver.DefaultDataSchemaResolver in project rest.li by linkedin.
the class TestUtil method pdlSchemaParserFromInputStream.
public static PdlSchemaParser pdlSchemaParserFromInputStream(InputStream is) throws UnsupportedEncodingException {
PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver());
parser.parse(is);
return parser;
}
use of com.linkedin.data.schema.resolver.DefaultDataSchemaResolver in project rest.li by linkedin.
the class TestPdlSchemaParser method testFixedParserLocations.
@Test
public void testFixedParserLocations() {
PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver(), true);
parser.parse(getClass().getResourceAsStream("TestFixedForParserContextLocations.pdl"));
List<DataSchema> topLevelSchemas = parser.topLevelDataSchemas();
Assert.assertEquals(topLevelSchemas.size(), 1, "Expected 1 top-level schema to be parsed.");
FixedDataSchema topSchema = (FixedDataSchema) topLevelSchemas.get(0);
Map<Object, PdlSchemaParser.ParseLocation> locations = parser.getParseLocations();
checkParseLocationForFixed(locations, topSchema);
}
use of com.linkedin.data.schema.resolver.DefaultDataSchemaResolver in project rest.li by linkedin.
the class SchemaTranslator method getResolver.
/**
* Allows caller to specify a file path for schema resolution.
*/
private static DataSchemaResolver getResolver(SchemaParserFactory parserFactory, AvroToDataSchemaTranslationOptions options) {
String resolverPath = options.getFileResolutionPaths();
if (resolverPath != null) {
FileDataSchemaResolver resolver = new FileDataSchemaResolver(parserFactory, resolverPath);
resolver.setExtension(AVRO_FILE_EXTENSION);
return resolver;
} else {
return new DefaultDataSchemaResolver(parserFactory);
}
}
Aggregations