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

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

-- | A set of validation rules for incoming Method requests.
--
-- In OpenAPI, a RequestValidator of an API is defined by the
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html#api-gateway-swagger-extensions-request-validators.requestValidator.html x-amazon-apigateway-request-validators.requestValidator>
-- object. It the referenced using the
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-swagger-extensions.html#api-gateway-swagger-extensions-request-validator x-amazon-apigateway-request-validator>
-- property.
--
-- <https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-method-request-validation.html Enable Basic Request Validation in API Gateway>
--
-- /See:/ 'newRequestValidator' smart constructor.
data RequestValidator = RequestValidator'
  { -- | A Boolean flag to indicate whether to validate request parameters
    -- (@true@) or not (@false@).
    RequestValidator -> Maybe Bool
validateRequestParameters :: Prelude.Maybe Prelude.Bool,
    -- | The name of this RequestValidator
    RequestValidator -> Maybe Text
name :: Prelude.Maybe Prelude.Text,
    -- | A Boolean flag to indicate whether to validate a request body according
    -- to the configured Model schema.
    RequestValidator -> Maybe Bool
validateRequestBody :: Prelude.Maybe Prelude.Bool,
    -- | The identifier of this RequestValidator.
    RequestValidator -> Maybe Text
id :: Prelude.Maybe Prelude.Text
  }
  deriving (RequestValidator -> RequestValidator -> Bool
(RequestValidator -> RequestValidator -> Bool)
-> (RequestValidator -> RequestValidator -> Bool)
-> Eq RequestValidator
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RequestValidator -> RequestValidator -> Bool
$c/= :: RequestValidator -> RequestValidator -> Bool
== :: RequestValidator -> RequestValidator -> Bool
$c== :: RequestValidator -> RequestValidator -> Bool
Prelude.Eq, ReadPrec [RequestValidator]
ReadPrec RequestValidator
Int -> ReadS RequestValidator
ReadS [RequestValidator]
(Int -> ReadS RequestValidator)
-> ReadS [RequestValidator]
-> ReadPrec RequestValidator
-> ReadPrec [RequestValidator]
-> Read RequestValidator
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RequestValidator]
$creadListPrec :: ReadPrec [RequestValidator]
readPrec :: ReadPrec RequestValidator
$creadPrec :: ReadPrec RequestValidator
readList :: ReadS [RequestValidator]
$creadList :: ReadS [RequestValidator]
readsPrec :: Int -> ReadS RequestValidator
$creadsPrec :: Int -> ReadS RequestValidator
Prelude.Read, Int -> RequestValidator -> ShowS
[RequestValidator] -> ShowS
RequestValidator -> String
(Int -> RequestValidator -> ShowS)
-> (RequestValidator -> String)
-> ([RequestValidator] -> ShowS)
-> Show RequestValidator
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RequestValidator] -> ShowS
$cshowList :: [RequestValidator] -> ShowS
show :: RequestValidator -> String
$cshow :: RequestValidator -> String
showsPrec :: Int -> RequestValidator -> ShowS
$cshowsPrec :: Int -> RequestValidator -> ShowS
Prelude.Show, (forall x. RequestValidator -> Rep RequestValidator x)
-> (forall x. Rep RequestValidator x -> RequestValidator)
-> Generic RequestValidator
forall x. Rep RequestValidator x -> RequestValidator
forall x. RequestValidator -> Rep RequestValidator x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RequestValidator x -> RequestValidator
$cfrom :: forall x. RequestValidator -> Rep RequestValidator x
Prelude.Generic)

-- |
-- Create a value of 'RequestValidator' 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', 'requestValidator_validateRequestParameters' - A Boolean flag to indicate whether to validate request parameters
-- (@true@) or not (@false@).
--
-- 'name', 'requestValidator_name' - The name of this RequestValidator
--
-- 'validateRequestBody', 'requestValidator_validateRequestBody' - A Boolean flag to indicate whether to validate a request body according
-- to the configured Model schema.
--
-- 'id', 'requestValidator_id' - The identifier of this RequestValidator.
newRequestValidator ::
  RequestValidator
newRequestValidator :: RequestValidator
newRequestValidator =
  RequestValidator' :: Maybe Bool
