abaplint / abaplint-sci-server

Node backend application for running abaplint on ABAP

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unify API form and input validation

sbcgua opened this issue · comments

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 ;)

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