github.com/phrase/openapi@v0.0.0-20240514140800-49e8a106740e/openapi-generator/templates/java/libraries/jersey2/ApiResponse.mustache (about)

     1  {{>licenseInfo}}
     2  
     3  package {{invokerPackage}};
     4  
     5  import java.util.List;
     6  import java.util.Map;
     7  {{#caseInsensitiveResponseHeaders}}
     8  import java.util.Map.Entry;		
     9  import java.util.TreeMap;
    10  {{/caseInsensitiveResponseHeaders}}
    11  
    12  /**
    13   * API response returned by API call.
    14   *
    15   * @param <T> The type of data that is deserialized from response body
    16   */
    17  public class ApiResponse<T> {
    18      private final int statusCode;
    19      private final Map<String, List<String>> headers;
    20      private final T data;
    21  
    22      /**
    23       * @param statusCode The status code of HTTP response
    24       * @param headers The headers of HTTP response
    25       */
    26      public ApiResponse(int statusCode, Map<String, List<String>> headers) {
    27          this(statusCode, headers, null);
    28      }
    29  
    30      /**
    31       * @param statusCode The status code of HTTP response
    32       * @param headers The headers of HTTP response
    33       * @param data The object deserialized from response bod
    34       */
    35      public ApiResponse(int statusCode, Map<String, List<String>> headers, T data) {
    36          this.statusCode = statusCode;
    37          {{#caseInsensitiveResponseHeaders}}
    38          Map<String, List<String>> responseHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
    39          for(Entry<String, List<String>> entry : headers.entrySet()){
    40             responseHeaders.put(entry.getKey().toLowerCase(), entry.getValue());
    41          }
    42          {{/caseInsensitiveResponseHeaders}}
    43          this.headers = {{#caseInsensitiveResponseHeaders}}responseHeaders{{/caseInsensitiveResponseHeaders}}{{^caseInsensitiveResponseHeaders}}headers{{/caseInsensitiveResponseHeaders}};
    44          this.data = data;
    45      }
    46  
    47      public int getStatusCode() {
    48          return statusCode;
    49      }
    50  
    51      public Map<String, List<String>> getHeaders() {
    52          return headers;
    53      }
    54  
    55      public T getData() {
    56          return data;
    57      }
    58  }