{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.APIGateway.Types.GatewayResponse
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.APIGateway.Types.GatewayResponse where

import Amazonka.APIGateway.Types.GatewayResponseType
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | A gateway response of a given response type and status code, with
-- optional response parameters and mapping templates.
--
-- For more information about valid gateway response types, see
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/supported-gateway-response-types.html Gateway Response Types Supported by API Gateway>
--
-- ==== Example: Get a Gateway Response of a given response type
--
-- ===== Request
--
-- This example shows how to get a gateway response of the
-- @MISSING_AUTHENTICATION_TOKEN@ type.
--
-- > GET /restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN HTTP/1.1 Host: beta-apigateway.us-east-1.amazonaws.com Content-Type: application/json X-Amz-Date: 20170503T202516Z Authorization: AWS4-HMAC-SHA256 Credential={access-key-id}/20170503/us-east-1/apigateway/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=1b52460e3159c1a26cff29093855d50ea141c1c5b937528fecaf60f51129697a Cache-Control: no-cache Postman-Token: 3b2a1ce9-c848-2e26-2e2f-9c2caefbed45
--
-- The response type is specified as a URL path.
--
-- ===== Response
--
-- The successful operation returns the @200 OK@ status code and a payload
-- similar to the following:
--
-- > { "_links": { "curies": { "href": "http://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-gatewayresponse-{rel}.html", "name": "gatewayresponse", "templated": true }, "self": { "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN" }, "gatewayresponse:delete": { "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN" }, "gatewayresponse:put": { "href": "/restapis/o81lxisefl/gatewayresponses/{response_type}", "templated": true }, "gatewayresponse:update": { "href": "/restapis/o81lxisefl/gatewayresponses/MISSING_AUTHENTICATION_TOKEN" } }, "defaultResponse": false, "responseParameters": { "gatewayresponse.header.x-request-path": "method.request.path.petId", "gatewayresponse.header.Access-Control-Allow-Origin": "'a.b.c'", "gatewayresponse.header.x-request-query": "method.request.querystring.q", "gatewayresponse.header.x-request-header": "method.request.header.Accept" }, "responseTemplates": { "application/json": "{\n \"message\": $context.error.messageString,\n \"type\": \"$context.error.responseType\",\n \"stage\": \"$context.stage\",\n \"resourcePath\": \"$context.resourcePath\",\n \"stageVariables.a\": \"$stageVariables.a\",\n \"statusCode\": \"'404'\"\n}" }, "responseType": "MISSING_AUTHENTICATION_TOKEN", "statusCode": "404" }
--
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/customize-gateway-responses.html Customize Gateway Responses>
--
-- /See:/ 'newGatewayResponse' smart constructor.
data GatewayResponse = GatewayResponse'
  { -- | A Boolean flag to indicate whether this GatewayResponse is the default
    -- gateway response (@true@) or not (@false@). A default gateway response
    -- is one generated by API Gateway without any customization by an API
    -- developer.
    GatewayResponse -> Maybe Bool
defaultResponse :: Prelude.Maybe Prelude.Bool,
    -- | Response templates of the GatewayResponse as a string-to-string map of
    -- key-value pairs.
    GatewayResponse -> Maybe (HashMap Text Text)
responseTemplates :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The response type of the associated GatewayResponse.
    GatewayResponse -> Maybe GatewayResponseType
responseType :: Prelude.Maybe GatewayResponseType,
    -- | The HTTP status code for this GatewayResponse.
    GatewayResponse -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text,
    -- | Response parameters (paths, query strings and headers) of the
    -- GatewayResponse as a string-to-string map of key-value pairs.
    GatewayResponse -> Maybe (HashMap Text Text)
responseParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text)
  }
  deriving (GatewayResponse -> GatewayResponse -> Bool
(GatewayResponse -> GatewayResponse -> Bool)
-> (GatewayResponse -> GatewayResponse -> Bool)
-> Eq GatewayResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GatewayResponse -> GatewayResponse -> Bool
$c/= :: GatewayResponse -> GatewayResponse -> Bool
== :: GatewayResponse -> GatewayResponse -> Bool
$c== :: GatewayResponse -> GatewayResponse -> Bool
Prelude.Eq, ReadPrec [GatewayResponse]
ReadPrec GatewayResponse
Int -> ReadS GatewayResponse
ReadS [GatewayResponse]
(Int -> ReadS GatewayResponse)
-> ReadS [GatewayResponse]
-> ReadPrec GatewayResponse
-> ReadPrec [GatewayResponse]
-> Read GatewayResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GatewayResponse]
$creadListPrec :: ReadPrec [GatewayResponse]
readPrec :: ReadPrec GatewayResponse
$creadPrec :: ReadPrec GatewayResponse
readList :: ReadS [GatewayResponse]
$creadList :: ReadS [GatewayResponse]
readsPrec :: Int -> ReadS GatewayResponse
$creadsPrec :: Int -> ReadS GatewayResponse
Prelude.Read, Int -> GatewayResponse -> ShowS
[GatewayResponse] -> ShowS
GatewayResponse -> String
(Int -> GatewayResponse -> ShowS)
-> (GatewayResponse -> String)
-> ([GatewayResponse] -> ShowS)
-> Show GatewayResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GatewayResponse] -> ShowS
$cshowList :: [GatewayResponse] -> ShowS
show :: GatewayResponse -> String
$cshow :: GatewayResponse -> String
showsPrec :: Int -> GatewayResponse -> ShowS
$cshowsPrec :: Int -> GatewayResponse -> ShowS
Prelude.Show, (forall x. GatewayResponse -> Rep GatewayResponse x)
-> (forall x. Rep GatewayResponse x -> GatewayResponse)
-> Generic GatewayResponse
forall x. Rep GatewayResponse x -> GatewayResponse
forall x. GatewayResponse -> Rep GatewayResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GatewayResponse x -> GatewayResponse
$cfrom :: forall x. GatewayResponse -> Rep GatewayResponse x
Prelude.Generic)

