visitHttpOperation()

in packages/extensions/core/src/lib/plugins/tree-shaker/tree-shaker.ts [209:303]


  visitHttpOperation(targetParent: AnyObject, nodes: Iterable<Node>) {
    // split out the servers first.
    const [servers, theNodes] = partition([...nodes], (each) => each.key === "servers");

    // set the operationServers if they exist.
    servers.forEach((s) => (this.operationServers = s.value));

    this.clone(targetParent, "servers", "/", this.servers);

    let newArray =
      this.pathParameters && this.pathParameters.length > 0 ? this.newArray(targetParent, "parameters", "") : undefined;
    if (newArray) {
      for (const child of this.pathParameters ?? []) {
        const p = this.dereference(
          "/components/parameters",
          this.parameters,
          this.visitParameter,
          newArray,
          child.key,
          child.pointer,
          child.value,
          child.children,
        );
        // tag it as a method parameter. (default is 'client', so we have to tag it when we move it.)
        if (!child.value.$ref && p["x-ms-parameter-location"] === undefined) {
          p["x-ms-parameter-location"] = { value: "method", pointer: "" };
        }
      }
    }

    for (const { value, key, pointer, children } of theNodes) {
      switch (key) {
        case "parameters":
          {
            // parameters are a small special case, because they have to be tweaked when they are moved to the global parameter section.
            newArray = newArray || this.newArray(targetParent, key, pointer);
            for (const child of children) {
              const index = (this.pathParameters ? this.pathParameters.length : 0) + Number(child.key);
              const p = this.dereference(
                "/components/parameters",
                this.parameters,
                this.visitParameter,
                newArray,
                index.toString(),
                child.pointer,
                child.value,
                child.children,
              );
              // tag it as a method parameter. (default is 'client', so we have to tag it when we move it.)
              if (!child.value.$ref && p["x-ms-parameter-location"] === undefined) {
                p["x-ms-parameter-location"] = { value: "method", pointer: "" };
              }
            }
          }
          break;

        case "requestBody":
          this.dereference(
            "/components/requestBodies",
            this.requestBodies,
            this.visitRequestBody,
            targetParent,
            key,
            pointer,
            value,
            children,
          );
          break;
        case "responses":
          this.dereferenceItems(
            "/components/responses",
            this.responses,
            this.visitResponse,
            this.newObject(targetParent, key, pointer),
            children,
          );
          break;
        case "callbacks":
          this.dereferenceItems(
            "/components/callbacks",
            this.callbacks,
            this.visitCallback,
            this.newObject(targetParent, key, pointer),
            children,
          );
          break;
        default:
          this.clone(targetParent, key, pointer, value);
          break;
      }
    }

    // reset at end
    this.operationServers = undefined;
  }