{-# 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.PutRestApi
-- 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)
--
-- A feature of the API Gateway control service for updating an existing
-- API with an input of external API definitions. The update can take the
-- form of merging the supplied definition into the existing API or
-- overwriting the existing API.
module Amazonka.APIGateway.PutRestApi
  ( -- * Creating a Request
    PutRestApi (..),
    newPutRestApi,

    -- * Request Lenses
    putRestApi_mode,
    putRestApi_failOnWarnings,
    putRestApi_parameters,
    putRestApi_restApiId,
    putRestApi_body,

    -- * Destructuring the Response
    RestApi (..),
    newRestApi,

    -- * Response Lenses
    restApi_minimumCompressionSize,
    restApi_disableExecuteApiEndpoint,
    restApi_binaryMediaTypes,
    restApi_warnings,
    restApi_createdDate,
    restApi_name,
    restApi_version,
    restApi_apiKeySource,
    restApi_id,
    restApi_policy,
    restApi_endpointConfiguration,
    restApi_description,
    restApi_tags,
  )
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

-- | A PUT request to update an existing API, with external API definitions
-- specified as the request body.
--
-- /See:/ 'newPutRestApi' smart constructor.
data PutRestApi = PutRestApi'
  { -- | The @mode@ query parameter to specify the update mode. Valid values are
    -- \"merge\" and \"overwrite\". By default, the update mode is \"merge\".
    PutRestApi -> Maybe PutMode
mode :: Prelude.Maybe PutMode,
    -- | A query parameter to indicate whether to rollback the API update
    -- (@true@) or not (@false@) when a warning is encountered. The default
    -- value is @false@.
    PutRestApi -> Maybe Bool
failOnWarnings :: Prelude.Maybe Prelude.Bool,
    -- | Custom header parameters as part of the request. For example, to exclude
    -- DocumentationParts from an imported API, set @ignore=documentation@ as a
    -- @parameters@ value, as in the AWS CLI command of
    -- @aws apigateway import-rest-api --parameters ignore=documentation --body \'file:\/\/\/path\/to\/imported-api-body.json\'@.
    PutRestApi -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | [Required] The string identifier of the associated RestApi.
    PutRestApi -> Text
restApiId :: Prelude.Text,
    -- | [Required] The PUT request body containing external API definitions.
    -- Currently, only OpenAPI definition JSON\/YAML files are supported. The
    -- maximum size of the API definition file is 6MB.
    PutRestApi -> ByteString
body :: Prelude.ByteString
  }
  deriving (PutRestApi -> PutRestApi -> Bool
(PutRestApi -> PutRestApi -> Bool)
-> (PutRestApi -> PutRestApi -> Bool) -> Eq PutRestApi
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PutRestApi -> PutRestApi -> Bool
$c/= :: PutRestApi -> PutRestApi -> Bool
== :: PutRestApi -> PutRestApi -> Bool
$c== :: PutRestApi -> PutRestApi -> Bool
Prelude.Eq, Int -> PutRestApi -> ShowS
[PutRestApi] -> ShowS
PutRestApi -> String
(Int -> PutRestApi -> ShowS)
-> (PutRestApi -> String)
-> ([PutRestApi] -> ShowS)
-> Show PutRestApi
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PutRestApi] -> ShowS
$cshowList :: [PutRestApi] -> ShowS
show :: PutRestApi -> String
$cshow :: PutRestApi -> String
showsPrec :: Int -> PutRestApi -> ShowS
$cshowsPrec :: Int -> PutRestApi -> ShowS
Prelude.Show, (forall x. PutRestApi -> Rep PutRestApi x)
-> (forall x. Rep PutRestApi x -> PutRestApi) -> Generic PutRestApi
forall x. Rep PutRestApi x -> PutRestApi
forall x. PutRestApi -> Rep PutRestApi x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PutRestApi x -> PutRestApi
$cfrom :: forall x. PutRestApi -> Rep PutRestApi x
Prelude.Generic)

-- |
-- Create a value of 'PutRestApi' 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:
--
-- 'mode', 'putRestApi_mode' - The @mode@ query parameter to specify the update mode. Valid values are
-- \"merge\" and \"overwrite\". By default, the update mode is \"merge\".
--
-- 'failOnWarnings', 'putRestApi_failOnWarnings' - A query parameter to indicate whether to rollback the API update
-- (@true@) or not (@false@) when a warning is encountered. The default
-- value is @false@.
--
-- 'parameters', 'putRestApi_parameters' - Custom header parameters as part of the request. For example, to exclude
-- DocumentationParts from an imported API, set @ignore=documentation@ as a
-- @parameters@ value, as in the AWS CLI command of
-- @aws apigateway import-rest-api --parameters ignore=documentation --body \'file:\/\/\/path\/to\/imported-api-body.json\'@.
--
-- 'restApiId', 'putRestApi_restApiId' - [Required] The string identifier of the associated RestApi.
--
-- 'body', 'putRestApi_body' - [Required] The PUT request body containing external API definitions.
-- Currently, only OpenAPI definition JSON\/YAML files are supported. The
-- maximum size of the API definition file is 6MB.
newPutRestApi ::
  -- | 'restApiId'
  Prelude.Text ->
  -- | 'body'
  Prelude.ByteString ->
  PutRestApi
