Skip to content
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

Unify API form and input validation #27

Open
sbcgua opened this issue Apr 19, 2020 · 1 comment
Open

Unify API form and input validation #27

sbcgua opened this issue Apr 19, 2020 · 1 comment

Comments

@sbcgua
Copy link
Collaborator

sbcgua commented Apr 19, 2020

For the API response shape I propose to have something like below. I know might look a bit over engineering for the existing functionality but general API shape is something that is very difficult to change after :)

// for success
{ success: 1, payload: any }
// for error
{ success: 0, error: { message: "Wrong API call", detail: any } }
  • payload can be of any shape (depending on the specific endpoint)
  • error detail - will probably be either array with errors, or object shape similar to request with errors instead of data attrs

Input validation, a bit in doubts:

  1. just ignore for now (i don't like , this is a ground concept)
  2. use some of standard libs. One is very typescript friendly - https://www.npmjs.com/package/class-validator - but looks a bit bloated for me, and requires classes instead of interfaces which imho corrupts the beauty of TS
  3. Use https://github.com/koorchik/js-validator-livr - a very lightweight, descriptive approach, no dependencies. Used it before, no issues (and I know the author - not sure if it is + or - - but they support and use it quite intesively so it does not go anywhere ;)
@larshp
Copy link
Member

larshp commented Apr 19, 2020

LIVR: looks good for javascript, but in typescript we can define the types, and the input data should correspond to the types defined

I'm not sure what the easiest way to do this in typescript is, but I'd like to avoid having to do double typing.

eg. https://schema.abaplint.org/schema.json is generated automatically from the typescript code, in this validation scenario the input could be validated according to a json schema

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants