-
-
Notifications
You must be signed in to change notification settings - Fork 413
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
Use full header type in response header instances #1697
Use full header type in response header instances #1697
Conversation
@worm2fed thanks a lot for this PR. Does this unlock nice things beyond the openapi feature? If so we should probably have a changelog entry for it. :) |
@tchoutri thank you) As I can see there a few things have to be done:
Maybe it will be better to define helper type -- | Helper type to define 'Header' with 'Description'.
type HeaderWithDescription description =
Header' '[Description description, Optional, Strict] |
0d237e5
to
7dfae41
Compare
Seems like problem with order of
Actually, I think it's correct to do that - add -- In this instance, we add a Header on top of something that is already decorated with some headers
instance {-# OVERLAPPING #-} ( KnownSymbol h, ToHttpApiData v )
=> AddHeader h v (Headers (fst ': rest) a) (Headers (Header' mods h v ': fst ': rest) a) where
addOptionalHeader hdr (Headers resp heads) = Headers resp (HCons hdr heads)
-- In this instance, 'a' parameter is decorated with a Header.
instance {-# OVERLAPPABLE #-} ( KnownSymbol h, ToHttpApiData v , new ~ Headers '[Header' mods h v] a)
=> AddHeader h v a new where
addOptionalHeader hdr resp = Headers resp (HCons hdr HNil) Here is this error:
Honestly, I do not understand what is it |
@tchoutri maybe you can explain what is going on? My current understanding is that -- We need all these fundeps to save type inference
class AddHeader h v orig new (mods :: [*])
| h v orig mods -> new, new -> h, new -> v, new -> orig, new -> mods where
addOptionalHeader :: ResponseHeader h v -> orig -> new -- ^ N.B.: The same header can't be added multiple times in this class all these dependencies required to validate that there is only one exact header. And by using And in sense of logic it is same because description is just "documentation label", but current implementation of providing description to headers via modifiers limits to implement this. So, to perform such validation we need to add HLS gives me a bit more information:
|
Oh, I see in test |
I think you may consider mimicking Summary:
|
@blackheaven I do no see how it will work with I will take a look |
so, smith like this:
which can be used not only for response headers, but for any @blackheaven is it what you are suggesting? |
Exactly, thanks. |
@blackheaven I think it will be good to include |
I would say, in a perfect world, it should be in
|
939b8ef
to
a32345e
Compare
@blackheaven it is a little more difficult than it might seem at first I've added test and it's failing,
This showed, that it will be impossible to add this just to |
I tried also, I didn't find a solution, it doesn't seems a good idea in the end, sorry for that :/ |
I will leave diff here, maybe someone else will want to try |
Use `Header'` instead of `Header` in response, so it's possible to provide `Description`, for example: ``` type PaginationTotalCountHeader = Header' '[ Description "Indicates to the client total count of items in collection" , Optional , Strict ] "Total-Count" Int ``` Note: if you want to add header with description you should use `addHeader'` or `noHeader'` which accepts `Header'` with all modifiers.
a32345e
to
89680f8
Compare
@tchoutri should I add |
@worm2fed good question, I must admit I haven't used stack in some years now. If you add them and it works, I'll approve it. :) |
mm.. seems like |
It's in `cabal.project`, but not in `stack.yaml`. Actually, there is more packages in `cabal.project` - `doc/cookbook/*`, but stack is not happy with their cabal files and asks to rename, so I do not add them.
They are in base, you just don't get them automatically through mtl. See changelog |
@ysangkok thanks for explanation |
@tchoutri can you please review this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks a lot!
@tchoutri I think we had to squash fixups before merge.. Any way, thanks) |
@tchoutri oh, I see, sorry |
Yep |
* Use `Header'` in response headers Use `Header'` instead of `Header` in response, so it's possible to provide `Description`, for example: ``` type PaginationTotalCountHeader = Header' '[ Description "Indicates to the client total count of items in collection" , Optional , Strict ] "Total-Count" Int ``` Note: if you want to add header with description you should use `addHeader'` or `noHeader'` which accepts `Header'` with all modifiers.
Hi @worm2fed! As far as I understand, your change to Can we instead add @tchoutri what do you think? |
A compat alias could be nice yes! |
This is required to be able provide
Description
into headers, for example like this:This PR is related to another one: biocad/servant-openapi3#48 and related to issue biocad/servant-openapi3#45