Smithy4s refinement types and range combination issue #1525
Replies: 4 comments 2 replies
-
Not gonna lie : I hadn't envisioned this usecase. Refinements were designed with the goal of incorporating validated types that are not quite provided OOTB by the smithy standard library (things like phone numbers, email addresses, urls, etc), and I didn't really think of combining them with existing validators. So with your context in mind, the feature was designed so that you could define However, we could potentially meet you halfway, and add a If you're interested to contribute this, the PR would roughly involve the following :
I'd like @kubukoz' opinion on the matter though. |
Beta Was this translation helpful? Give feedback.
-
Thanks @Baccata for not dismissing my use case right away (and for your detail answer). tbh, I didn't expect this work (at all), because it's mentioned in the documentation, but I tried it anyway because I though it could be nice way to combine these two features (refinements and validators). And that combination will give users much more flexibility like in my use case. And yes, I'm interested in contributing this feature. I'll need to read your guideline a bit more and following up with a PR. |
Beta Was this translation helpful? Give feedback.
-
@Baccata I looked into your suggestion and wanted to clarify if I understand you correctly. So, our goal for this is implement a @trait(selector: "* [trait|trait]")
structure scalaImports {
@required
import: Import
} And use it like: use smithy4s.meta#scalaImports
apply fide.spec#GetPlayersInput @scalaImports(
import: "fide.spec.providers.given"
)
@readonly
@paginated(inputToken: "page", outputToken: "nextPage", pageSize: "pageSize")
@http(method: "GET", uri: "/api/players", code: 200)
operation GetPlayers {
input := {
@httpQuery("page")
page: PageNumber = "1"
@httpQuery("page_size")
@range(min: 1, max: 100)
pageSize: PageSize = 30
}
output := {
@required
items: Players
nextPage: PageNumber
}
errors: [InternalServerError]
} So that, the generated If I understand correctly, I can start working on a PR soon. |
Beta Was this translation helpful? Give feedback.
-
I'm not following... |
Beta Was this translation helpful? Give feedback.
-
Smithy4s refinement types and range combination issue
Everything works if I have implicit
RefinementProvider
in refined type companion objectI have an issue related to refinement range combination in Smithy4s. I have a model like this:
It works completely fine as I provide implicit
RefinementProvider
for all types like this:Please notice
RefinementProvider.Simple[smithy.api.Range, Natural]
is necessary to provide range constraint that I use in thePageSize
field.Problem arises when I need to move
RefinementProvider
out of refined type companion objectNow I want to move
Natural
type into a separate module which is independent from smithy module. The error I get is from here:In this file, We don't have implicit provider for Range to Natural because it's not in Natural companion object any more.
You can find all the code here: https://github.com/lenguyenthanh/fide
And changes that causes the issue: lenguyenthanh/fide#100
Question
Currently I don't see how to include the implicit provider for
Range
toNatural
in theGetPlayersInput
companion object. How can I solve this issue?proposed solutions
Add mechanism to provide implicit
RefinementProvider
for refinement type in Input objector
include all implicit
RefinementProvider
in refinement object some how (in this case PageSize object)Beta Was this translation helpful? Give feedback.
All reactions