private generateSteps()

in lib/apiScenario/gen/restlerApiScenarioGenerator.ts [442:522]


  private generateSteps() {
    const scenario: RawScenario = {
      scenario: "GeneratedScenario",
      steps: [],
    };

    const heap = new Heap<Node>((a, b) => {
      const priority = b.priority - a.priority;
      if (priority) {
        return priority;
      }

      const degree = b.outDegree - a.outDegree;
      if (degree) {
        return degree;
      }
      return methodOrder.indexOf(a.method) - methodOrder.indexOf(b.method);
    });

    for (const node of this.graph.values()) {
      if (node.operationId.includes("CheckNameAvailability")) {
        scenario.steps.push({ operationId: node.operationId });
        node.visited = true;
        continue;
      }
      if (node.inDegree === 0 && node.method === "put") {
        heap.push(node);
        node.visited = true;
      }
    }

    const deleteStack: Node[] = [];

    while (!heap.empty()) {
      const node = heap.pop()!;

      scenario.steps.push({ operationId: node.operationId });
      const operation = node.operationId.split("_")[0];

      for (const n of node.children.values()) {
        n.inDegree--;
        if (n.inDegree === 0 && n.method === "put") {
          heap.push(n);
          n.visited = true;
        }
      }

      if (node.method !== "put") {
        continue;
      }

      for (const n of this.graph.values()) {
        if (n.inDegree === 0 && !n.visited && n.operationId.split("_")[0] === operation) {
          n.priority = 1;
          if (n.method === "delete") {
            n.visited = true;
            deleteStack.push(n);
          } else {
            heap.push(n);
            n.visited = true;
          }
        }
      }
    }

    for (const node of this.graph.values()) {
      if (!node.visited) {
        scenario.steps.push({ operationId: node.operationId });
        if (node.inDegree !== 0) {
          console.error("node inDegree is not 0 ", node.operationId, node.method);
        }
      }
    }

    while (deleteStack.length > 0) {
      const node = deleteStack.pop()!;
      scenario.steps.push({ operationId: node.operationId });
    }

    return scenario;
  }