public async process()

in packages/extensions/core/src/lib/plugins/merger.ts [94:188]


  public async process(target: ProxyObject<oai.Model>, nodes: Iterable<Node>) {
    for (const { key, value, pointer, children } of nodes) {
      switch (key) {
        case "paths":
        case "x-ms-paths":
          // Merge paths and x-ms-paths together under paths.
          if (!this.isSecondaryFile) {
            const paths = target.paths || this.newObject(target, "paths", pointer);
            this.visitPaths(paths as any, children);
          }
          break;

        case "components":
          {
            const components = target.components || this.newObject(target, "components", pointer);
            this.visitComponents(components as any, children);
          }
          break;

        case "servers":
          if (!this.isSecondaryFile) {
            const array = <any>target.servers ?? this.newArray(target, "servers", pointer);
            for (const item of children) {
              this.visitServer(item, array);
            }
          }
          break;
        case "security":
        case "tags":
          if (!this.isSecondaryFile) {
            const array = <any>target[key] || this.newArray(target, key, pointer);
            for (const item of children) {
              array.__push__({
                value: item.value,
                pointer: item.pointer,
                recurse: true,
              });
            }
          }
          break;

        case "info":
          if (!this.isSecondaryFile) {
            const info = this.getOrCreateObject(target, "info", pointer);
            this.visitInfo(info, children);
          }

          break;

        case "externalDocs":
          if (!this.isSecondaryFile) {
            if (!target.externalDocs) {
              const docs = this.newObject(target, "externalDocs", pointer);
              for (const child of children) {
                this.copy(docs, child.key, child.pointer, child.value, true);
              }
            }
            const docsMetadata =
              (<oai.ExternalDocumentation>target.externalDocs)["x-ms-metadata"] ||
              this.newArray(<oai.ExternalDocumentation>target.externalDocs, "x-ms-metadata" as any, pointer);
            docsMetadata.__push__({
              value: cloneDeep(value),
              pointer,
              recurse: true,
            });
          }
          break;

        case "openapi":
          if (!this.isSecondaryFile) {
            if (!target.openapi) {
              this.copy(target, key, pointer, value);
            }
          }
          break;

        default:
          if (!this.isSecondaryFile) {
            if (!target[key as any]) {
              this.copy(target, key as any, pointer, value);
            }
          }
          break;
      }
    }

    // after each file, we have to go fix up local references to be absolute references
    // just in case it wasn't done before we got here.
    this.expandRefs(this.generated);

    // mark this merged.
    if (!this.metadata.merged) {
      this.metadata.merged = { value: true, pointer: "/", filename: this.currentInputFilename };
    }
  }