-
Notifications
You must be signed in to change notification settings - Fork 25
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
Support servant-pagination
#45
Comments
I have a same problem, working on it. Actually, easier way is just to use P.S. I do no think that this is appropriate place to define instances for 3d-party lib, it should be defined in |
So strange
As you can see, HI, @maksbotan! Hope you know what it can be :) |
Maybe, this is because in servant-openapi3/src/Servant/OpenApi/Internal.hs Lines 378 to 391 in 9eab895
|
I have a workaround, smth like this: instance ToParamSchema (Ranges fields resource) where
toParamSchema :: Proxy (Ranges fields resource) -> Schema
toParamSchema _ =
mempty
& (O.type_ ?~ O. OpenApiString)
& ( O.example
?~ A.String "<field> [<value>][; offset <o>][; limit <l>][; order <asc|desc>]"
)
instance
{-# OVERLAPS #-}
(KnownSymbol sym, HasOpenApi sub)
=> HasOpenApi (Header' mods sym (Ranges fields resource) :> sub)
where
toOpenApi :: Proxy (Header' mods sym (Ranges fields resource) :> sub) -> OpenApi
toOpenApi _ =
toOpenApi (Proxy :: Proxy sub)
& addParam param
& addDefaultResponse400 name
where
name = toText (symbolVal (Proxy :: Proxy sym))
param =
mempty
& (O.name .~ name)
& ( O.description
?~ "Indicates to the server what parts of the collection is requested"
)
& (O.in_ .~ O.ParamHeader)
& (O.required ?~ False)
& (O.schema ?~ O.Inline (toParamSchema @(Ranges fields resource) Proxy)) but I'm wondering, how can I not define whole parameter by my own, but use default lib implementation and modify it |
here it is -- | Request 'Header' for pagination.
type PaginationRequestHeader (fields :: [Symbol]) (resource :: Type) =
Header'
'[ Optional
, Strict
, Description "Indicates to the server what parts of the collection is requested"
]
"Range"
(Ranges fields resource)
instance ToParamSchema (Ranges fields resource) where
toParamSchema :: Proxy (Ranges fields resource) -> Schema
toParamSchema _ =
mempty
& (O.type_ ?~ O.OpenApiString)
& ( O.example
?~ toJSON
("<field> [<value>][; offset <o>][; limit <l>][; order <asc|desc>]" :: Text)
) This way original version can get |
Hello!
Have you considered supporting servant-pagination?
From the Servant pagination recipe, one needs to manually write these 3 instances:
and I am thinking that this library (or maybe a new library
servant-openapi-pagination
?) could provide support (defaultGeneric
instances? Or just default instance for basic types likeInt
,Text
, etc.? I haven't thought about that in detail).The text was updated successfully, but these errors were encountered: