{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# 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.CreateRequestValidator
-- 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)
--
-- Creates a ReqeustValidator of a given RestApi.
module Amazonka.APIGateway.CreateRequestValidator
  ( -- * Creating a Request
    CreateRequestValidator (..),
    newCreateRequestValidator,

    -- * Request Lenses
    createRequestValidator_validateRequestParameters,
    createRequestValidator_name,
    createRequestValidator_validateRequestBody,
    createRequestValidator_restApiId,

    -- * Destructuring the Response
    RequestValidator (..),
    newRequestValidator,

    -- * Response Lenses
    requestValidator_validateRequestParameters,
    requestValidator_name,
    requestValidator_validateRequestBody,
    requestValidator_id,
  )
where

import Amazonka.APIGateway.Types
import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | Creates a RequestValidator of a given RestApi.
--
-- /See:/ 'newCreateRequestValidator' smart constructor.
data CreateRequestValidator = CreateRequestValidator'
  { -- | A Boolean flag to indicate whether to validate request parameters,
    -- @true@, or not @false@.
    CreateRequestValidator -> Maybe Bool
validateRequestParameters :: Prelude.Maybe Prelude.Bool,
    -- | The name of the to-be-created RequestValidator.
    CreateRequestValidator -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A Boolean flag to indicate whether to validate request body according to
    -- the configured model schema for the method (@true@) or not (@false@).
    CreateRequestValidator -> Maybe Bool
validateRequestBody :: Prelude.Maybe Prelude.Bool,
    -- | [Required] The string identifier of the associated RestApi.
    CreateRequestValidator -> Text
restApiId :: Prelude.Text
  }
  deriving (CreateRequestValidator -> CreateRequestValidator -> Bool
(CreateRequestValidator -> CreateRequestValidator -> Bool)
-> (CreateRequestValidator -> CreateRequestValidator -> Bool)
-> Eq CreateRequestValidator
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: CreateRequestValidator -> CreateRequestValidator -> Bool
$c/= :: CreateRequestValidator -> CreateRequestValidator -> Bool
== :: CreateRequestValidator -> CreateRequestValidator -> Bool
$c== :: CreateRequestValidator -> CreateRequestValidator -> Bool
Prelude.Eq, ReadPrec [CreateRequestValidator]
ReadPrec CreateRequestValidator
Int -> ReadS CreateRequestValidator
ReadS [CreateRequestValidator]
(Int -> ReadS CreateRequestValidator)
-> ReadS [CreateRequestValidator]
-> ReadPrec CreateRequestValidator
-> ReadPrec [CreateRequestValidator]
-> Read CreateRequestValidator
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [CreateRequestValidator]
$creadListPrec :: ReadPrec [CreateRequestValidator]
readPrec :: ReadPrec CreateRequestValidator
$creadPrec :: ReadPrec CreateRequestValidator
readList :: ReadS [CreateRequestValidator]
$creadList :: ReadS [CreateRequestValidator]
readsPrec :: Int -> ReadS CreateRequestValidator
$creadsPrec :: Int -> ReadS CreateRequestValidator
Prelude.Read, Int -> CreateRequestValidator -> ShowS
[CreateRequestValidator] -> ShowS
CreateRequestValidator -> String
(Int -> CreateRequestValidator -> ShowS)
-> (CreateRequestValidator -> String)
-> ([CreateRequestValidator] -> ShowS)
-> Show CreateRequestValidator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [CreateRequestValidator] -> ShowS
$cshowList :: [CreateRequestValidator] -> ShowS
show :: CreateRequestValidator -> String
$cshow :: CreateRequestValidator -> String
showsPrec :: Int -> CreateRequestValidator -> ShowS
$cshowsPrec :: Int -> CreateRequestValidator -> ShowS
Prelude.Show, (forall x. CreateRequestValidator -> Rep CreateRequestValidator x)
-> (forall x.
    Rep CreateRequestValidator x -> CreateRequestValidator)
-> Generic CreateRequestValidator
forall x. Rep CreateRequestValidator x -> CreateRequestValidator
forall x. CreateRequestValidator -> Rep CreateRequestValidator x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep CreateRequestValidator x -> CreateRequestValidator
$cfrom :: forall x. CreateRequestValidator -> Rep CreateRequestValidator x
Prelude.Generic)

-- |
-- Create a value of 'CreateRequestValidator' 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:
--
-- 'validateRequestParameters', 'createRequestValidator_validateRequestParameters' - A Boolean flag to indicate whether to validate request parameters,
-- @true@, or not @false@.
--
-- 'name', 'createRequestValidator_name' - The name of the to-be-created RequestValidator.
--
-- 'validateRequestBody', 'createRequestValidator_validateRequestBody' - A Boolean flag to indicate whether to validate request body according to
-- the configured model schema for the method (@true@) or not (@false@).
--
-- 'restApiId', 'createRequestValidator_restApiId' - [Required] The string identifier of the associated RestApi.
newCreateRequestValidator ::
  -- | 'restApiId'
  Prelude.Text ->
  CreateRequestValidator
newCreateRequestValidator :: Text -> CreateRequestValidator
newCreateRequestValidator Text
pRestApiId_ =
  CreateRequestValidator' :: Maybe Bool
-> Maybe Text -> Maybe Bool -> Text -> CreateRequestValidator
CreateRequestValidator'
    { $sel:validateRequestParameters:CreateRequestValidator' :: Maybe Bool
validateRequestParameters =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:name:CreateRequestValidator' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:validateRequestBody:CreateRequestValidator' :: Maybe Bool
validateRequestBody = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:CreateRequestValidator' :: Text
restApiId = Text
pRestApiId_
    }

-- | A Boolean flag to indicate whether to validate request parameters,
-- @true@, or not @false@.
createRequestValidator_validateRequestParameters :: Lens.Lens' CreateRequestValidator (Prelude.Maybe Prelude.Bool)
createRequestValidator_validateRequestParameters :: (Maybe Bool -> f (Maybe Bool))
-> CreateRequestValidator -> f CreateRequestValidator
createRequestValidator_validateRequestParameters = (CreateRequestValidator -> Maybe Bool)
-> (CreateRequestValidator -> Maybe Bool -> CreateRequestValidator)
-> Lens
     CreateRequestValidator
     CreateRequestValidator
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRequestValidator' {Maybe Bool
validateRequestParameters :: Maybe Bool
$sel:validateRequestParameters:CreateRequestValidator' :: CreateRequestValidator -> Maybe Bool
validateRequestParameters} -> Maybe Bool
validateRequestParameters) (\s :: CreateRequestValidator
s@CreateRequestValidator' {} Maybe Bool
a -> CreateRequestValidator
s {$sel:validateRequestParameters:CreateRequestValidator' :: Maybe Bool
validateRequestParameters = Maybe Bool
a} :: CreateRequestValidator)

-- | The name of the to-be-created RequestValidator.
createRequestValidator_name :: Lens.Lens' CreateRequestValidator (Prelude.Maybe Prelude.Text)
createRequestValidator_name :: (Maybe Text -> f (Maybe Text))
-> CreateRequestValidator -> f CreateRequestValidator
createRequestValidator_name = (CreateRequestValidator -> Maybe Text)
-> (CreateRequestValidator -> Maybe Text -> CreateRequestValidator)
-> Lens
     CreateRequestValidator
     CreateRequestValidator
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRequestValidator' {Maybe Text
name :: Maybe Text
$sel:name:CreateRequestValidator' :: CreateRequestValidator -> Maybe Text
name} -> Maybe Text
name) (\s :: CreateRequestValidator
s@CreateRequestValidator' {} Maybe Text
a -> CreateRequestValidator
s {$sel:name:CreateRequestValidator' :: Maybe Text
name = Maybe Text
a} :: CreateRequestValidator)

-- | A Boolean flag to indicate whether to validate request body according to
-- the configured model schema for the method (@true@) or not (@false@).
createRequestValidator_validateRequestBody :: Lens.Lens' CreateRequestValidator (Prelude.Maybe Prelude.Bool)
createRequestValidator_validateRequestBody :: (Maybe Bool -> f (Maybe Bool))
-> CreateRequestValidator -> f CreateRequestValidator
createRequestValidator_validateRequestBody = (CreateRequestValidator -> Maybe Bool)
-> (CreateRequestValidator -> Maybe Bool -> CreateRequestValidator)
-> Lens
     CreateRequestValidator
     CreateRequestValidator
     (Maybe Bool)
     (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRequestValidator' {Maybe Bool
validateRequestBody :: Maybe Bool
$sel:validateRequestBody:CreateRequestValidator' :: CreateRequestValidator -> Maybe Bool
validateRequestBody} -> Maybe Bool
validateRequestBody) (\s :: CreateRequestValidator
s@CreateRequestValidator' {} Maybe Bool
a -> CreateRequestValidator
s {$sel:validateRequestBody:CreateRequestValidator' :: Maybe Bool
validateRequestBody = Maybe Bool
a} :: CreateRequestValidator)

