Search in sources :

Example 1 with FileDataSchemaLocation

use of com.linkedin.data.schema.resolver.FileDataSchemaLocation in project rest.li by linkedin.

the class RequestBuilderSpecGenerator method generate.

public void generate(ResourceSchema resource, File sourceFile) {
    try {
        _currentSchemaLocation = new FileDataSchemaLocation(sourceFile);
        generateRootRequestBuilder(null, resource, sourceFile.getAbsolutePath(), new HashMap<>());
    } catch (IOException e) {
        throw new RuntimeException("Error processing file [" + sourceFile.getAbsolutePath() + "] " + e.getMessage(), e);
    }
}
Also used : FileDataSchemaLocation(com.linkedin.data.schema.resolver.FileDataSchemaLocation) IOException(java.io.IOException)

Example 2 with FileDataSchemaLocation

use of com.linkedin.data.schema.resolver.FileDataSchemaLocation in project rest.li by linkedin.

the class AvroSchemaGenerator method parseFile.

@Override
protected void parseFile(File schemaSourceFile) throws IOException {
    super.parseFile(schemaSourceFile);
    _sourceLocations.add(new FileDataSchemaLocation(schemaSourceFile));
}
Also used : FileDataSchemaLocation(com.linkedin.data.schema.resolver.FileDataSchemaLocation)

Example 3 with FileDataSchemaLocation

use of com.linkedin.data.schema.resolver.FileDataSchemaLocation in project rest.li by linkedin.

the class AbstractGenerator method parseSchema.

/**
 * Parse a source file to obtain the data schemas contained within.
 *
 * @param schemaSourceFile provides the source file.
 * @return the data schemas within the source file.
 * @throws IOException if there is a file access error.
 */
protected List<DataSchema> parseSchema(final File schemaSourceFile) throws IOException {
    PegasusSchemaParser parser = AbstractSchemaParser.parserForFile(schemaSourceFile, getSchemaResolver());
    FileInputStream schemaStream = new SchemaFileInputStream(schemaSourceFile);
    try {
        parser.setLocation(new FileDataSchemaLocation(schemaSourceFile));
        parser.parse(schemaStream);
        if (parser.hasError()) {
            return Collections.emptyList();
        }
        return parser.topLevelDataSchemas();
    } finally {
        schemaStream.close();
        if (parser.hasError()) {
            getMessage().append(schemaSourceFile.getPath() + ",");
            getMessage().append(parser.errorMessage());
        }
    }
}
Also used : FileDataSchemaLocation(com.linkedin.data.schema.resolver.FileDataSchemaLocation) PegasusSchemaParser(com.linkedin.data.schema.PegasusSchemaParser) FileInputStream(java.io.FileInputStream)

Aggregations

FileDataSchemaLocation (com.linkedin.data.schema.resolver.FileDataSchemaLocation)3 PegasusSchemaParser (com.linkedin.data.schema.PegasusSchemaParser)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1