-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tagging endpoints on Sub APIs #73
Comments
IMO, it’s much more sensible, modular etc. to define this symbol: data SwaggerTag name description
deriving (Typeable)
instance HasServer api ctx =>
HasServer (SwaggerTag name description
:> api) ctx where
type ServerT (SwaggerTag name description
:> api) m = ServerT api m
route _ = route (Proxy @api)
hoistServerWithContext _ = hoistServerWithContext (Proxy @api)
instance HasClient m api =>
HasClient m (SwaggerTag name description
:> api) where
type Client m (SwaggerTag name description
:> api) = Client m api
clientWithRoute _ _ = clientWithRoute (Proxy @m) (Proxy @api)
hoistClientMonad pm _ = hoistClientMonad pm (Proxy @api)
instance (HasSwagger api, KnownSymbol name, KnownSymbol description) =>
HasSwagger (SwaggerTag name description
:> api) where
toSwagger _ =
let tag =
Tag
(pack $ symbolVal (Proxy @name))
((\case
"" -> Nothing
t -> Just t) .
pack $
symbolVal (Proxy @description))
Nothing
in toSwagger (Proxy @api) & applyTags [tag] And then you can add tags like: type UserAPI
= "user"
:> SwaggerTag "User" "User sub-API is very important."
:> (RegisterAPI
:<|> LoginAPI
:<|> LogoutAPI) … and all three of And other parts of your API (that don’t have that =) |
Is there a good reason it's not in servant-swagger, or is that simply due to lack of time / something? |
I wouldn’t know that, but my idea is rather, hmm, arbitrary, so to say. I’m not sure if I’d want it in, hmm, somewhat official It doesn’t seem enough, IMO, more like a quick hack. |
+1 for this, @michalrus you should send that as a PR! |
Or give me a day, and I'll do it :) |
I think this is done in the package right? https://hackage.haskell.org/package/servant-swagger-tags |
Would be amazing if someone made a PR with that tag implementation :) cc @nakaji-dayo |
I was gonna give it a shot, but servant-swagger's tests aren't passing due to hash map keys being printed in a different order between test runs 🙃 So I fixed that first: #140 |
@chreekat awesome :) Can I request to include nakaji-dayo/servant-swagger-tags#1? |
Hey @domenkozar , unfortunately I remembered that https://hackage.haskell.org/package/openapi3 exists, which reduced my enthusiasm for contributing here 😇 |
Sounds good, we need this then for https://github.com/biocad/servant-openapi3 |
Hi, Thanks in advance! |
Running into some issues trying to tag endpoints when we have broken up the API so it doesn't live in one monolithic file/type.
For example, we have a top level:
with
and
and then
What would be the proper way to tag the endpoint?
Results in the tag getting created, but not associated with the endpoint. Attempting to specify Routes as the whole API results int he following type error:
The text was updated successfully, but these errors were encountered: