feat: web: serve openapi.json
Serving the OpenAPI JSON schema means that clients can auto-discover how to use the API. I am particularly interested in this because open-webui can use OpenAPI to add context to LLM responses.
This commit is contained in:
parent
e360e50497
commit
4e9aa5825d
@ -19,10 +19,14 @@ module Hledger.Web.Handler.MiscR
|
|||||||
, getManageR
|
, getManageR
|
||||||
, getRobotsR
|
, getRobotsR
|
||||||
, getRootR
|
, getRootR
|
||||||
|
, getOpenApiR
|
||||||
) where
|
) where
|
||||||
|
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import qualified Data.Text as T
|
import qualified Data.Text as T
|
||||||
|
import qualified Data.Yaml as Yaml
|
||||||
|
import qualified Data.ByteString as BS
|
||||||
|
import Data.FileEmbed (embedFile)
|
||||||
import Yesod.Default.Handlers (getFaviconR, getRobotsR)
|
import Yesod.Default.Handlers (getFaviconR, getRobotsR)
|
||||||
|
|
||||||
import Hledger
|
import Hledger
|
||||||
@ -107,3 +111,13 @@ getAccounttransactionsR a = do
|
|||||||
styleAmounts (journalCommodityStylesWith HardRounding j) $
|
styleAmounts (journalCommodityStylesWith HardRounding j) $
|
||||||
accountTransactionsReport rspec{_rsQuery=Any} j thisacctq
|
accountTransactionsReport rspec{_rsQuery=Any} j thisacctq
|
||||||
|
|
||||||
|
openApiYaml :: BS.ByteString
|
||||||
|
openApiYaml = $(embedFile "config/openapi.yaml")
|
||||||
|
|
||||||
|
getOpenApiR :: Handler Value
|
||||||
|
getOpenApiR =
|
||||||
|
case Yaml.decodeEither' openApiYaml of
|
||||||
|
Left _ -> notFound
|
||||||
|
Right openapi -> do
|
||||||
|
addHeader "Content-Type" "application/json"
|
||||||
|
return openapi
|
||||||
|
|||||||
@ -2,6 +2,8 @@
|
|||||||
/robots.txt RobotsR GET
|
/robots.txt RobotsR GET
|
||||||
/static StaticR Static getStatic
|
/static StaticR Static getStatic
|
||||||
|
|
||||||
|
/openapi.json OpenApiR GET
|
||||||
|
|
||||||
/ RootR GET
|
/ RootR GET
|
||||||
/journal JournalR GET
|
/journal JournalR GET
|
||||||
/register RegisterR GET
|
/register RegisterR GET
|
||||||
|
|||||||
@ -176,6 +176,7 @@ library
|
|||||||
, data-default
|
, data-default
|
||||||
, directory >=1.2.3.0
|
, directory >=1.2.3.0
|
||||||
, extra >=1.7.11
|
, extra >=1.7.11
|
||||||
|
, file-embed >=0.0.16.0
|
||||||
, filepath
|
, filepath
|
||||||
, githash >=0.1.6.2
|
, githash >=0.1.6.2
|
||||||
, hjsmin
|
, hjsmin
|
||||||
|
|||||||
@ -123,6 +123,7 @@ library:
|
|||||||
- Decimal >=0.5.1
|
- Decimal >=0.5.1
|
||||||
- directory >=1.2.3.0
|
- directory >=1.2.3.0
|
||||||
- extra >=1.7.11
|
- extra >=1.7.11
|
||||||
|
- file-embed >=0.0.16.0
|
||||||
- filepath
|
- filepath
|
||||||
- githash >=0.1.6.2
|
- githash >=0.1.6.2
|
||||||
- hjsmin
|
- hjsmin
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user