newPutRestApi :: Text -> ByteString -> PutRestApi
newPutRestApi Text
pRestApiId_ ByteString
pBody_ =
  PutRestApi' :: Maybe PutMode
-> Maybe Bool
-> Maybe (HashMap Text Text)
-> Text
-> ByteString
-> PutRestApi
PutRestApi'
    { $sel:mode:PutRestApi' :: Maybe PutMode
mode = Maybe PutMode
forall a. Maybe a
Prelude.Nothing,
      $sel:failOnWarnings:PutRestApi' :: Maybe Bool
failOnWarnings = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:parameters:PutRestApi' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:restApiId:PutRestApi' :: Text
restApiId = Text
pRestApiId_,
      $sel:body:PutRestApi' :: ByteString
body = ByteString
pBody_
    }

-- | The @mode@ query parameter to specify the update mode. Valid values are
-- \"merge\" and \"overwrite\". By default, the update mode is \"merge\".
putRestApi_mode :: Lens.Lens' PutRestApi (Prelude.Maybe PutMode)
putRestApi_mode :: (Maybe PutMode -> f (Maybe PutMode)) -> PutRestApi -> f PutRestApi
putRestApi_mode = (PutRestApi -> Maybe PutMode)
-> (PutRestApi -> Maybe PutMode -> PutRestApi)
-> Lens PutRestApi PutRestApi (Maybe PutMode) (Maybe PutMode)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRestApi' {Maybe PutMode
mode :: Maybe PutMode
$sel:mode:PutRestApi' :: PutRestApi -> Maybe PutMode
mode} -> Maybe PutMode
mode) (\s :: PutRestApi
s@PutRestApi' {} Maybe PutMode
a -> PutRestApi
s {$sel:mode:PutRestApi' :: Maybe PutMode
mode = Maybe PutMode
a} :: PutRestApi)

-- | A query parameter to indicate whether to rollback the API update
-- (@true@) or not (@false@) when a warning is encountered. The default
-- value is @false@.
putRestApi_failOnWarnings :: Lens.Lens' PutRestApi (Prelude.Maybe Prelude.Bool)
putRestApi_failOnWarnings :: (Maybe Bool -> f (Maybe Bool)) -> PutRestApi -> f PutRestApi
putRestApi_failOnWarnings = (PutRestApi -> Maybe Bool)
-> (PutRestApi -> Maybe Bool -> PutRestApi)
-> Lens PutRestApi PutRestApi (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRestApi' {Maybe Bool
failOnWarnings :: Maybe Bool
$sel:failOnWarnings:PutRestApi' :: PutRestApi -> Maybe Bool
failOnWarnings} -> Maybe Bool
failOnWarnings) (\s :: PutRestApi
s@PutRestApi' {} Maybe Bool
a -> PutRestApi
s {$sel:failOnWarnings:PutRestApi' :: Maybe Bool
failOnWarnings = Maybe Bool
a} :: PutRestApi)

-- | Custom header parameters as part of the request. For example, to exclude
-- DocumentationParts from an imported API, set @ignore=documentation@ as a
-- @parameters@ value, as in the AWS CLI command of
-- @aws apigateway import-rest-api --parameters ignore=documentation --body \'file:\/\/\/path\/to\/imported-api-body.json\'@.
putRestApi_parameters :: Lens.Lens' PutRestApi (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
putRestApi_parameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> PutRestApi -> f PutRestApi
putRestApi_parameters = (PutRestApi -> Maybe (HashMap Text Text))
-> (PutRestApi -> Maybe (HashMap Text Text) -> PutRestApi)
-> Lens
     PutRestApi
     PutRestApi
     (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 (\PutRestApi' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:PutRestApi' :: PutRestApi -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: PutRestApi
s@PutRestApi' {} Maybe (HashMap Text Text)
a -> PutRestApi
s {$sel:parameters:PutRestApi' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: PutRestApi) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> PutRestApi -> f PutRestApi)
-> ((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)))
-> PutRestApi
-> f PutRestApi
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

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

-- | [Required] The PUT request body containing external API definitions.
-- Currently, only OpenAPI definition JSON\/YAML files are supported. The
-- maximum size of the API definition file is 6MB.
putRestApi_body :: Lens.Lens' PutRestApi Prelude.ByteString
putRestApi_body :: (ByteString -> f ByteString) -> PutRestApi -> f PutRestApi
putRestApi_body = (PutRestApi -> ByteString)
-> (PutRestApi -> ByteString -> PutRestApi)
-> Lens PutRestApi PutRestApi ByteString ByteString
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\PutRestApi' {ByteString
body :: ByteString
$sel:body:PutRestApi' :: PutRestApi -> ByteString
body} -> ByteString
body) (\s :: PutRestApi
s@PutRestApi' {} ByteString
a -> PutRestApi
s {$sel:body:PutRestApi' :: ByteString
body = ByteString
a} :: PutRestApi)