-- |
-- Create a value of 'GatewayResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'defaultResponse', 'gatewayResponse_defaultResponse' - A Boolean flag to indicate whether this GatewayResponse is the default
-- gateway response (@true@) or not (@false@). A default gateway response
-- is one generated by API Gateway without any customization by an API
-- developer.
--
-- 'responseTemplates', 'gatewayResponse_responseTemplates' - Response templates of the GatewayResponse as a string-to-string map of
-- key-value pairs.
--
-- 'responseType', 'gatewayResponse_responseType' - The response type of the associated GatewayResponse.
--
-- 'statusCode', 'gatewayResponse_statusCode' - The HTTP status code for this GatewayResponse.
--
-- 'responseParameters', 'gatewayResponse_responseParameters' - Response parameters (paths, query strings and headers) of the
-- GatewayResponse as a string-to-string map of key-value pairs.
newGatewayResponse ::
  GatewayResponse
newGatewayResponse :: GatewayResponse
newGatewayResponse =
  GatewayResponse' :: Maybe Bool
-> Maybe (HashMap Text Text)
-> Maybe GatewayResponseType
-> Maybe Text
-> Maybe (HashMap Text Text)
-> GatewayResponse
GatewayResponse'
    { $sel:defaultResponse:GatewayResponse' :: Maybe Bool
defaultResponse = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:responseTemplates:GatewayResponse' :: Maybe (HashMap Text Text)
responseTemplates = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:responseType:GatewayResponse' :: Maybe GatewayResponseType
responseType = Maybe GatewayResponseType
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:GatewayResponse' :: Maybe Text
statusCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:responseParameters:GatewayResponse' :: Maybe (HashMap Text Text)
responseParameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing
    }

-- | A Boolean flag to indicate whether this GatewayResponse is the default
-- gateway response (@true@) or not (@false@). A default gateway response
-- is one generated by API Gateway without any customization by an API
-- developer.
gatewayResponse_defaultResponse :: Lens.Lens' GatewayResponse (Prelude.Maybe Prelude.Bool)
gatewayResponse_defaultResponse :: (Maybe Bool -> f (Maybe Bool))
-> GatewayResponse -> f GatewayResponse
gatewayResponse_defaultResponse = (GatewayResponse -> Maybe Bool)
-> (GatewayResponse -> Maybe Bool -> GatewayResponse)
-> Lens GatewayResponse GatewayResponse (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe Bool
defaultResponse :: Maybe Bool
$sel:defaultResponse:GatewayResponse' :: GatewayResponse -> Maybe Bool
defaultResponse} -> Maybe Bool
defaultResponse) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe Bool
a -> GatewayResponse
s {$sel:defaultResponse:GatewayResponse' :: Maybe Bool
defaultResponse = Maybe Bool
a} :: GatewayResponse)

-- | Response templates of the GatewayResponse as a string-to-string map of
-- key-value pairs.
gatewayResponse_responseTemplates :: Lens.Lens' GatewayResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
gatewayResponse_responseTemplates :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GatewayResponse -> f GatewayResponse
gatewayResponse_responseTemplates = (GatewayResponse -> Maybe (HashMap Text Text))
-> (GatewayResponse
    -> Maybe (HashMap Text Text) -> GatewayResponse)
-> Lens
     GatewayResponse
     GatewayResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe (HashMap Text Text)
responseTemplates :: Maybe (HashMap Text Text)
$sel:responseTemplates:GatewayResponse' :: GatewayResponse -> Maybe (HashMap Text Text)
responseTemplates} -> Maybe (HashMap Text Text)
responseTemplates) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe (HashMap Text Text)
a -> GatewayResponse
s {$sel:responseTemplates:GatewayResponse' :: Maybe (HashMap Text Text)
responseTemplates = Maybe (HashMap Text Text)
a} :: GatewayResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> GatewayResponse -> f GatewayResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GatewayResponse
-> f GatewayResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The response type of the associated GatewayResponse.
gatewayResponse_responseType :: Lens.Lens' GatewayResponse (Prelude.Maybe GatewayResponseType)
gatewayResponse_responseType :: (Maybe GatewayResponseType -> f (Maybe GatewayResponseType))
-> GatewayResponse -> f GatewayResponse
gatewayResponse_responseType = (GatewayResponse -> Maybe GatewayResponseType)
-> (GatewayResponse
    -> Maybe GatewayResponseType -> GatewayResponse)
