Search in sources :

Example 16 with NamedDataSchema

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);
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) RoutingException(com.linkedin.restli.server.RoutingException) SchemaSampleDataGenerator(com.linkedin.data.schema.generator.SchemaSampleDataGenerator) RestLiInternalException(com.linkedin.restli.internal.server.RestLiInternalException) IOException(java.io.IOException) DataMap(com.linkedin.data.DataMap)

Example 17 with NamedDataSchema

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);
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) OptionsResponse(com.linkedin.restli.common.OptionsResponse) Test(org.testng.annotations.Test)

Example 18 with NamedDataSchema

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);
        }
    }
}
Also used : NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema)

Example 19 with NamedDataSchema

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;
}
Also used : JsonBuilder(com.linkedin.data.schema.JsonBuilder) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema) FileOutputStream(java.io.FileOutputStream) SchemaToJsonEncoder(com.linkedin.data.schema.SchemaToJsonEncoder) File(java.io.File)

Example 20 with NamedDataSchema

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);
    }
}
Also used : DataSchema(com.linkedin.data.schema.DataSchema) UnionDataSchema(com.linkedin.data.schema.UnionDataSchema) MapDataSchema(com.linkedin.data.schema.MapDataSchema) TyperefDataSchema(com.linkedin.data.schema.TyperefDataSchema) RecordDataSchema(com.linkedin.data.schema.RecordDataSchema) NamedDataSchema(com.linkedin.data.schema.NamedDataSchema) ArrayDataSchema(com.linkedin.data.schema.ArrayDataSchema)

Aggregations

NamedDataSchema (com.linkedin.data.schema.NamedDataSchema)46 DataSchema (com.linkedin.data.schema.DataSchema)25 RecordDataSchema (com.linkedin.data.schema.RecordDataSchema)16 ArrayDataSchema (com.linkedin.data.schema.ArrayDataSchema)12 MapDataSchema (com.linkedin.data.schema.MapDataSchema)11 TyperefDataSchema (com.linkedin.data.schema.TyperefDataSchema)11 UnionDataSchema (com.linkedin.data.schema.UnionDataSchema)11 DataMap (com.linkedin.data.DataMap)8 IOException (java.io.IOException)8 DataSchemaLocation (com.linkedin.data.schema.DataSchemaLocation)7 PrimitiveDataSchema (com.linkedin.data.schema.PrimitiveDataSchema)7 EnumDataSchema (com.linkedin.data.schema.EnumDataSchema)6 FixedDataSchema (com.linkedin.data.schema.FixedDataSchema)6 SchemaParser (com.linkedin.data.schema.SchemaParser)6 ComplexDataSchema (com.linkedin.data.schema.ComplexDataSchema)5 File (java.io.File)5 Test (org.testng.annotations.Test)5 CustomInfoSpec (com.linkedin.pegasus.generator.spec.CustomInfoSpec)4 RestLiInternalException (com.linkedin.restli.internal.server.RestLiInternalException)4 FileInputStream (java.io.FileInputStream)4