-- | [Required] The string identifier of the associated RestApi.
createRequestValidator_restApiId :: Lens.Lens' CreateRequestValidator Prelude.Text
createRequestValidator_restApiId :: (Text -> f Text)
-> CreateRequestValidator -> f CreateRequestValidator
createRequestValidator_restApiId = (CreateRequestValidator -> Text)
-> (CreateRequestValidator -> Text -> CreateRequestValidator)
-> Lens CreateRequestValidator CreateRequestValidator Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\CreateRequestValidator' {Text
restApiId :: Text
$sel:restApiId:CreateRequestValidator' :: CreateRequestValidator -> Text
restApiId} -> Text
restApiId) (\s :: CreateRequestValidator
s@CreateRequestValidator' {} Text
a -> CreateRequestValidator
s {$sel:restApiId:CreateRequestValidator' :: Text
restApiId = Text
a} :: CreateRequestValidator)

instance Core.AWSRequest CreateRequestValidator where
  type
    AWSResponse CreateRequestValidator =
      RequestValidator
  request :: CreateRequestValidator -> Request CreateRequestValidator
request = Service -> CreateRequestValidator -> Request CreateRequestValidator
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy CreateRequestValidator
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateRequestValidator)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse CreateRequestValidator))
-> Logger
-> Service
-> Proxy CreateRequestValidator
-> ClientResponse ClientBody
-> m (Either
        Error (ClientResponse (AWSResponse CreateRequestValidator)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      (\Int
s ResponseHeaders
h Object
x -> Object -> Either String RequestValidator
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable CreateRequestValidator

instance Prelude.NFData CreateRequestValidator

instance Core.ToHeaders CreateRequestValidator where
  toHeaders :: CreateRequestValidator -> ResponseHeaders
toHeaders =
    ResponseHeaders -> CreateRequestValidator -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Accept"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# (ByteString
"application/json" :: Prelude.ByteString)
          ]
      )

instance Core.ToJSON CreateRequestValidator where
  toJSON :: CreateRequestValidator -> Value
toJSON CreateRequestValidator' {Maybe Bool
Maybe Text
Text
restApiId :: Text
validateRequestBody :: Maybe Bool
name :: Maybe Text
validateRequestParameters :: Maybe Bool
$sel:restApiId:CreateRequestValidator' :: CreateRequestValidator -> Text
$sel:validateRequestBody:CreateRequestValidator' :: CreateRequestValidator -> Maybe Bool
$sel:name:CreateRequestValidator' :: CreateRequestValidator -> Maybe Text
$sel:validateRequestParameters:CreateRequestValidator' :: CreateRequestValidator -> Maybe Bool
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"validateRequestParameters" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
validateRequestParameters,
            (Text
"name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
name,
            (Text
"validateRequestBody" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=)
              (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
validateRequestBody
          ]
      )

instance Core.ToPath CreateRequestValidator where
  toPath :: CreateRequestValidator -> ByteString
toPath CreateRequestValidator' {Maybe Bool
Maybe Text
Text
restApiId :: Text
validateRequestBody :: Maybe Bool
name :: Maybe Text
validateRequestParameters :: Maybe Bool
$sel:restApiId:CreateRequestValidator' :: CreateRequestValidator -> Text
$sel:validateRequestBody:CreateRequestValidator' :: CreateRequestValidator -> Maybe Bool
$sel:name:CreateRequestValidator' :: CreateRequestValidator -> Maybe Text
$sel:validateRequestParameters:CreateRequestValidator' :: CreateRequestValidator -> Maybe Bool
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"/restapis/",
        Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
restApiId,
        ByteString
"/requestvalidators"
      ]

instance Core.ToQuery CreateRequestValidator where
  toQuery :: CreateRequestValidator -> QueryString
toQuery = QueryString -> CreateRequestValidator -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty