api: /swagger.json serves swagger 2.0 api docs
This commit is contained in:
parent
b9b1cff22d
commit
f083a88e76
@ -71,7 +71,7 @@ main = do
|
|||||||
args <- getArgs >>= parseArgsOrExit doc
|
args <- getArgs >>= parseArgsOrExit doc
|
||||||
when (isPresent args (longOption "help")) $ exitWithUsage doc
|
when (isPresent args (longOption "help")) $ exitWithUsage doc
|
||||||
when (isPresent args (longOption "version")) $ putStrLn version >> exitSuccess
|
when (isPresent args (longOption "version")) $ putStrLn version >> exitSuccess
|
||||||
when (isPresent args (longOption "swagger")) $ BL8.putStrLn (encode swaggerDoc) >> exitSuccess
|
when (isPresent args (longOption "swagger")) $ BL8.putStrLn (encode swaggerSpec) >> exitSuccess
|
||||||
let defp = "8001"
|
let defp = "8001"
|
||||||
p <- case readMay $ getArgWithDefault args defp (longOption "port") of
|
p <- case readMay $ getArgWithDefault args defp (longOption "port") of
|
||||||
Nothing -> exitWithUsage doc
|
Nothing -> exitWithUsage doc
|
||||||
@ -96,11 +96,13 @@ type HledgerApi =
|
|||||||
:<|> "commodities" :> Get '[JSON] [Commodity]
|
:<|> "commodities" :> Get '[JSON] [Commodity]
|
||||||
:<|> "accounts" :> Get '[JSON] [Account]
|
:<|> "accounts" :> Get '[JSON] [Account]
|
||||||
:<|> "accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport
|
:<|> "accounttransactions" :> Capture "acct" AccountName :> Get '[JSON] AccountTransactionsReport
|
||||||
-- :<|> "swagger" :> Get '[JSON] Swagger
|
|
||||||
:<|> Raw
|
:<|> Raw
|
||||||
|
|
||||||
|
type HledgerApi' = ("swagger.json" :> Get '[JSON] Swagger) :<|> HledgerApi
|
||||||
|
|
||||||
hledgerApiApp :: FilePath -> Journal -> Wai.Application
|
hledgerApiApp :: FilePath -> Journal -> Wai.Application
|
||||||
hledgerApiApp staticdir j = Servant.serve api server
|
hledgerApiApp staticdir j =
|
||||||
|
Servant.serve (Proxy :: Proxy HledgerApi') (return swaggerSpec :<|> server)
|
||||||
where
|
where
|
||||||
api :: Proxy HledgerApi
|
api :: Proxy HledgerApi
|
||||||
api = Proxy
|
api = Proxy
|
||||||
@ -113,7 +115,6 @@ hledgerApiApp staticdir j = Servant.serve api server
|
|||||||
:<|> commoditiesH
|
:<|> commoditiesH
|
||||||
:<|> accountsH
|
:<|> accountsH
|
||||||
:<|> accounttransactionsH
|
:<|> accounttransactionsH
|
||||||
-- :<|> swaggerH
|
|
||||||
:<|> serveDirectory staticdir
|
:<|> serveDirectory staticdir
|
||||||
where
|
where
|
||||||
accountnamesH = return $ journalAccountNames j
|
accountnamesH = return $ journalAccountNames j
|
||||||
@ -131,7 +132,6 @@ hledgerApiApp staticdir j = Servant.serve api server
|
|||||||
q = Hledger.Query.Any --filterQuery (not . queryIsDepth) $ queryFromOpts d ropts'
|
q = Hledger.Query.Any --filterQuery (not . queryIsDepth) $ queryFromOpts d ropts'
|
||||||
thisacctq = Acct $ accountNameToAccountRegex a -- includes subs
|
thisacctq = Acct $ accountNameToAccountRegex a -- includes subs
|
||||||
return $ accountTransactionsReport ropts j q thisacctq
|
return $ accountTransactionsReport ropts j q thisacctq
|
||||||
-- swaggerH = return swaggerDoc
|
|
||||||
|
|
||||||
instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoiding https://github.com/bos/aeson/issues/290
|
instance ToJSON ClearedStatus where toJSON = genericToJSON defaultOptions -- avoiding https://github.com/bos/aeson/issues/290
|
||||||
instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions
|
instance ToJSON GenericSourcePos where toJSON = genericToJSON defaultOptions
|
||||||
@ -175,14 +175,13 @@ instance ToJSON AccountTransactionsReport where toJSON = genericToJSON defaultOp
|
|||||||
|
|
||||||
-- swagger api doc
|
-- swagger api doc
|
||||||
|
|
||||||
swaggerDoc :: Swagger
|
swaggerSpec :: Swagger
|
||||||
swaggerDoc = toSwagger (Proxy :: Proxy HledgerApi)
|
swaggerSpec = toSwagger (Proxy :: Proxy HledgerApi)
|
||||||
& info.infoTitle .~ "hledger API"
|
& info.infoTitle .~ "hledger API"
|
||||||
& info.infoVersion .~ "0.0.0.1"
|
& info.infoVersion .~ "0.0.0.1"
|
||||||
& info.infoDescription ?~ "This is the API provided by hledger-api for reading hledger data"
|
& info.infoDescription ?~ "This is the API provided by hledger-api for reading hledger data"
|
||||||
& info.infoLicense ?~ License "GPLv3+" (Nothing)
|
& info.infoLicense ?~ License "GPLv3+" (Nothing)
|
||||||
|
|
||||||
-- instance ToSchema Swagger
|
|
||||||
instance ToSchema ClearedStatus
|
instance ToSchema ClearedStatus
|
||||||
instance ToSchema GenericSourcePos
|
instance ToSchema GenericSourcePos
|
||||||
instance ToSchema Decimal
|
instance ToSchema Decimal
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user