Swagger: setting tags

5 views
Skip to first unread message

Corentin Dupont

unread,
Nov 20, 2018, 5:53:48 AM11/20/18
to nick...@getshoptv.com, oleg.g...@iki.fi, haskell...@googlegroups.com
Hello,
I'm trying to set tags on my Swagger endpoints.

swaggerDoc :: S.Swagger
swaggerDoc = toSwagger (Proxy :: Proxy AppAPI)
    & S.info . S.title       .~ "App API"
    & S.info . S.version     .~ "v2.0.0"
    & S.info . S.description ?~ "This is the API"

I would like to apply a tag on all the endpoints, based on the URL.
For example, all endpoints starting with "/api/v1/foo" should be tagged "Foo".
How to achieve that?

Thanks a lot
Corentin

Corentin Dupont

unread,
Nov 22, 2018, 2:22:36 AM11/22/18
to Nickolay Kudasov, oleg.g...@iki.fi, haskell...@googlegroups.com
Hey there!
This mailing list is very silent :)
I found an answer after some research:

swaggerDoc :: S.Swagger
swaggerDoc = toSwagger (Proxy :: Proxy AppAPI)
  & S.info . S.title       .~ "App API"
  & S.info . S.version     .~ "v2.0.0"
  & S.info . S.description ?~ "This is the API"
  & S.basePath ?~ "/api/v1"
  & S.applyTagsFor fooOps ["Foo"]
  & S.applyTagsFor barOps ["Bar"]
  where
    fooOps, barOps :: Traversal' S.Swagger S.Operation
    fooOps = subOperations (Proxy :: Proxy FooAPI) (Proxy :: Proxy AppAPI)
    barOps = subOperations (Proxy :: Proxy BarAPI) (Proxy :: Proxy AppAPI)

Cheers
Reply all
Reply to author
Forward
0 new messages