use of com.linkedin.data.schema.Name in project rest.li by linkedin.
the class PdlSchemaParser method parseRecord.
private RecordDataSchema parseRecord(NamedTypeDeclarationContext context, RecordDeclarationContext record) throws ParseException {
Name name = toName(record.name);
RecordDataSchema schema = new RecordDataSchema(name, RecordDataSchema.RecordType.RECORD);
bindNameToSchema(name, schema);
FieldsAndIncludes fieldsAndIncludes = parseIncludes(record.fieldIncludes());
fieldsAndIncludes.fields.addAll(parseFields(schema, record.recordDecl));
schema.setFields(fieldsAndIncludes.fields, errorMessageBuilder());
schema.setInclude(fieldsAndIncludes.includes);
schema.setIncludesDeclaredInline(fieldsAndIncludes.includesDeclaredInline);
validateDefaults(schema);
setProperties(context, schema);
return schema;
}
use of com.linkedin.data.schema.Name in project rest.li by linkedin.
the class TestTemplateSpecGenerator method testCustomInfoForUnionMembers.
@Test(dataProvider = "customTypeDataForUnion")
public void testCustomInfoForUnionMembers(final List<DataSchema> customTypedSchemas) {
final UnionDataSchema union = new UnionDataSchema();
union.setTypes(customTypedSchemas, null);
final TyperefDataSchema typeref = new TyperefDataSchema(new Name(INPUT_SCHEMA_NAME));
typeref.setReferencedType(union);
final TemplateSpecGenerator generator = new TemplateSpecGenerator(_resolver);
final UnionTemplateSpec spec = (UnionTemplateSpec) generator.generate(typeref, _location);
for (int i = 0; i < customTypedSchemas.size(); ++i) {
Assert.assertNotNull(spec.getMembers().get(i).getCustomInfo());
Assert.assertEquals(spec.getMembers().get(i).getCustomInfo().getCustomClass().getClassName(), CustomTypeUtil.getJavaCustomTypeClassNameFromSchema((TyperefDataSchema) customTypedSchemas.get(i)));
}
}
use of com.linkedin.data.schema.Name in project rest.li by linkedin.
the class TestTemplateSpecGenerator method testCustomInfoForRecordFields.
@Test(dataProvider = "customTypeDataForRecord")
public void testCustomInfoForRecordFields(final List<DataSchema> customTypedSchemas) {
final List<RecordDataSchema.Field> fields = customTypedSchemas.stream().map(RecordDataSchema.Field::new).peek(field -> field.setName("field_" + _uniqueNumberGenerator.getAndIncrement(), null)).collect(Collectors.toList());
final RecordDataSchema record = new RecordDataSchema(new Name(INPUT_SCHEMA_NAME), RecordDataSchema.RecordType.RECORD);
record.setFields(fields, null);
final TemplateSpecGenerator generator = new TemplateSpecGenerator(_resolver);
final RecordTemplateSpec spec = (RecordTemplateSpec) generator.generate(record, _location);
for (int i = 0; i < customTypedSchemas.size(); ++i) {
Assert.assertNotNull(spec.getFields().get(i).getCustomInfo());
Assert.assertEquals(spec.getFields().get(i).getCustomInfo().getCustomClass().getClassName(), CustomTypeUtil.getJavaCustomTypeClassNameFromSchema((TyperefDataSchema) customTypedSchemas.get(i)));
}
}
use of com.linkedin.data.schema.Name in project rest.li by linkedin.
the class DynamicRecordMetadata method buildSchema.
/**
* Build the schema of a {@link DynamicRecordTemplate}.
*
* @param name the name of the record.
* @param fieldDefs the fields of the record.
* @throws IllegalArgumentException if the {@link com.linkedin.data.schema.RecordDataSchema.Field} of the fieldDefs
* are already set.
*/
public static RecordDataSchema buildSchema(String name, Collection<? extends FieldDef<?>> fieldDefs) {
StringBuilder errorMessageBuilder = new StringBuilder();
RecordDataSchema schema = new RecordDataSchema(new Name(name, errorMessageBuilder), RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> fields = new ArrayList<RecordDataSchema.Field>(fieldDefs.size());
for (FieldDef<?> fieldDef : fieldDefs) {
RecordDataSchema.Field paramField = fieldDef.getField();
if (paramField.getRecord() != null) {
throw new IllegalArgumentException("Attempt to assign field " + fieldDef.getName() + " to record " + schema.getName() + "failed: " + "Record of field is already set to " + paramField.getRecord().getName());
}
paramField.setRecord(schema);
fields.add(paramField);
}
schema.setFields(fields, errorMessageBuilder);
return schema;
}
use of com.linkedin.data.schema.Name in project rest.li by linkedin.
the class BatchKVResponse method createSchema.
protected void createSchema(Class<V> valueClass) {
_valueClass = valueClass;
final StringBuilder errorMessageBuilder = new StringBuilder(10);
final Name elementSchemaName = new Name(valueClass.getSimpleName(), errorMessageBuilder);
final MapDataSchema resultsSchema = new MapDataSchema(new RecordDataSchema(elementSchemaName, RecordDataSchema.RecordType.RECORD));
final RecordDataSchema.Field resultsField = new RecordDataSchema.Field(resultsSchema);
resultsField.setName(RESULTS, errorMessageBuilder);
final Name errorSchemaName = new Name(ErrorResponse.class.getSimpleName(), errorMessageBuilder);
final MapDataSchema errorsSchema = new MapDataSchema(new RecordDataSchema(errorSchemaName, RecordDataSchema.RecordType.RECORD));
final RecordDataSchema.Field errorsField = new RecordDataSchema.Field(errorsSchema);
errorsField.setName(ERRORS, errorMessageBuilder);
final Name name = new Name(BatchKVResponse.class.getSimpleName(), errorMessageBuilder);
_schema = new RecordDataSchema(name, RecordDataSchema.RecordType.RECORD);
_schema.setFields(Arrays.asList(resultsField, errorsField), errorMessageBuilder);
}
Aggregations