use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class RestLiHTMLDocumentationRenderer method renderDataModel.
@Override
public void renderDataModel(String dataModelName, OutputStream out) {
final NamedDataSchema schema = _relationships.getDataModels().get(dataModelName);
if (schema == null) {
throw new RoutingException(String.format("Data model named '%s' does not exist", dataModelName), 404);
}
final Map<String, Object> pageModel = createPageModel();
pageModel.put("dataModel", schema);
final DataMap example = SchemaSampleDataGenerator.buildRecordData(schema, new SchemaSampleDataGenerator.DataGenerationOptions());
try {
pageModel.put("example", new String(_codec.mapToBytes(example)));
} catch (IOException e) {
throw new RestLiInternalException(e);
}
addRelated(schema, pageModel);
_templatingEngine.render("dataModel.vm", pageModel, out);
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class TestGreetingsClient method testModelsForOptionsRequest.
@Test(dataProvider = com.linkedin.restli.internal.common.TestConstants.RESTLI_PROTOCOL_1_2_PREFIX + "optionsData")
public void testModelsForOptionsRequest(OptionsRequestBuilder request, NamedDataSchema[] schemas) throws RemoteInvocationException, URISyntaxException, IOException {
Request<OptionsResponse> optionsRequest = request.build();
OptionsResponse optionsResponse = getClient().sendRequest(optionsRequest).getResponse().getEntity();
Map<String, DataSchema> rawDataSchemas = optionsResponse.getDataSchemas();
for (NamedDataSchema dataSchema : schemas) {
DataSchema optionsDataSchema = rawDataSchemas.get(dataSchema.getFullName());
Assert.assertEquals(optionsDataSchema, dataSchema);
}
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class SnapshotGenerator method recordType.
private void recordType(DataSchema schema, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
if (schema instanceof NamedDataSchema) {
NamedDataSchema namedDataSchema = (NamedDataSchema) schema;
if (!foundTypes.containsKey(namedDataSchema.getFullName())) {
foundTypes.put(namedDataSchema.getFullName(), namedDataSchema);
if (// recurse into record, record any contained types.
schema instanceof RecordDataSchema) {
RecordDataSchema recordDataSchema = (RecordDataSchema) schema;
for (NamedDataSchema includedSchema : recordDataSchema.getInclude()) {
recordType(includedSchema, foundTypes, typeOrder);
}
for (RecordDataSchema.Field field : recordDataSchema.getFields()) {
recordType(field.getType(), foundTypes, typeOrder);
}
} else if (schema instanceof TyperefDataSchema) {
recordType(schema.getDereferencedDataSchema(), foundTypes, typeOrder);
}
typeOrder.add(namedDataSchema);
}
} else if (schema instanceof ArrayDataSchema) {
ArrayDataSchema arraySchema = (ArrayDataSchema) schema;
recordType(arraySchema.getItems(), foundTypes, typeOrder);
} else if (schema instanceof MapDataSchema) {
MapDataSchema mapSchema = (MapDataSchema) schema;
recordType(mapSchema.getValues(), foundTypes, typeOrder);
} else if (schema instanceof UnionDataSchema) {
UnionDataSchema unionSchema = (UnionDataSchema) schema;
for (DataSchema type : unionSchema.getTypes()) {
recordType(type, foundTypes, typeOrder);
}
}
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class SnapshotGenerator method writeFile.
public File writeFile(File outdirFile, String fileName) throws IOException {
fileName += RestConstants.SNAPSHOT_FILENAME_EXTENTION;
final File file = new File(outdirFile, fileName);
FileOutputStream fileOutputStream = new FileOutputStream(file);
JsonBuilder jsonBuilder = new JsonBuilder(JsonBuilder.Pretty.INDENTED);
SchemaToJsonEncoder encoder = new SchemaToJsonEncoder(jsonBuilder);
jsonBuilder.writeStartObject();
jsonBuilder.writeFieldName(Snapshot.MODELS_KEY);
jsonBuilder.writeStartArray();
List<NamedDataSchema> models = generateModelList();
for (DataSchema model : models) {
encoder.encode(model);
}
jsonBuilder.writeEndArray();
jsonBuilder.writeFieldName(Snapshot.SCHEMA_KEY);
jsonBuilder.writeDataTemplate(_topLevelSchema, true);
jsonBuilder.writeEndObject();
try {
fileOutputStream.write(jsonBuilder.result().getBytes());
} finally {
fileOutputStream.close();
jsonBuilder.close();
}
return file;
}
use of com.linkedin.data.schema.NamedDataSchema in project rest.li by linkedin.
the class SnapshotGenerator method recordType.
private void recordType(String type, Map<String, NamedDataSchema> foundTypes, List<NamedDataSchema> typeOrder) {
if (!foundTypes.containsKey(type)) {
DataSchema schema = RestSpecCodec.textToSchema(type, _schemaResolver);
recordType(schema, foundTypes, typeOrder);
}
}
Aggregations