private getArmMethodInfo()

in lib/apiScenario/armUrlParser.ts [125:188]


  private getArmMethodInfo(
    resourceSlice: string[],
    httpMethod: HttpMethods,
    path: string,
    provider: string,
    operation?: Operation
  ) {
    let resourceUri = path;
    let actionName: string | undefined = undefined;
    const resourcePart = `/${resourceSlice.join("/")}`;
    const resourceTypeArr = resourceSlice.filter((_, idx) => idx % 2 === 0);
    const resourceNameArr = resourceSlice.filter((_, idx) => idx % 2 === 1);

    const methodTypeMap: { [key in HttpMethods]?: ArmMethodType } = {
      PUT: "CreateOrUpdate",
      DELETE: "Delete",
      GET: resourceSlice.length % 2 === 0 ? "Get" : "GetCollection",
      PATCH: "Update",
      HEAD: "Head",
      POST: "Action",
    };
    const methodType = methodTypeMap[httpMethod];
    if (methodType === undefined) {
      throw new Error(`Unsupported http method ${httpMethod} in path: ${resourcePart}`);
    }

    if (methodType === "Action") {
      if (resourceSlice.length % 2 === 0) {
        // throw new Error(
        //   `Invalid ARM action part, should contains odd path segments: ${resourcePart}`
        // );
        logger.warn(`Invalid ARM action part, should contains odd path segments: ${path}`);
      }
      actionName = resourceTypeArr.pop();
      resourceUri = path.slice(0, path.lastIndexOf("/"));
    }

    const resourceName = resourceNameArr.join("/");
    let resourceTypes: string[] = [provider];
    if (operation === undefined) {
      resourceTypes[0] = `${provider}/${resourceTypeArr.join("/")}`;
    } else {
      for (const seg of resourceTypeArr) {
        const paramName = this.getParamNameForPathTemplate(seg);
        if (paramName === undefined) {
          resourceTypes = resourceTypes.map((t) => `${t}/${seg}`);
        } else {
          const segTypes = this.getPathParamEnumValues(operation, paramName);
          resourceTypes = resourceTypes
            .map((t) => segTypes.map((s) => `${t}/${s}`))
            .reduce((a, b) => a.concat(b), []);
        }
      }
    }

    return {
      actionName,
      methodType,
      resourceName,
      resourceTypes,
      resourceUri,
      resourcePart,
    };
  }