Search in sources :

Example 1 with TemplateSpecGenerator

use of com.linkedin.pegasus.generator.TemplateSpecGenerator in project rest.li by linkedin.

the class TestRequestBuilderSpecGenerator method generateBuilderSpec.

private Set<BuilderSpec> generateBuilderSpec(String[] sources) {
    final DataSchemaParser schemaParser = new DataSchemaParser(RESOLVER_DIR);
    final TemplateSpecGenerator specGenerator = new TemplateSpecGenerator(schemaParser.getSchemaResolver());
    final RestSpecParser parser = new RestSpecParser();
    final Map<ResourceMethod, String> builderBaseMap = new HashMap<ResourceMethod, String>();
    builderBaseMap.put(ResourceMethod.GET, "GetRequestBuilder");
    builderBaseMap.put(ResourceMethod.DELETE, "DeleteRequestBuilder");
    builderBaseMap.put(ResourceMethod.UPDATE, "UpdateRequestBuilder");
    builderBaseMap.put(ResourceMethod.CREATE, "CreateIdRequestBuilder");
    builderBaseMap.put(ResourceMethod.PARTIAL_UPDATE, "PartialUpdateRequestBuilder");
    builderBaseMap.put(ResourceMethod.GET_ALL, "GetAllRequestBuilder");
    builderBaseMap.put(ResourceMethod.OPTIONS, "OptionsRequestBuilder");
    builderBaseMap.put(ResourceMethod.ACTION, "ActionRequestBuilder");
    builderBaseMap.put(ResourceMethod.FINDER, "FinderRequestBuilder");
    builderBaseMap.put(ResourceMethod.BATCH_GET, "BatchGetRequestBuilder");
    builderBaseMap.put(ResourceMethod.BATCH_UPDATE, "BatchUpdateRequestBuilder");
    builderBaseMap.put(ResourceMethod.BATCH_PARTIAL_UPDATE, "BatchPartialUpdateRequestBuilder");
    builderBaseMap.put(ResourceMethod.BATCH_DELETE, "BatchDeleteRequestBuilder");
    builderBaseMap.put(ResourceMethod.BATCH_CREATE, "BatchCreateIdRequestBuilder");
    final RequestBuilderSpecGenerator builderSpecGenerator = new RequestBuilderSpecGenerator(schemaParser.getSchemaResolver(), specGenerator, RestliVersion.RESTLI_2_0_0, builderBaseMap);
    // parse idl to ResourceSchemas
    final RestSpecParser.ParseResult parseResult = parser.parseSources(sources);
    // generate Builder specs from ResourceSchema
    for (CodeUtil.Pair<ResourceSchema, File> pair : parseResult.getSchemaAndFiles()) {
        builderSpecGenerator.generate(pair.first, pair.second);
    }
    return builderSpecGenerator.getBuilderSpec();
}
Also used : ResourceSchema(com.linkedin.restli.restspec.ResourceSchema) HashMap(java.util.HashMap) CodeUtil(com.linkedin.pegasus.generator.CodeUtil) DataSchemaParser(com.linkedin.pegasus.generator.DataSchemaParser) TemplateSpecGenerator(com.linkedin.pegasus.generator.TemplateSpecGenerator) File(java.io.File) ResourceMethod(com.linkedin.restli.common.ResourceMethod)

Aggregations

CodeUtil (com.linkedin.pegasus.generator.CodeUtil)1 DataSchemaParser (com.linkedin.pegasus.generator.DataSchemaParser)1 TemplateSpecGenerator (com.linkedin.pegasus.generator.TemplateSpecGenerator)1 ResourceMethod (com.linkedin.restli.common.ResourceMethod)1 ResourceSchema (com.linkedin.restli.restspec.ResourceSchema)1 File (java.io.File)1 HashMap (java.util.HashMap)1