-> Maybe Text -> Maybe Bool -> Maybe Text -> RequestValidator
RequestValidator'
    { $sel:validateRequestParameters:RequestValidator' :: Maybe Bool
validateRequestParameters =
        Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:name:RequestValidator' :: Maybe Text
name = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:validateRequestBody:RequestValidator' :: Maybe Bool
validateRequestBody = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:id:RequestValidator' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing
    }

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

-- | The name of this RequestValidator
requestValidator_name :: Lens.Lens' RequestValidator (Prelude.Maybe Prelude.Text)
requestValidator_name :: (Maybe Text -> f (Maybe Text))
-> RequestValidator -> f RequestValidator
requestValidator_name = (RequestValidator -> Maybe Text)
-> (RequestValidator -> Maybe Text -> RequestValidator)
-> Lens RequestValidator RequestValidator (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestValidator' {Maybe Text
name :: Maybe Text
$sel:name:RequestValidator' :: RequestValidator -> Maybe Text
name} -> Maybe Text
name) (\s :: RequestValidator
s@RequestValidator' {} Maybe Text
a -> RequestValidator
s {$sel:name:RequestValidator' :: Maybe Text
name = Maybe Text
a} :: RequestValidator)

-- | A Boolean flag to indicate whether to validate a request body according
-- to the configured Model schema.
requestValidator_validateRequestBody :: Lens.Lens' RequestValidator (Prelude.Maybe Prelude.Bool)
requestValidator_validateRequestBody :: (Maybe Bool -> f (Maybe Bool))
-> RequestValidator -> f RequestValidator
requestValidator_validateRequestBody = (RequestValidator -> Maybe Bool)
-> (RequestValidator -> Maybe Bool -> RequestValidator)
-> Lens RequestValidator RequestValidator (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestValidator' {Maybe Bool
validateRequestBody :: Maybe Bool
$sel:validateRequestBody:RequestValidator' :: RequestValidator -> Maybe Bool
validateRequestBody} -> Maybe Bool
validateRequestBody) (\s :: RequestValidator
s@RequestValidator' {} Maybe Bool
a -> RequestValidator
s {$sel:validateRequestBody:RequestValidator' :: Maybe Bool
validateRequestBody = Maybe Bool
a} :: RequestValidator)

-- | The identifier of this RequestValidator.
requestValidator_id :: Lens.Lens' RequestValidator (Prelude.Maybe Prelude.Text)
requestValidator_id :: (Maybe Text -> f (Maybe Text))
-> RequestValidator -> f RequestValidator
requestValidator_id = (RequestValidator -> Maybe Text)
-> (RequestValidator -> Maybe Text -> RequestValidator)
-> Lens RequestValidator RequestValidator (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RequestValidator' {Maybe Text
id :: Maybe Text
$sel:id:RequestValidator' :: RequestValidator -> Maybe Text
id} -> Maybe Text
id) (\s :: RequestValidator
s@RequestValidator' {} Maybe Text
a -> RequestValidator
s {$sel:id:RequestValidator' :: Maybe Text
id = Maybe Text
a} :: RequestValidator)

instance Core.FromJSON RequestValidator where
  parseJSON :: Value -> Parser RequestValidator
parseJSON =
    String
-> (Object -> Parser RequestValidator)
-> Value
-> Parser RequestValidator
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RequestValidator"
      ( \Object
x ->
          Maybe Bool
-> Maybe Text -> Maybe Bool -> Maybe Text -> RequestValidator
RequestValidator'
            (Maybe Bool
 -> Maybe Text -> Maybe Bool -> Maybe Text -> RequestValidator)
-> Parser (Maybe Bool)
-> Parser
     (Maybe Text -> Maybe Bool -> Maybe Text -> RequestValidator)
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
"validateRequestParameters")
            Parser (Maybe Text -> Maybe Bool -> Maybe Text -> RequestValidator)
-> Parser (Maybe Text)
-> Parser (Maybe Bool -> Maybe Text -> RequestValidator)
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
"name")
            Parser (Maybe Bool -> Maybe Text -> RequestValidator)
-> Parser (Maybe Bool) -> Parser (Maybe Text -> RequestValidator)
forall (f :: * -> *) a b. Applicative f => 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
"validateRequestBody")
            Parser (Maybe Text -> RequestValidator)
-> Parser (Maybe Text) -> Parser RequestValidator
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
"id")
      )

instance Prelude.Hashable RequestValidator

instance Prelude.NFData RequestValidator