use of com.linkedin.data.schema.grammar.PdlSchemaParser in project rest.li by linkedin.
the class TestUtil method pdlSchemaParserFromString.
public static PdlSchemaParser pdlSchemaParserFromString(String s) throws UnsupportedEncodingException {
PdlSchemaParser parser = new PdlSchemaParser(new DefaultDataSchemaResolver());
parser.parse(inputStreamFromString(s));
return parser;
}
use of com.linkedin.data.schema.grammar.PdlSchemaParser in project rest.li by linkedin.
the class PdlEncoderTest method parseSchema.
private DataSchema parseSchema(String text, String name) throws IOException {
DataSchemaResolver resolver = MultiFormatDataSchemaResolver.withBuiltinFormats(pegasusSrcDir.getAbsolutePath());
AbstractSchemaParser parser = new PdlSchemaParser(resolver);
parser.parse(text);
return extractSchema(parser, name);
}
use of com.linkedin.data.schema.grammar.PdlSchemaParser 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.grammar.PdlSchemaParser in project rest.li by linkedin.
the class ExtensionSchemaValidationCmdLineApp method parseAndValidateExtensionSchemas.
static void parseAndValidateExtensionSchemas(String resolverPath, File inputDir) throws IOException, InvalidExtensionSchemaException {
// Parse each extension schema and validate it
Iterator<File> iterator = FileUtils.iterateFiles(inputDir, new String[] { PDL }, true);
DataSchemaResolver resolver = MultiFormatDataSchemaResolver.withBuiltinFormats(resolverPath);
while (iterator.hasNext()) {
File inputFile = iterator.next();
PdlSchemaParser parser = new PdlSchemaParser(resolver);
parser.parse(new FileInputStream(inputFile));
if (parser.hasError()) {
throw new InvalidExtensionSchemaException(parser.errorMessage());
}
List<DataSchema> topLevelDataSchemas = parser.topLevelDataSchemas();
if (topLevelDataSchemas == null || topLevelDataSchemas.isEmpty() || topLevelDataSchemas.size() > 1) {
throw new InvalidExtensionSchemaException("Could not parse extension schema : " + inputFile.getAbsolutePath());
}
DataSchema topLevelDataSchema = topLevelDataSchemas.get(0);
if (!(topLevelDataSchema instanceof NamedDataSchema)) {
throw new InvalidExtensionSchemaException("Invalid extension schema : " + inputFile.getAbsolutePath() + ", the schema is not a named schema.");
}
if (!((NamedDataSchema) topLevelDataSchema).getName().endsWith(EXTENSIONS_SUFFIX)) {
throw new InvalidExtensionSchemaException("Invalid extension schema name: '" + ((NamedDataSchema) topLevelDataSchema).getName() + "'. The name of the extension schema must be <baseSchemaName> + 'Extensions'");
}
List<NamedDataSchema> includes = ((RecordDataSchema) topLevelDataSchema).getInclude();
if (includes.size() != 1) {
throw new InvalidExtensionSchemaException("The extension schema: '" + ((NamedDataSchema) topLevelDataSchema).getName() + "' should include and only include the base schema");
}
NamedDataSchema includeSchema = includes.get(0);
if (!((NamedDataSchema) topLevelDataSchema).getName().startsWith(includeSchema.getName())) {
throw new InvalidExtensionSchemaException("Invalid extension schema name: '" + ((NamedDataSchema) topLevelDataSchema).getName() + "'. The name of the extension schema must be baseSchemaName: '" + includeSchema.getName() + "' + 'Extensions");
}
List<RecordDataSchema.Field> extensionSchemaFields = ((RecordDataSchema) topLevelDataSchema).getFields().stream().filter(f -> !((RecordDataSchema) topLevelDataSchema).isFieldFromIncludes(f)).collect(Collectors.toList());
checkExtensionSchemaFields(extensionSchemaFields);
}
}
use of com.linkedin.data.schema.grammar.PdlSchemaParser 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;
}
Aggregations