class TemplatePathsAPI extends TraverserAPI {

    private static final Logger LOG = Log.logger(TemplatePathsAPI.class);

    private static List<RepeatEdgeStep> steps(HugeGraph g,
                                              List<TemplatePathStep> steps) {
        List<RepeatEdgeStep> edgeSteps = new ArrayList<>(steps.size());
        for (TemplatePathStep step : steps) {
            edgeSteps.add(repeatEdgeStep(g, step));
        }
        return edgeSteps;
    }

    private static RepeatEdgeStep repeatEdgeStep(HugeGraph graph,
                                                 TemplatePathStep step) {
        return new RepeatEdgeStep(graph, step.direction, step.labels,
                                  step.properties, step.maxDegree,
                                  step.skipDegree, step.maxTimes);
    }

    @POST
    @Timed
    @Consumes(APPLICATION_JSON)
    @Produces(APPLICATION_JSON_WITH_CHARSET)
    public String post(@Context GraphManager manager,
                       @PathParam("graph") String graph,
                       Request request) {<FILL_FUNCTION_BODY>}

    private static class Request {

        @JsonProperty("sources")
        public Vertices sources;
        @JsonProperty("targets")
        public Vertices targets;
        @JsonProperty("steps")
        public List<TemplatePathStep> steps;
        @JsonProperty("with_ring")
        public boolean withRing = false;
        @JsonProperty("capacity")
        public long capacity = Long.parseLong(DEFAULT_CAPACITY);
        @JsonProperty("limit")
        public int limit = Integer.parseInt(DEFAULT_PATHS_LIMIT);
        @JsonProperty("with_vertex")
        public boolean withVertex = false;
        @JsonProperty("with_edge")
        public boolean withEdge = false;

        @Override
        public String toString() {
            return String.format("TemplatePathsRequest{sources=%s,targets=%s," +
                                 "steps=%s,withRing=%s,capacity=%s,limit=%s," +
                                 "withVertex=%s,withEdge=%s}",
                                 this.sources, this.targets, this.steps,
                                 this.withRing, this.capacity, this.limit,
                                 this.withVertex, this.withEdge);
        }
    }

    protected static class TemplatePathStep extends Step {

        @JsonProperty("max_times")
        public int maxTimes = 1;

        @Override
        public String toString() {
            return String.format("TemplatePathStep{direction=%s,labels=%s," +
                                 "properties=%s,maxDegree=%s,skipDegree=%s," +
                                 "maxTimes=%s}",
                                 this.direction, this.labels, this.properties,
                                 this.maxDegree, this.skipDegree,
                                 this.maxTimes);
        }
    }
}

        E.checkArgumentNotNull(request, "The request body can't be null");
        E.checkArgumentNotNull(request.sources,
                               "The sources of request can't be null");
        E.checkArgumentNotNull(request.targets,
                               "The targets of request can't be null");
        E.checkArgument(request.steps != null && !request.steps.isEmpty(),
                        "The steps of request can't be empty");

        LOG.debug("Graph [{}] get template paths from source vertices '{}', " +
                  "target vertices '{}', with steps '{}', " +
                  "capacity '{}', limit '{}', with_vertex '{}' and with_edge '{}'",
                  graph, request.sources, request.targets, request.steps,
                  request.capacity, request.limit, request.withVertex, request.withEdge);

        ApiMeasurer measure = new ApiMeasurer();

        HugeGraph g = graph(manager, graph);
        Iterator<Vertex> sources = request.sources.vertices(g);
        Iterator<Vertex> targets = request.targets.vertices(g);
        List<RepeatEdgeStep> steps = steps(g, request.steps);

        TemplatePathsTraverser traverser = new TemplatePathsTraverser(g);
        TemplatePathsTraverser.WrappedPathSet wrappedPathSet =
                traverser.templatePaths(sources, targets, steps,
                                        request.withRing, request.capacity,
                                        request.limit);
        measure.addIterCount(traverser.vertexIterCounter.get(),
                             traverser.edgeIterCounter.get());

        Set<HugeTraverser.Path> paths = wrappedPathSet.paths();

        Iterator<?> iterVertex;
        Set<Id> vertexIds = new HashSet<>();
        for (HugeTraverser.Path path : paths) {
            vertexIds.addAll(path.vertices());
        }
        if (request.withVertex && !vertexIds.isEmpty()) {
            iterVertex = g.vertices(vertexIds.toArray());
            measure.addIterCount(vertexIds.size(), 0L);
        } else {
            iterVertex = vertexIds.iterator();
        }

        Iterator<?> iterEdge;
        Set<Edge> edges = wrappedPathSet.edges();
        if (request.withEdge && !edges.isEmpty()) {
            iterEdge = edges.iterator();
        } else {
            iterEdge = HugeTraverser.EdgeRecord.getEdgeIds(edges).iterator();
        }

        return manager.serializer(g, measure.measures())
                      .writePaths("paths", paths, false,
                                  iterVertex, iterEdge);
    
<methods>public non-sealed void <init>() <variables>