{-# 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.ImportRestApi
-- 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 creating a new API from
-- an external API definition file.
module Amazonka.APIGateway.ImportRestApi
  ( -- * Creating a Request
    ImportRestApi (..),
    newImportRestApi,

    -- * Request Lenses
    importRestApi_failOnWarnings,
    importRestApi_parameters,
    importRestApi_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 POST request to import an API to API Gateway using an input of an API
-- definition file.
--
-- /See:/ 'newImportRestApi' smart constructor.
data ImportRestApi = ImportRestApi'
  { -- | A query parameter to indicate whether to rollback the API creation
    -- (@true@) or not (@false@) when a warning is encountered. The default
    -- value is @false@.
    ImportRestApi -> Maybe Bool
failOnWarnings :: Prelude.Maybe Prelude.Bool,
    -- | A key-value map of context-specific query string parameters specifying
    -- the behavior of different API importing operations. The following shows
    -- operation-specific parameters and their supported values.
    --
    -- To exclude DocumentationParts from the import, set @parameters@ as
    -- @ignore=documentation@.
    --
    -- To configure the endpoint type, set @parameters@ as
    -- @endpointConfigurationTypes=EDGE@,
    -- @endpointConfigurationTypes=REGIONAL@, or
    -- @endpointConfigurationTypes=PRIVATE@. The default endpoint type is
    -- @EDGE@.
    --
    -- To handle imported @basepath@, set @parameters@ as @basepath=ignore@,
    -- @basepath=prepend@ or @basepath=split@.
    --
    -- For example, the AWS CLI command to exclude documentation from the
    -- imported API is:
    --
    -- > aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'
    --
    -- The AWS CLI command to set the regional endpoint on the imported API is:
    --
    -- > aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'
    ImportRestApi -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | [Required] The POST 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.
    ImportRestApi -> ByteString
body :: Prelude.ByteString
  }
  deriving (ImportRestApi -> ImportRestApi -> Bool
(ImportRestApi -> ImportRestApi -> Bool)
-> (ImportRestApi -> ImportRestApi -> Bool) -> Eq ImportRestApi
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportRestApi -> ImportRestApi -> Bool
$c/= :: ImportRestApi -> ImportRestApi -> Bool
== :: ImportRestApi -> ImportRestApi -> Bool
$c== :: ImportRestApi -> ImportRestApi -> Bool
Prelude.Eq, Int -> ImportRestApi -> ShowS
[ImportRestApi] -> ShowS
ImportRestApi -> String
(Int -> ImportRestApi -> ShowS)
-> (ImportRestApi -> String)
-> ([ImportRestApi] -> ShowS)
-> Show ImportRestApi
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportRestApi] -> ShowS
$cshowList :: [ImportRestApi] -> ShowS
show :: ImportRestApi -> String
$cshow :: ImportRestApi -> String
showsPrec :: Int -> ImportRestApi -> ShowS
$cshowsPrec :: Int -> ImportRestApi -> ShowS
Prelude.Show, (forall x. ImportRestApi -> Rep ImportRestApi x)
-> (forall x. Rep ImportRestApi x -> ImportRestApi)
-> Generic ImportRestApi
forall x. Rep ImportRestApi x -> ImportRestApi
forall x. ImportRestApi -> Rep ImportRestApi x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImportRestApi x -> ImportRestApi
$cfrom :: forall x. ImportRestApi -> Rep ImportRestApi x
Prelude.Generic)

-- |
-- Create a value of 'ImportRestApi' 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:
--
-- 'failOnWarnings', 'importRestApi_failOnWarnings' - A query parameter to indicate whether to rollback the API creation
-- (@true@) or not (@false@) when a warning is encountered. The default
-- value is @false@.
--
-- 'parameters', 'importRestApi_parameters' - A key-value map of context-specific query string parameters specifying
-- the behavior of different API importing operations. The following shows
-- operation-specific parameters and their supported values.
--
-- To exclude DocumentationParts from the import, set @parameters@ as
-- @ignore=documentation@.
--
-- To configure the endpoint type, set @parameters@ as
-- @endpointConfigurationTypes=EDGE@,
-- @endpointConfigurationTypes=REGIONAL@, or
-- @endpointConfigurationTypes=PRIVATE@. The default endpoint type is
-- @EDGE@.
--
-- To handle imported @basepath@, set @parameters@ as @basepath=ignore@,
-- @basepath=prepend@ or @basepath=split@.
--
-- For example, the AWS CLI command to exclude documentation from the
-- imported API is:
--
-- > aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'
--
-- The AWS CLI command to set the regional endpoint on the imported API is:
--
-- > aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'
--
-- 'body', 'importRestApi_body' - [Required] The POST 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.
newImportRestApi ::
  -- | 'body'
  Prelude.ByteString ->
  ImportRestApi
newImportRestApi :: ByteString -> ImportRestApi
newImportRestApi ByteString
pBody_ =
  ImportRestApi' :: Maybe Bool
-> Maybe (HashMap Text Text) -> ByteString -> ImportRestApi
ImportRestApi'
    { $sel:failOnWarnings:ImportRestApi' :: Maybe Bool
failOnWarnings = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
      $sel:parameters:ImportRestApi' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
forall a. Maybe a
Prelude.Nothing,
      $sel:body:ImportRestApi' :: ByteString
body = ByteString
pBody_
    }

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

-- | A key-value map of context-specific query string parameters specifying
-- the behavior of different API importing operations. The following shows
-- operation-specific parameters and their supported values.
--
-- To exclude DocumentationParts from the import, set @parameters@ as
-- @ignore=documentation@.
--
-- To configure the endpoint type, set @parameters@ as
-- @endpointConfigurationTypes=EDGE@,
-- @endpointConfigurationTypes=REGIONAL@, or
-- @endpointConfigurationTypes=PRIVATE@. The default endpoint type is
-- @EDGE@.
--
-- To handle imported @basepath@, set @parameters@ as @basepath=ignore@,
-- @basepath=prepend@ or @basepath=split@.
--
-- For example, the AWS CLI command to exclude documentation from the
-- imported API is:
--
-- > aws apigateway import-rest-api --parameters ignore=documentation --body 'file:///path/to/imported-api-body.json'
--
-- The AWS CLI command to set the regional endpoint on the imported API is:
--
-- > aws apigateway import-rest-api --parameters endpointConfigurationTypes=REGIONAL --body 'file:///path/to/imported-api-body.json'
importRestApi_parameters :: Lens.Lens' ImportRestApi (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
importRestApi_parameters :: (Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
-> ImportRestApi -> f ImportRestApi
importRestApi_parameters = (ImportRestApi -> Maybe (HashMap Text Text))
-> (ImportRestApi -> Maybe (HashMap Text Text) -> ImportRestApi)
-> Lens
     ImportRestApi
     ImportRestApi
     (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 (\ImportRestApi' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:ImportRestApi' :: ImportRestApi -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: ImportRestApi
s@ImportRestApi' {} Maybe (HashMap Text Text)
a -> ImportRestApi
s {$sel:parameters:ImportRestApi' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: ImportRestApi) ((Maybe (HashMap Text Text) -> f (Maybe (HashMap Text Text)))
 -> ImportRestApi -> f ImportRestApi)
-> ((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)))
-> ImportRestApi
-> f ImportRestApi
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 POST 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.
importRestApi_body :: Lens.Lens' ImportRestApi Prelude.ByteString
importRestApi_body :: (ByteString -> f ByteString) -> ImportRestApi -> f ImportRestApi
importRestApi_body = (ImportRestApi -> ByteString)
-> (ImportRestApi -> ByteString -> ImportRestApi)
-> Lens ImportRestApi ImportRestApi ByteString ByteString
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ImportRestApi' {ByteString
body :: ByteString
$sel:body:ImportRestApi' :: ImportRestApi -> ByteString
body} -> ByteString
body) (\s :: ImportRestApi
s@ImportRestApi' {} ByteString
a -> ImportRestApi
s {$sel:body:ImportRestApi' :: ByteString
body = ByteString
a} :: ImportRestApi)

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

instance Prelude.NFData ImportRestApi

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

instance Core.ToHeaders ImportRestApi where
  toHeaders :: ImportRestApi -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ImportRestApi -> 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 ImportRestApi where
  toPath :: ImportRestApi -> ByteString
toPath = ByteString -> ImportRestApi -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/restapis"

instance Core.ToQuery ImportRestApi where
  toQuery :: ImportRestApi -> QueryString
toQuery ImportRestApi' {Maybe Bool
Maybe (HashMap Text Text)
ByteString
body :: ByteString
parameters :: Maybe (HashMap Text Text)
failOnWarnings :: Maybe Bool
$sel:body:ImportRestApi' :: ImportRestApi -> ByteString
$sel:parameters:ImportRestApi' :: ImportRestApi -> Maybe (HashMap Text Text)
$sel:failOnWarnings:ImportRestApi' :: ImportRestApi -> Maybe Bool
..} =
    [QueryString] -> QueryString
forall a. Monoid a => [a] -> a
Prelude.mconcat
      [ 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
            ),
        QueryString
"mode=import"
      ]