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();
}
Aggregations