haskell-servant / haskell-servant/servant-swagger

Helpers for serving swagger.json on server

Open
#17 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
123
Forks
34
PR merge metrics
No merged PRs in 30d

Description

This is what I've been using:

``` haskell
type WithSwagger api = api :<|> ("swagger.json" :> Get '[JSON] Swagger)

serveWithSwagger :: forall layout. HasServer layout => Swagger -> Proxy layout -> Server layout -> Application
serveWithSwagger spec _ serv = serve (Proxy :: Proxy (WithSwagger layout)) (serv :<|> return spec)
```

This can be probably generalized so that we won't have to depend on `servant-server`:

``` haskell
withSwagger :: forall m api application server. Monad m
=> (Proxy (WithSwagger api) -> (server :<|> m Swagger) -> application) -- serve
-> Swagger -> Proxy api -> server -> application
withSwagger serve spec _ server =
serve (Proxy :: Proxy (WithSwagger layout)) (server :<|> return spec)

-- usage example
withSwagger serve (toSwagger api) api server
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the issue's serveWithSwagger and proposed withSwagger signatures, then inspect how Proxy api, Swagger, and the server composition operator are exposed. Confirm the generalized helper no longer requires servant-server and validate the usage example with toSwagger api.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.