{-# 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.MethodResponse
-- 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.MethodResponse where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude

-- | Represents a method response of a given HTTP status code returned to the
-- client. The method response is passed from the back end through the
-- associated integration response that can be transformed using a mapping
-- template.
--
-- ==== Example: A __MethodResponse__ instance of an API
--
-- ===== Request
--
-- The example request retrieves a __MethodResponse__ of the 200 status
-- code.
--
-- > GET /restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200 HTTP/1.1 Content-Type: application/json Host: apigateway.us-east-1.amazonaws.com X-Amz-Date: 20160603T222952Z Authorization: AWS4-HMAC-SHA256 Credential={access_key_ID}/20160603/us-east-1/apigateway/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature={sig4_hash}
--
-- ===== Response
--
-- The successful response returns @200 OK@ status and a payload as
-- follows:
--
-- > { "_links": { "curies": { "href": "https://docs.aws.amazon.com/apigateway/latest/developerguide/restapi-method-response-{rel}.html", "name": "methodresponse", "templated": true }, "self": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200", "title": "200" }, "methodresponse:delete": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200" }, "methodresponse:update": { "href": "/restapis/fugvjdxtri/resources/3kzxbg5sa2/methods/GET/responses/200" } }, "responseModels": { "application/json": "Empty" }, "responseParameters": { "method.response.header.Content-Type": false }, "statusCode": "200" }
--
-- Method, IntegrationResponse, Integration
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-create-api.html Creating an API>
--
-- /See:/ 'newMethodResponse' smart constructor.
data MethodResponse = MethodResponse'
  { -- | Specifies the Model resources used for the response\'s content-type.
    -- Response models are represented as a key\/value map, with a content-type
    -- as the key and a Model name as the value.
    MethodResponse -> Maybe (HashMap Text Text)
responseModels :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | The method response\'s status code.
    MethodResponse -> Maybe Text
statusCode :: Prelude.Maybe Prelude.Text,
    -- | A key-value map specifying required or optional response parameters that
    -- API Gateway can send back to the caller. A key defines a method response
    -- header and the value specifies whether the associated method response
    -- header is required or not. The expression of the key must match the
    -- pattern @method.response.header.{name}@, where @name@ is a valid and
    -- unique header name. API Gateway passes certain integration response data
    -- to the method response headers specified here according to the mapping
    -- you prescribe in the API\'s IntegrationResponse. The integration
    -- response data that can be mapped include an integration response header
    -- expressed in @integration.response.header.{name}@, a static value
    -- enclosed within a pair of single quotes (e.g., @\'application\/json\'@),
    -- or a JSON expression from the back-end response payload in the form of
    -- @integration.response.body.{JSON-expression}@, where @JSON-expression@
    -- is a valid JSON expression without the @$@ prefix.)
    MethodResponse -> Maybe (HashMap Text Bool)
responseParameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Bool)
  }
  deriving (MethodResponse -> MethodResponse -> Bool
(MethodResponse -> MethodResponse -> Bool)
-> (MethodResponse -> MethodResponse -> Bool) -> Eq MethodResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MethodResponse -> MethodResponse -> Bool
$c/= :: MethodResponse -> MethodResponse -> Bool
== :: MethodResponse -> MethodResponse -> Bool
$c== :: MethodResponse -> MethodResponse -> Bool
Prelude.Eq, ReadPrec [MethodResponse]
ReadPrec MethodResponse
Int -> ReadS MethodResponse
ReadS [MethodResponse]
(Int -> ReadS MethodResponse)
-> ReadS [MethodResponse]
-> ReadPrec MethodResponse
-> ReadPrec [MethodResponse]
-> Read MethodResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [MethodResponse]
$creadListPrec :: ReadPrec [MethodResponse]
readPrec :: ReadPrec MethodResponse
$creadPrec :: ReadPrec MethodResponse
readList :: ReadS [MethodResponse]
$creadList :: ReadS [MethodResponse]
readsPrec :: Int -> ReadS MethodResponse
$creadsPrec :: Int -> ReadS MethodResponse
Prelude.Read, Int -> MethodResponse -> ShowS
[MethodResponse] -> ShowS
MethodResponse -> String
(Int -> MethodResponse -> ShowS)
-> (MethodResponse -> String)
-> ([MethodResponse] -> ShowS)
-> Show MethodResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [MethodResponse] -> ShowS
$cshowList :: [MethodResponse] -> ShowS
show :: MethodResponse -> String
$cshow :: MethodResponse -> String
showsPrec :: Int -> MethodResponse -> ShowS
$cshowsPrec :: Int -> MethodResponse -> ShowS
Prelude.Show, (forall x. MethodResponse -> Rep MethodResponse x)
-> (forall x. Rep MethodResponse x -> MethodResponse)
-> Generic MethodResponse
forall x. Rep MethodResponse x -> MethodResponse
forall x. MethodResponse -> Rep MethodResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep MethodResponse x -> MethodResponse
$cfrom :: forall x. MethodResponse -> Rep MethodResponse x
Prelude.Generic)

