use of com.linkedin.data.schema.RecordDataSchema 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);
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestMockActionResponseFactory method testDynamicSchema.
@Test
public void testDynamicSchema() {
final RecordTemplateWithDefaultValue record = new RecordTemplateWithDefaultValue();
record.setId(42L);
record.setMessage("Lorem ipsum");
final CollectionResponse<RecordTemplateWithDefaultValue> collectionResponse = new CollectionResponse<>(RecordTemplateWithDefaultValue.class);
collectionResponse.getElements().add(record);
@SuppressWarnings("unchecked") final ActionResponse<CollectionResponse<RecordTemplateWithDefaultValue>> response = (ActionResponse<CollectionResponse<RecordTemplateWithDefaultValue>>) (Object) MockActionResponseFactory.create(CollectionResponse.class, collectionResponse.schema(), collectionResponse);
Assert.assertEquals(response.getValue(), collectionResponse);
final RecordDataSchema schema = response.schema();
Assert.assertEquals(schema.getName(), ActionResponse.class.getSimpleName());
Assert.assertEquals(schema.getField(ActionResponse.VALUE_NAME).getType(), collectionResponse.schema());
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class BatchCreateIdEntityResponse method generateSchema.
private static RecordDataSchema generateSchema() {
StringBuilder errorMessageBuilder = new StringBuilder(10);
ArrayDataSchema arraySchema = new ArrayDataSchema(new RecordDataSchema(new Name(CreateStatus.class.getSimpleName()), RecordDataSchema.RecordType.RECORD));
RecordDataSchema.Field arrayField = new RecordDataSchema.Field(arraySchema);
arrayField.setName(CollectionResponse.ELEMENTS, errorMessageBuilder);
RecordDataSchema schema = new RecordDataSchema(new Name(BatchCreateIdEntityResponse.class.getSimpleName()), RecordDataSchema.RecordType.RECORD);
schema.setFields(Arrays.asList(arrayField), errorMessageBuilder);
return schema;
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class BatchCreateIdResponse method generateSchema.
private static RecordDataSchema generateSchema() {
StringBuilder errorMessageBuilder = new StringBuilder(10);
ArrayDataSchema arraySchema = new ArrayDataSchema(new RecordDataSchema(new Name(CreateStatus.class.getSimpleName()), RecordDataSchema.RecordType.RECORD));
RecordDataSchema.Field arrayField = new RecordDataSchema.Field(arraySchema);
arrayField.setName(CollectionResponse.ELEMENTS, errorMessageBuilder);
RecordDataSchema schema = new RecordDataSchema(new Name(BatchCreateIdResponse.class.getSimpleName()), RecordDataSchema.RecordType.RECORD);
schema.setFields(Arrays.asList(arrayField), errorMessageBuilder);
return schema;
}
use of com.linkedin.data.schema.RecordDataSchema in project rest.li by linkedin.
the class TestResourceCompatibilityChecker method bindSchemaResolvers.
/**
* Constructs "previous", "current-compatible", and "current-incompatible" schemas and binds them to their respective
* schema resolvers.
* TODO: This should be refactored to use schemas defined in the resources directory so that it's easier to extend.
*/
private void bindSchemaResolvers() {
StringBuilder errors = new StringBuilder();
Name toneName = new Name("com.linkedin.greetings.api.Tone");
EnumDataSchema tone = new EnumDataSchema(toneName);
List<String> symbols = new ArrayList<>();
symbols.add("FRIENDLY");
symbols.add("SINCERE");
symbols.add("INSULTING");
tone.setSymbols(symbols, errors);
Name greetingName = new Name("com.linkedin.greetings.api.Greeting");
RecordDataSchema prevGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> oldFields = new ArrayList<>();
RecordDataSchema.Field id = new RecordDataSchema.Field(new LongDataSchema());
id.setName("id", errors);
oldFields.add(id);
RecordDataSchema.Field message = new RecordDataSchema.Field(new StringDataSchema());
message.setName("message", errors);
oldFields.add(message);
RecordDataSchema.Field toneField = new RecordDataSchema.Field(tone);
toneField.setName("tone", errors);
toneField.setOptional(true);
oldFields.add(toneField);
prevGreeting.setFields(oldFields, errors);
// Previous error details schema (overwrites the existing one in the resolver path)
Name dummyErrorDetailsName = new Name("com.linkedin.restli.tools.DummyErrorDetails");
RecordDataSchema prevDummyErrorDetails = new RecordDataSchema(dummyErrorDetailsName, RecordDataSchema.RecordType.RECORD);
RecordDataSchema.Field idField = new RecordDataSchema.Field(new LongDataSchema());
idField.setName("id", errors);
RecordDataSchema.Field validatedField = new RecordDataSchema.Field(new StringDataSchema());
validatedField.setName("validated", errors);
validatedField.setProperties(Collections.singletonMap("validate", new DataMap(Collections.singletonMap("v1", new DataMap()))));
prevDummyErrorDetails.setFields(Arrays.asList(idField, validatedField), errors);
prevSchemaResolver.bindNameToSchema(toneName, tone, null);
prevSchemaResolver.bindNameToSchema(greetingName, prevGreeting, null);
prevSchemaResolver.bindNameToSchema(dummyErrorDetailsName, prevDummyErrorDetails, null);
// compat greeting added a new optional field "newField"
RecordDataSchema compatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> compatFields = new ArrayList<>();
compatFields.add(id);
compatFields.add(message);
compatFields.add(toneField);
RecordDataSchema.Field newCompatField = new RecordDataSchema.Field(new StringDataSchema());
newCompatField.setName("newField", errors);
newCompatField.setOptional(true);
compatFields.add(newCompatField);
compatGreeting.setFields(compatFields, errors);
// Compatible error details schema
RecordDataSchema compatDummyErrorDetails = new RecordDataSchema(dummyErrorDetailsName, RecordDataSchema.RecordType.RECORD);
compatDummyErrorDetails.setFields(Arrays.asList(idField, validatedField, newCompatField), errors);
compatSchemaResolver.bindNameToSchema(toneName, tone, null);
compatSchemaResolver.bindNameToSchema(greetingName, compatGreeting, null);
compatSchemaResolver.bindNameToSchema(dummyErrorDetailsName, compatDummyErrorDetails, null);
// Incompatible greeting has removed non-optional field "message",
// has changed the type of "id" to string,
// and added a new non-optional field "newField"
RecordDataSchema incompatGreeting = new RecordDataSchema(greetingName, RecordDataSchema.RecordType.RECORD);
List<RecordDataSchema.Field> incompatFields = new ArrayList<>();
RecordDataSchema.Field incompatId = new RecordDataSchema.Field(new StringDataSchema());
incompatId.setName("id", errors);
oldFields.add(incompatId);
incompatFields.add(incompatId);
incompatFields.add(toneField);
RecordDataSchema.Field newIncompatField = new RecordDataSchema.Field(new StringDataSchema());
newIncompatField.setName("newField", errors);
incompatFields.add(newIncompatField);
incompatGreeting.setFields(incompatFields, errors);
// Incompatible error details schema
RecordDataSchema incompatDummyErrorDetails = new RecordDataSchema(dummyErrorDetailsName, RecordDataSchema.RecordType.RECORD);
RecordDataSchema.Field incompatValidatedField = new RecordDataSchema.Field(new StringDataSchema());
incompatValidatedField.setName("validated", errors);
incompatValidatedField.setProperties(Collections.singletonMap("validate", new DataMap(Collections.singletonMap("v2", new DataMap()))));
incompatDummyErrorDetails.setFields(Collections.singletonList(incompatValidatedField), errors);
incompatSchemaResolver.bindNameToSchema(toneName, tone, null);
incompatSchemaResolver.bindNameToSchema(greetingName, incompatGreeting, null);
incompatSchemaResolver.bindNameToSchema(dummyErrorDetailsName, incompatDummyErrorDetails, null);
}
Aggregations