function processOperation()

in eng/tools/typespec-migration-validation/src/document.ts [66:119]


function processOperation(operation: OpenAPI2Operation): OpenAPI2Operation {
  const newOperation = deepCopy(operation);
  let index = newOperation.parameters.findIndex(p => isApiVersionParameter(p));
  if (index > -1) {
    newOperation.parameters.splice(index, 1);
  }
  index = newOperation.parameters.findIndex(p => isSubscriptionIdParameter(p));
  if (index > -1) {
    newOperation.parameters.splice(index, 1);
  }
  index = newOperation.parameters.findIndex(p => isResourceGroupNameParameter(p));
  if (index > -1) {
    newOperation.parameters.splice(index, 1);
  }
  newOperation.parameters = newOperation.parameters.map(p => processParameter(p));

  for (const response in operation.responses) {
    const responseObject = operation.responses[response] as OpenAPI2Response;
    const processedResponse = processResponse(responseObject);
    newOperation.responses ??= {};
    newOperation.responses[response] = processedResponse;
  }

  if (newOperation["x-ms-long-running-operation"] === false) {
    delete newOperation["x-ms-long-running-operation"];
  }
  if (newOperation["x-ms-long-running-operation-options"] && newOperation["x-ms-long-running-operation-options"]["final-state-via"] === "location") {
    delete newOperation["x-ms-long-running-operation-options"];
  }

  if (newOperation["x-ms-pageable"] && newOperation["x-ms-pageable"]["nextLinkName"] === null) {
    newOperation["x-ms-pageable"]["nextLinkName"] = "nextLink";
  }
  if (newOperation["x-ms-pageable"] && newOperation["x-ms-pageable"]["itemName"] === "value") {
    delete newOperation["x-ms-pageable"]["itemName"];
  }

  if (newOperation.produces && newOperation.produces.length === 1 && newOperation.produces[0] === "application/json") {
    delete newOperation.produces;
  }
  if (newOperation.consumes && newOperation.consumes.length === 1 && newOperation.consumes[0] === "application/json") {
    delete newOperation.consumes;
  }

  if (newOperation.tags) {
    delete newOperation.tags;
  }

  if (configuration.ignoreDescription) {
    delete newOperation.description;
    delete newOperation.summary;
  }
  return newOperation;
}