module Network.PinPon.SwaggerAPI
(
API
, app
, api
, server
, pinPonSwagger
, writeSwaggerJSON
)
where
import Protolude
import Control.Lens ((&), (.~), (?~))
import Data.Aeson.Encode.Pretty (encodePretty)
import qualified Data.ByteString.Lazy.Char8 as C8
import Data.Swagger
(Swagger, URL(..), description, info, license, title, url, version)
import Network.Wai (Application)
import Servant ((:<|>)(..), Proxy(..), Server, serve)
import Servant.Swagger (toSwagger)
import Servant.Swagger.UI (SwaggerSchemaUI, swaggerSchemaUIServer)
import qualified Network.PinPon.API as PinPon (API, api, server)
import Network.PinPon.Config (Config(..))
type API =
PinPon.API :<|>
SwaggerSchemaUI "swagger-ui" "swagger.json"
api :: Proxy API
api = Proxy
server :: Config -> Server API
server config = PinPon.server config :<|> swaggerSchemaUIServer pinPonSwagger
app :: Config -> Application
app = serve api . server
pinPonSwagger :: Swagger
pinPonSwagger = toSwagger PinPon.api
& info.title .~ "PinPon API"
& info.version .~ "0.1"
& info.description ?~ "A simple Internet-enabled doorbell notificaion service"
& info.license ?~ ("BSD3" & url ?~ URL "https://opensource.org/licenses/BSD-3-Clause")
writeSwaggerJSON :: IO ()
writeSwaggerJSON = C8.writeFile "swagger.json" (encodePretty pinPonSwagger)