-- |
-- Create a value of 'MethodResponse' 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:
--
-- 'responseModels', 'methodResponse_responseModels' - Specifies the Model resources used for the response\'s content-type.
-- Response models are represented as a key\/value map, with a content-type
-- as the key and a Model name as the value.
--
-- 'statusCode', 'methodResponse_statusCode' - The method response\'s status code.
--
-- 'responseParameters', 'methodResponse_responseParameters' - A key-value map specifying required or optional response parameters that
-- API Gateway can send back to the caller. A key defines a method response
-- header and the value specifies whether the associated method response
-- header is required or not. The expression of the key must match the
-- pattern @method.response.header.{name}@, where @name@ is a valid and
-- unique header name. API Gateway passes certain integration response data
-- to the method response headers specified here according to the mapping
-- you prescribe in the API\'s IntegrationResponse. The integration
-- response data that can be mapped include an integration response header
-- expressed in @integration.response.header.{name}@, a static value
-- enclosed within a pair of single quotes (e.g., @\'application\/json\'@),
-- or a JSON expression from the back-end response payload in the form of
-- @integration.response.body.{JSON-expression}@, where @JSON-expression@
-- is a valid JSON expression without the @$@ prefix.)
newMethodResponse ::
  MethodResponse
newMethodResponse :: MethodResponse
newMethodResponse =
  MethodResponse' :: Maybe (HashMap Text Text)
-> Maybe Text -> Maybe (HashMap Text Bool) -> MethodResponse
MethodResponse'
    { $sel:responseModels:MethodResponse' :: Maybe (HashMap Text Text)
responseModels = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:statusCode:MethodResponse' :: Maybe Text
statusCode = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:responseParameters:MethodResponse' :: Maybe (HashMap Text Bool)
responseParameters = Maybe (HashMap Text Bool)
forall a. Maybe a
Prelude.Nothing
    }

-- | Specifies the Model resources used for the response\'s content-type.
-- Response models are represented as a key\/value map, with a content-type
-- as the key and a Model name as the value.
methodResponse_responseModels :: Lens.Lens' MethodResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
methodResponse_responseModels :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> MethodResponse -> f MethodResponse
methodResponse_responseModels = (MethodResponse -> Maybe (HashMap Text Text))
-> (MethodResponse -> Maybe (HashMap Text Text) -> MethodResponse)
-> Lens
     MethodResponse
     MethodResponse
     (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 (\MethodResponse' {Maybe (HashMap Text Text)
responseModels :: Maybe (HashMap Text Text)
$sel:responseModels:MethodResponse' :: MethodResponse -> Maybe (HashMap Text Text)
responseModels} -> Maybe (HashMap Text Text)
responseModels) (\s :: MethodResponse
s@MethodResponse' {} Maybe (HashMap Text Text)
a -> MethodResponse
s {$sel:responseModels:MethodResponse' :: Maybe (HashMap Text Text)
responseModels = Maybe (HashMap Text Text)
a} :: MethodResponse) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> MethodResponse -> f MethodResponse)
-> ((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)))
-> MethodResponse
-> f MethodResponse
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 method response\'s status code.
methodResponse_statusCode :: Lens.Lens' MethodResponse (Prelude.Maybe Prelude.Text)
methodResponse_statusCode :: (Maybe Text -> f (Maybe Text))
-> MethodResponse -> f MethodResponse
methodResponse_statusCode = (MethodResponse -> Maybe Text)
-> (MethodResponse -> Maybe Text -> MethodResponse)
-> Lens MethodResponse MethodResponse (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MethodResponse' {Maybe Text
statusCode :: Maybe Text
$sel:statusCode:MethodResponse' :: MethodResponse -> Maybe Text
statusCode} -> Maybe Text
statusCode) (\s :: MethodResponse
s@MethodResponse' {} Maybe Text
a -> MethodResponse
s {$sel:statusCode:MethodResponse' :: Maybe Text
statusCode = Maybe Text
a} :: MethodResponse)

