Is there a certain schema validator lib that is pr...
# suitescript
m
Is there a certain schema validator lib that is preferred to be used with restlets?
b
Be weary of trying to be so structured. you are not in full control of your error messages
m
How so? What about, for example, doing the validation (whatever the lib is) in a trycatch block, and respond in the catch?
How do you do it? Do you write the validation logic by yourself?
b
if the client messes up authenticaion, you do not control the error message. If netsuite is down, you do not control the error message. If there is a java error, you do not control the error message
you use a restlet because you expect to have control over both the client and the server. You have a lot less need of validation if you are in charge of generating the input.
Expect to have a lot of issues around edge cases if you are trying to run a structured web service using a restlet
m
I am fine with the error message part as long as the client will get an error. But I don't understand why that would make all validations useless.
Another dev will write how the input would look like, but you have no idea what will happen in the future (like another dev comes and changes something, for example), and I don't really trust JS. So checking the types, for example, would be useful, no?
b
its more the job of a testing framework to make sure that future developers don't break the code with changes
Validation in restlets is rare because restlets are usually used in a scenario where the same person / team is writing both client and server. You would be validating that the input you generated matches what you expect. if you wanted to be boring, the validation would perform the same job if done by the client.
My warning for you is if you are using a restlet as a formal webservice with external clients who expect actual schemas.
m
Hmm, got it. Thanks!
j
@Marawan مَرَوَان I've been successfully using Zod in restlets, to validate input parameters, post body, etc. Also when validating responses from external services. To make it work in SuiteScript, it just needs to be bundled to be compatible with AMD-style modules. We've made publicly available an example of that, here's a bundled version of Zod v4: github.com/anagram-dev/suitecloud-ts/blob/…/zod.js Then the following, for example, should work:
Copy code
define(['./lib/zod'], function(z){
   const PayloadSchema = z.object({
     hello: z.literal(true),
   })
})
Hopefully it helps!
m
@joaquin Thanks 🤍
👍 1