use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class TestSchemaFilter method dataSchemaFromString.
private static NamedDataSchema dataSchemaFromString(String s, boolean isAvroUnionMode) throws IOException {
SchemaParser parser = new SchemaParser();
parser.getValidationOptions().setAvroUnionMode(isAvroUnionMode);
parser.parse(TestUtil.inputStreamFromString(s));
if (parser.hasError()) {
TestUtil.out.println("ERROR: " + parser.errorMessage());
return null;
}
return (NamedDataSchema) parser.topLevelDataSchemas().get(parser.topLevelDataSchemas().size() - 1);
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class ResourceModelEncoder method buildDataSchemaType.
/*package*/
static String buildDataSchemaType(DataSchema schema) {
if (schema instanceof PrimitiveDataSchema || schema instanceof NamedDataSchema) {
return schema.getUnionMemberKey();
}
JsonBuilder builder = null;
try {
builder = new JsonBuilder(JsonBuilder.Pretty.SPACES);
final SchemaToJsonEncoder encoder = new SchemaToJsonEncoder(builder, AbstractSchemaEncoder.TypeReferenceFormat.MINIMIZE);
encoder.encode(schema);
return builder.result();
} catch (IOException e) {
throw new RestLiInternalException("could not encode schema for '" + schema.toString() + "'", e);
} finally {
if (builder != null) {
builder.closeQuietly();
}
}
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class AbstractGenerator method validateSchemaWithFilepath.
/**
* Checks that the schema name and namespace match the file name and path. These must match for
* FileDataSchemaResolver to find a schema pdscs by fully qualified name.
*
*/
private void validateSchemaWithFilepath(File schemaSourceFile, DataSchema schema) {
if (schemaSourceFile != null && schemaSourceFile.isFile() && schema instanceof NamedDataSchema) {
NamedDataSchema namedDataSchema = (NamedDataSchema) schema;
String namespace = namedDataSchema.getNamespace();
if (!FileUtil.removeFileExtension(schemaSourceFile.getName()).equalsIgnoreCase(namedDataSchema.getName())) {
throw new IllegalArgumentException(namedDataSchema.getFullName() + " has name that does not match filename '" + schemaSourceFile.getAbsolutePath() + "'");
}
String directory = schemaSourceFile.getParentFile().getAbsolutePath();
if (!directory.endsWith(namespace.replace('.', File.separatorChar))) {
throw new IllegalArgumentException(namedDataSchema.getFullName() + " has namespace that does not match " + "file path '" + schemaSourceFile.getAbsolutePath() + "'");
}
}
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class AbstractDataSchemaResolver method parse.
/**
* Read an {@link InputStream} and parse the {@link InputStream} looking for the
* specified name.
*
* @param inputStream to parse.
* @param location of the input source.
* @param name to locate.
* @param errorMessageBuilder to append error messages to.
* @return the {@link NamedDataSchema} is found in the input stream, else return null.
*/
protected NamedDataSchema parse(InputStream inputStream, final DataSchemaLocation location, String name, StringBuilder errorMessageBuilder) {
NamedDataSchema schema = null;
PegasusSchemaParser parser = _parserFactory.create(_dependencyResolver);
parser.setLocation(location);
parser.parse(new FilterInputStream(inputStream) {
@Override
public String toString() {
return location.toString();
}
});
if (parser.hasError()) {
errorMessageBuilder.append("Error parsing ").append(location).append(" for \"").append(name).append("\".\n");
errorMessageBuilder.append(parser.errorMessageBuilder());
errorMessageBuilder.append("Done parsing ").append(location).append(".\n");
_badLocations.add(location);
} else {
DataSchema found = _nameToDataSchema.get(name);
if (found != null && found instanceof NamedDataSchema) {
schema = (NamedDataSchema) found;
}
}
return schema;
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class AbstractDataSchemaResolver method bindNameToSchema.
@Override
public void bindNameToSchema(Name name, NamedDataSchema schema, DataSchemaLocation location) {
String fullName = name.getFullName();
NamedDataSchema replaced = _nameToDataSchema.put(fullName, schema);
if (replaced != null)
throw new IllegalStateException(fullName + " cannot be refined from " + replaced + " to " + schema);
_nameToDataSchemaLocations.put(fullName, location);
_resolvedLocations.add(location);
}
Aggregations