function processOperationResponses()

in packages/autorest.go/src/transform/transform.ts [714:764]


function processOperationResponses(session: Session<m4.CodeModel>) {
  if (session.model.language.go!.responseEnvelopes === undefined) {
    session.model.language.go!.responseEnvelopes = new Array<m4.Schema>();
  }
  for (const group of values(session.model.operationGroups)) {
    for (const op of values(group.operations)) {
      // recursively add the marshalling format to the responses if applicable.
      // also remove any HTTP redirects from the list of responses.
      const filtered = new Array<m4.Response>();
      for (const resp of values(op.responses)) {
        if (skipRedirectStatusCode(<string>op.requests![0].protocol.http!.method, resp)) {
          // redirects are transient status codes, they aren't actually returned
          continue;
        }
        if (helpers.isSchemaResponse(resp)) {
          if (resp.schema.type === m4.SchemaType.Binary) {
            // don't create response envelopes for binary responses.
            // callers read directly from the *http.Response.Body
            continue;
          }
          resp.schema.language.go!.name = schemaTypeToGoType(session.model, resp.schema, 'InBody');
        }
        const marshallingFormat = getMarshallingFormat(resp.protocol);
        if (marshallingFormat !== 'na' && helpers.isSchemaResponse(resp)) {
          recursiveAddMarshallingFormat(resp.schema, marshallingFormat);
        }
        // fix up schema types for header responses
        const httpResponse = <m4.HttpResponse>resp.protocol.http;
        for (const header of values(httpResponse.headers)) {
          header.schema.language.go!.name = schemaTypeToGoType(session.model, header.schema, 'Property');
          // check if this is a header collection
          if (header.extensions?.['x-ms-header-collection-prefix']) {
            header.schema.language.go!.headerCollectionPrefix = header.extensions['x-ms-header-collection-prefix'];
          }
        }
        filtered.push(resp);
        if (resp.language.go!.description) {
          resp.language.go!.description = parseComments(resp.language.go!.description);
        }
      }
      // replace with the filtered list if applicable
      if (filtered.length === 0) {
        // handling of operations with no responses expects an undefined list, not an empty one
        op.responses = undefined;
      } else if (op.responses?.length !== filtered.length) {
        op.responses = filtered;
      }
      createResponseEnvelope(session.model, group, op);
    }
  }
}