{-# LANGUAGE DataKinds #-}{-# LANGUAGE DeriveGeneric #-}{-# LANGUAGE GeneralizedNewtypeDeriving #-}{-# LANGUAGE OverloadedStrings #-}{-# LANGUAGE TypeOperators #-}module Main whereimport Control.Lensimport Data.Aesonimport qualified Data.ByteString.Lazy.Char8 as BL8import Data.Proxyimport Data.Swaggerimport GHC.Genericsimport Servantimport Servant.Swagger-- Typesdata Todo = Todo { created :: Int , description :: String } deriving (Show, Eq, Generic)instance ToJSON Todonewtype TodoId = TodoId String deriving (FromText, Generic)-- APItype API = "todo" :> Capture "id" TodoId :> Get '[JSON] Todo-- Swagger DocswagDoc :: SwaggerswagDoc = toSwagger (Proxy :: Proxy API) & info.infoTitle .~ "Todo API" & info.infoVersion .~ "1.0" & info.infoDescription ?~ "This is an API that tests servant-swagger support for a Todo" & info.infoLicense ?~ License "MIT" (Just (URL "http://mit.com"))-- Documentation and annotationsinstance ToParamSchema TodoIdinstance ToSchema Todo where declareNamedSchema proxy = do (name, schema) <- genericDeclareNamedSchema defaultSchemaOptions proxy return (name, schema & schemaDescription ?~ "This is some real Todo right here" & schemaExample ?~ toJSON (Todo 100 "get milk"))-- Main, create swaggger.jsonmain :: IO ()main = BL8.writeFile "swagger.json" (encode swagDoc)