-- | A key-value map specifying required or optional response parameters that
-- API Gateway can send back to the caller. A key defines a method response
-- header and the value specifies whether the associated method response
-- header is required or not. The expression of the key must match the
-- pattern @method.response.header.{name}@, where @name@ is a valid and
-- unique header name. API Gateway passes certain integration response data
-- to the method response headers specified here according to the mapping
-- you prescribe in the API\'s IntegrationResponse. The integration
-- response data that can be mapped include an integration response header
-- expressed in @integration.response.header.{name}@, a static value
-- enclosed within a pair of single quotes (e.g., @\'application\/json\'@),
-- or a JSON expression from the back-end response payload in the form of
-- @integration.response.body.{JSON-expression}@, where @JSON-expression@
-- is a valid JSON expression without the @$@ prefix.)
methodResponse_responseParameters :: Lens.Lens' MethodResponse (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Bool))
methodResponse_responseParameters :: (Maybe (HashMap Text Bool) -> f (Maybe (HashMap Text Bool)))
-> MethodResponse -> f MethodResponse
methodResponse_responseParameters = (MethodResponse -> Maybe (HashMap Text Bool))
-> (MethodResponse -> Maybe (HashMap Text Bool) -> MethodResponse)
-> Lens
     MethodResponse
     MethodResponse
     (Maybe (HashMap Text Bool))
     (Maybe (HashMap Text Bool))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\MethodResponse' {Maybe (HashMap Text Bool)
responseParameters :: Maybe (HashMap Text Bool)
$sel:responseParameters:MethodResponse' :: MethodResponse -> Maybe (HashMap Text Bool)
responseParameters} -> Maybe (HashMap Text Bool)
responseParameters) (\s :: MethodResponse
s@MethodResponse' {} Maybe (HashMap Text Bool)
a -> MethodResponse
s {$sel:responseParameters:MethodResponse' :: Maybe (HashMap Text Bool)
responseParameters = Maybe (HashMap Text Bool)
a} :: MethodResponse) ((Maybe (HashMap Text Bool) -> f (Maybe (HashMap Text Bool)))
 -> MethodResponse -> f MethodResponse)
-> ((Maybe (HashMap Text Bool) -> f (Maybe (HashMap Text Bool)))
    -> Maybe (HashMap Text Bool) -> f (Maybe (HashMap Text Bool)))
-> (Maybe (HashMap Text Bool) -> f (Maybe (HashMap Text Bool)))
-> MethodResponse
-> f MethodResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (HashMap Text Bool)
  (HashMap Text Bool)
  (HashMap Text Bool)
  (HashMap Text Bool)
-> Iso
     (Maybe (HashMap Text Bool))
     (Maybe (HashMap Text Bool))
     (Maybe (HashMap Text Bool))
     (Maybe (HashMap Text Bool))
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 Bool)
  (HashMap Text Bool)
  (HashMap Text Bool)
  (HashMap Text Bool)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON MethodResponse where
  parseJSON :: Value -> Parser MethodResponse
parseJSON =
    String
-> (Object -> Parser MethodResponse)
-> Value
-> Parser MethodResponse
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"MethodResponse"
      ( \Object
x ->
          Maybe (HashMap Text Text)
-> Maybe Text -> Maybe (HashMap Text Bool) -> MethodResponse
MethodResponse'
            (Maybe (HashMap Text Text)
 -> Maybe Text -> Maybe (HashMap Text Bool) -> MethodResponse)
-> Parser (Maybe (HashMap Text Text))
-> Parser
     (Maybe Text -> Maybe (HashMap Text Bool) -> MethodResponse)
forall (f :: * -> *) a b. Functor 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
"responseModels" 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 Text -> Maybe (HashMap Text Bool) -> MethodResponse)
-> Parser (Maybe Text)
-> Parser (Maybe (HashMap Text Bool) -> MethodResponse)
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 Bool) -> MethodResponse)
-> Parser (Maybe (HashMap Text Bool)) -> Parser MethodResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x Object -> Text -> Parser (Maybe (Maybe (HashMap Text Bool)))
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"responseParameters"
                            Parser (Maybe (Maybe (HashMap Text Bool)))
-> Maybe (HashMap Text Bool) -> Parser (Maybe (HashMap Text Bool))
forall a. Parser (Maybe a) -> a -> Parser a
Core..!= Maybe (HashMap Text Bool)
forall a. Monoid a => a
Prelude.mempty
                        )
      )

instance Prelude.Hashable MethodResponse

instance Prelude.NFData MethodResponse