-
-
Notifications
You must be signed in to change notification settings - Fork 412
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
Exported Servant.Links.addQueryParam #1785
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
synopsis: Exported addQueryParam | ||
packages: servant | ||
prs: #1785 | ||
issues: #1232 | ||
significance: minor | ||
description: { | ||
`addQueryParams` is required to define custom `HasLink` instances which actually manipulate the | ||
generated query params. This function was not exported earlier and now it is. | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,6 +115,8 @@ module Servant.Links ( | |
, linkSegments | ||
, linkQueryParams | ||
, linkFragment | ||
, addQueryParam | ||
, addSegment | ||
) where | ||
|
||
import Data.Kind | ||
|
@@ -187,6 +189,10 @@ import Web.HttpApiData | |
-- | A safe link datatype. | ||
-- The only way of constructing a 'Link' is using 'safeLink', which means any | ||
-- 'Link' is guaranteed to be part of the mentioned API. | ||
-- | ||
-- NOTE: If you are writing a custom 'HasLink' instance, and need to manipulate | ||
-- the 'Link' (adding query params or fragments, perhaps), please use the the | ||
-- 'addQueryParam' and 'addSegment' functions. | ||
Comment on lines
+193
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good Note, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tchoutri should we also export There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not in this PR, I would like to take the time to think about a different module to export these "unsafe" modifiers for Links. |
||
data Link = Link | ||
{ _segments :: [Escaped] | ||
, _queryParams :: [Param] | ||
|
@@ -232,10 +238,18 @@ data Param | |
addSegment :: Escaped -> Link -> Link | ||
addSegment seg l = l { _segments = _segments l <> [seg] } | ||
|
||
-- | Add a 'Param' (query param) to a 'Link' | ||
-- | ||
-- Please use this judiciously from within your custom 'HasLink' instances | ||
-- to ensure that you don't end-up breaking the safe provided by "safe links" | ||
addQueryParam :: Param -> Link -> Link | ||
addQueryParam qp l = | ||
l { _queryParams = _queryParams l <> [qp] } | ||
|
||
-- | Add a 'Fragment' (query param) to a 'Link' | ||
-- | ||
-- Please use this judiciously from within your custom 'HasLink' instances | ||
-- to ensure that you don't end-up breaking the safe provided by "safe links" | ||
addFragment :: Fragment' -> Link -> Link | ||
addFragment fr l = l { _fragment = fr } | ||
|
||
|
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.
@fgaz remind me, is
minor
a valid value for thesignificance
field?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.
No, we only have
significance: significant
or omittedThere 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.
@tchoutri btw the docs are here: https://codeberg.org/fgaz/changelog-d