use of com.linkedin.data.grammar.PdlParser.TypeAssignmentContext in project rest.li by linkedin.
the class PdlSchemaParser method parseIncludes.
private FieldsAndIncludes parseIncludes(PdlParser.FieldIncludesContext includeSet) throws ParseException {
List<NamedDataSchema> includes = new ArrayList<>();
Set<NamedDataSchema> includesDeclaredInline = new HashSet<>();
List<Field> fields = new ArrayList<>();
if (includeSet != null) {
List<TypeAssignmentContext> includeTypes = includeSet.typeAssignment();
for (TypeAssignmentContext includeRef : includeTypes) {
DataSchema includedSchema = toDataSchema(includeRef);
if (includedSchema != null) {
DataSchema dereferencedIncludedSchema = includedSchema.getDereferencedDataSchema();
if (includedSchema instanceof NamedDataSchema && dereferencedIncludedSchema instanceof RecordDataSchema) {
NamedDataSchema includedNamedSchema = (NamedDataSchema) includedSchema;
RecordDataSchema dereferencedIncludedRecordSchema = (RecordDataSchema) dereferencedIncludedSchema;
fields.addAll(dereferencedIncludedRecordSchema.getFields());
includes.add(includedNamedSchema);
if (isDeclaredInline(includeRef)) {
includesDeclaredInline.add(includedNamedSchema);
}
} else {
startErrorMessage(includeRef).append("Include is not a record type or a typeref to a record type: ").append(includeRef).append(NEWLINE);
}
} else {
startErrorMessage(includeRef).append("Unable to resolve included schema: ").append(includeRef).append(NEWLINE);
}
}
}
return new FieldsAndIncludes(fields, includes, includesDeclaredInline);
}
use of com.linkedin.data.grammar.PdlParser.TypeAssignmentContext in project rest.li by linkedin.
the class PdlSchemaParser method parseUnion.
private UnionDataSchema parseUnion(UnionDeclarationContext union, boolean withinTypref) throws ParseException {
UnionDataSchema schema = new UnionDataSchema();
List<UnionMemberDeclarationContext> members = union.typeParams.members;
List<DataSchema> types = new ArrayList<>(members.size());
Set<DataSchema> typesDeclaredInline = new HashSet<>();
for (UnionMemberDeclarationContext memberDecl : members) {
TypeAssignmentContext memberType = memberDecl.member;
DataSchema dataSchema = toDataSchema(memberType);
if (dataSchema != null) {
types.add(dataSchema);
if (isDeclaredInline(memberDecl.member)) {
typesDeclaredInline.add(dataSchema);
}
}
}
schema.setTypes(types, errorMessageBuilder());
schema.setTypesDeclaredInline(typesDeclaredInline);
return schema;
}
use of com.linkedin.data.grammar.PdlParser.TypeAssignmentContext in project rest.li by linkedin.
the class PdlSchemaParser method parseMap.
private MapDataSchema parseMap(MapDeclarationContext map) throws ParseException {
TypeAssignmentContext keyType = map.typeParams.key;
TypeAssignmentContext valueType = map.typeParams.value;
MapDataSchema schema = new MapDataSchema(toDataSchema(valueType));
Map<String, Object> propsToAdd = new HashMap<String, Object>();
if (keyType.typeReference() != null) {
String typeName = keyType.typeReference().value;
if (!typeName.equals("string")) {
startErrorMessage(map).append("Unsupported map key type: ").append(typeName).append(". 'string' is the only currently supported map key type.\n");
// TODO(jbetz):
// Support typed map keys once https://github.com/linkedin/rest.li/pull/61 is accepted.
//String qualifiedKeyName = computeFullName(typeName);
//propsToAdd.put("keys", qualifiedKeyName);
}
} else if (keyType.typeDeclaration() != null) {
DataSchema keySchema = parseType(keyType.typeDeclaration());
String json = SchemaToJsonEncoder.schemaToJson(keySchema, JsonBuilder.Pretty.COMPACT);
startErrorMessage(map).append("Unsupported map key type declaration: ").append(json).append(". 'string' is the only currently supported map key type.\n");
// TODO(jbetz):
// Support typed map keys once https://github.com/linkedin/rest.li/pull/61 is accepted.
//DataMap dataMap = codec.stringToMap(json);
//propsToAdd.put("keys", dataMap);
}
schema.setProperties(propsToAdd);
schema.setValuesDeclaredInline(isDeclaredInline(valueType));
return schema;
}
Aggregations