-> Lens
     GatewayResponse
     GatewayResponse
     (Maybe GatewayResponseType)
     (Maybe GatewayResponseType)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe GatewayResponseType
responseType :: Maybe GatewayResponseType
$sel:responseType:GatewayResponse' :: GatewayResponse -> Maybe GatewayResponseType
responseType} -> Maybe GatewayResponseType
responseType) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe GatewayResponseType
a -> GatewayResponse
s {$sel:responseType:GatewayResponse' :: Maybe GatewayResponseType
responseType = Maybe GatewayResponseType
a} :: GatewayResponse)

-- | The HTTP status code for this GatewayResponse.
gatewayResponse_statusCode :: Lens.Lens' GatewayResponse (Prelude.Maybe Prelude.Text)
gatewayResponse_statusCode :: (Maybe Text -> f (Maybe Text))
-> GatewayResponse -> f GatewayResponse
gatewayResponse_statusCode = (GatewayResponse -> Maybe Text)
-> (GatewayResponse -> Maybe Text -> GatewayResponse)
-> Lens GatewayResponse GatewayResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:GatewayResponse' :: GatewayResponse -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe Text
a -> GatewayResponse
s {$sel:statusCode:GatewayResponse' :: Maybe Text
statusCode = Maybe Text
a} :: GatewayResponse)

-- | Response parameters (paths, query strings and headers) of the
-- GatewayResponse as a string-to-string map of key-value pairs.
gatewayResponse_responseParameters :: Lens.Lens' GatewayResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
gatewayResponse_responseParameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GatewayResponse -> f GatewayResponse
gatewayResponse_responseParameters = (GatewayResponse -> Maybe (HashMap Text Text))
-> (GatewayResponse
    -> Maybe (HashMap Text Text) -> GatewayResponse)
-> Lens
     GatewayResponse
     GatewayResponse
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GatewayResponse' {Maybe (HashMap Text Text)
responseParameters :: Maybe (HashMap Text Text)
$sel:responseParameters:GatewayResponse' :: GatewayResponse -> Maybe (HashMap Text Text)
responseParameters} -> Maybe (HashMap Text Text)
responseParameters) (\s :: GatewayResponse
s@GatewayResponse' {} Maybe (HashMap Text Text)
a -> GatewayResponse
s {$sel:responseParameters:GatewayResponse' :: Maybe (HashMap Text Text)
responseParameters = Maybe (HashMap Text Text)
a} :: GatewayResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> GatewayResponse -> f GatewayResponse)
-> ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
    -> Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> GatewayResponse
-> f GatewayResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
-> Iso
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
     (Maybe (HashMap Text Text))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
  (HashMap Text Text)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON GatewayResponse where
  parseJSON :: Value -> Parser GatewayResponse
parseJSON =
    String
-> (Object -> Parser GatewayResponse)
-> Value
-> Parser GatewayResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"GatewayResponse"
      ( \Object
x ->
          Maybe Bool
-> Maybe (HashMap Text Text)
-> Maybe GatewayResponseType
-> Maybe Text
-> Maybe (HashMap Text Text)
-> GatewayResponse
GatewayResponse'
            (Maybe Bool
 -> Maybe (HashMap Text Text)
 -> Maybe GatewayResponseType
 -> Maybe Text
 -> Maybe (HashMap Text Text)
 -> GatewayResponse)
-> Parser (Maybe Bool)
-> Parser
     (Maybe (HashMap Text Text)
      -> Maybe GatewayResponseType
      -> Maybe Text
      -> Maybe (HashMap Text Text)
      -> GatewayResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Bool)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"defaultResponse")
            Parser
  (Maybe (HashMap Text Text)
   -> Maybe GatewayResponseType
   -> Maybe Text
   -> Maybe (HashMap Text Text)
   -> GatewayResponse)
-> Parser (Maybe (HashMap Text Text))
-> Parser
     (Maybe GatewayResponseType
      -> Maybe Text -> Maybe (HashMap Text Text) -> GatewayResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"responseTemplates"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
            Parser
  (Maybe GatewayResponseType
   -> Maybe Text -> Maybe (HashMap Text Text) -> GatewayResponse)
-> Parser (Maybe GatewayResponseType)
-> Parser
     (Maybe Text -> Maybe (HashMap Text Text) -> GatewayResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe GatewayResponseType)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"responseType")
            Parser (Maybe Text -> Maybe (HashMap Text Text) -> GatewayResponse)
-> Parser (Maybe Text)
-> Parser (Maybe (HashMap Text Text) -> GatewayResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"statusCode")
            Parser (Maybe (HashMap Text Text) -> GatewayResponse)
-> Parser (Maybe (HashMap Text Text)) -> Parser GatewayResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Text)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"responseParameters"
                            Parser (Maybe (Maybe (HashMap Text Text)))
-> Maybe (HashMap Text Text) -> Parser (Maybe (HashMap Text Text))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Text)
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable GatewayResponse

instance Prelude.NFData GatewayResponse