Usage for HTTP validation
I'm looking to use Arktype as a Request/Response validator
This comes with the following requirements:
- Request body should be validated with deep
reject
unknownKeys so invalid requests are immediately 422
- Response should be validated with deep delete
unknownKeys so local information can't passthrough
- Response input should be cloned rather then inline-morphed (including key deletion) so you can pass in input objects as-is
Please list recommended AT APIs for this
Please link the related undone issues is any36 Replies
Unknown Userā¢6mo ago
Message Not Public
Sign In & Join Server To View
Well, it's either 400 or 422, and if you want to 400 for whatever else it's 422
Github uses
422 Validation failed
As I understood it's history, 422 did mean "you sent valid XML but its contents is š©"
So 400 is more or JSON.parse failure then validation failure
@ssalbdivad pingI've already answered this haven't I?
ah, it's still sumday, nevermind
I am working today
Oh
Maybe you meant the m
I've made this #questions so I don't ever ask it again
Actually I added a deep param for onUndeclaredKey
I still can't configure it at a scope level yet that's tricky and kinda what I'm working on now
Have to be very careful with caching across scopes
So, I'd like to have a unit test for this
So please list what functions I need and I'll try to make one
If you want to fuck around with stuff though which you generally do maybe you should look at the
transform
API on t.raw
(t.internal
on the next release).Hmm
What that does?
Deeply transforms type nodes
Ah
Here's how I use it to configure description at multkple levels:
Here's the new
onUndeclaredKey
implementation:
You'd have to learn a bit about the different node kinds to use this effectively but it is very powerful for this sort of thing
What are the cases you are referring to?Validation of untrusted input and serialization of untrimmed output?
Using exact same input Type
A la Zod's default behaviour I guess (is it? I didn't really use zod)
Or what are you asking
So, I'd like to have a unit test for this So please list what functions I need and I'll try to make oneWhat are you asking for the names of the APIs?
Yep, what API should I point my eyes to
There is no builtin for cloning universally before morphs yet.
You can pipe to
{...o}
or whatever clone fn you want easily enough I guess but it would be a nice convenience to have it as a scope option
You could probably contribute that feature quite easily if you wantš¤
I mean think about how trivial it is
It's just a tiny wrapper
And an if check
Ok I can just use a copy-on-write Proxy
š¤ Can I?
No proxies too slow
For the input data? or are you talking about an internal solution? I would just use an if check haha
So I can
Okay
For input I guess deep reject is enough
For the output
Hmm
I mean input and output are both just types at the ends of morphs
Nah I mean like Request and Response data
Hmm response validation seems weird but I know that's a thing I guess
That's not really a validation, it's more of serialization
Like a custom toJson that picks only needed stuff
How does validation really help with that
Seems like just object utility methods
By allowing to throw in any š©
Maybe not the greatest idea but I want a working prototype
Or just
@arktype/util
I guess I dunno
Whatever I know people do output validationAh yes, I use that
I mean this
I would love if you wrote some unit tests for the feature you wanted.
Or implemented that config to clone before morphing
That's what I want as well
I can't understand what I want until I make it
I mean I guess I basically know what it would be
The tricky thing it will be one of the first config options to affect the parsed type result so I have to be a bit careful
Actually I guess not really
Yep, me too
But it's a "vibes" understanding, not the "experience" understanding
Well not the external type anyways
Well look at the way existing config options are passed at various levels in the tests
onUndeclaredKey
would be a config option on structure
I guess it could be at the root as well for convenience will have to think about how to normalize thatUnknown Userā¢6mo ago
Message Not Public
Sign In & Join Server To View