instance Core.AWSRequest PutRestApi where
  type AWSResponse PutRestApi = RestApi
  request :: PutRestApi -> Request PutRestApi
request = Service -> PutRestApi -> Request PutRestApi
forall a. (ToRequest a, ToBody a) => Service -> a -> Request a
Request.putBody Service
defaultService
  response :: Logger
-> Service
-> Proxy PutRestApi
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutRestApi)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse PutRestApi))
-> Logger
-> Service
-> Proxy PutRestApi
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse PutRestApi)))
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 RestApi
forall a. FromJSON a => Object -> Either String a
Core.eitherParseJSON Object
x)

instance Prelude.Hashable PutRestApi

instance Prelude.NFData PutRestApi

instance Core.ToBody PutRestApi where
  toBody :: PutRestApi -> RequestBody
toBody PutRestApi' {Maybe Bool
Maybe (HashMap Text Text)
Maybe PutMode
ByteString
Text
body :: ByteString
restApiId :: Text
parameters :: Maybe (HashMap Text Text)
failOnWarnings :: Maybe Bool
mode :: Maybe PutMode
$sel:body:PutRestApi' :: PutRestApi -> ByteString
$sel:restApiId:PutRestApi' :: PutRestApi -> Text
$sel:parameters:PutRestApi' :: PutRestApi -> Maybe (HashMap Text Text)
$sel:failOnWarnings:PutRestApi' :: PutRestApi -> Maybe Bool
$sel:mode:PutRestApi' :: PutRestApi -> Maybe PutMode
..} = ByteString -> RequestBody
forall a. ToBody a => a -> RequestBody
Core.toBody ByteString
body

instance Core.ToHeaders PutRestApi where
  toHeaders :: PutRestApi -> ResponseHeaders
toHeaders =
    ResponseHeaders -> PutRestApi -> 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.ToPath PutRestApi where
  toPath :: PutRestApi -> ByteString
toPath PutRestApi' {Maybe Bool
Maybe (HashMap Text Text)
Maybe PutMode
ByteString
Text
body :: ByteString
restApiId :: Text
parameters :: Maybe (HashMap Text Text)
failOnWarnings :: Maybe Bool
mode :: Maybe PutMode
$sel:body:PutRestApi' :: PutRestApi -> ByteString
$sel:restApiId:PutRestApi' :: PutRestApi -> Text
$sel:parameters:PutRestApi' :: PutRestApi -> Maybe (HashMap Text Text)
$sel:failOnWarnings:PutRestApi' :: PutRestApi -> Maybe Bool
$sel:mode:PutRestApi' :: PutRestApi -> Maybe PutMode
..} =
    [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
Prelude.mconcat [ByteString
"/restapis/", Text -> ByteString
forall a. ToByteString a => a -> ByteString
Core.toBS Text
restApiId]

instance Core.ToQuery PutRestApi where
  toQuery :: PutRestApi -> QueryString
toQuery PutRestApi' {Maybe Bool
Maybe (HashMap Text Text)
Maybe PutMode
ByteString
Text
body :: ByteString
restApiId :: Text
parameters :: Maybe (HashMap Text Text)
failOnWarnings :: Maybe Bool
mode :: Maybe PutMode
$sel:body:PutRestApi' :: PutRestApi -> ByteString
$sel:restApiId:PutRestApi' :: PutRestApi -> Text
$sel:parameters:PutRestApi' :: PutRestApi -> Maybe (HashMap Text Text)
$sel:failOnWarnings:PutRestApi' :: PutRestApi -> Maybe Bool
$sel:mode:PutRestApi' :: PutRestApi -> Maybe PutMode
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ ByteString
"mode" ByteString -> Maybe PutMode -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe PutMode
mode,
        ByteString
"failonwarnings" ByteString -> Maybe Bool -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe Bool
failOnWarnings,
        ByteString
"parameters"
          ByteString -> QueryString -> QueryString
forall a. ToQuery a => ByteString -> a -> QueryString
Core.=: Maybe QueryString -> QueryString
forall a. ToQuery a => a -> QueryString
Core.toQuery
            ( ByteString
-> ByteString -> ByteString -> HashMap Text Text -> QueryString
forall k v.
(ToQuery k, ToQuery v) =>
ByteString
-> ByteString -> ByteString -> HashMap k v -> QueryString
Core.toQueryMap ByteString
"entry" ByteString
"key" ByteString
"value"
                (HashMap Text Text -> QueryString)
-> Maybe (HashMap Text Text) -> Maybe QueryString
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (HashMap Text Text)
parameters
            )
      ]