-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Router: validate input parameters #118
Comments
I am proposing to use AJV:
https://github.com/epoberezkin/ajv#coercing-data-types |
I think the use of AJV for validation is a good idea. This then has me wondering if LoopBack.next couldn't optionally allow the definition of models in that format, to avoid redundancy? LoopBack's |
I had the same idea in my mind too. Why to invent and maintain our own domain-specific language for defining models, when we can leverage an existing standard (JSON Schema)? However, @raymondfeng, our architect, has a different opinion. IIRC, he is proposing a slightly different implementation, where LoopBack internally uses some custom format, and then allows 3rd party plugins to provide converters from from different DSLs into this internal LoopBack format. In other words, JSON Schema would become only one of the supported ways how to define models. @raymondfeng could you please confirm whether I described your ideas correctly? |
That sounds like a good idea. but if AJV becomes the validator for LoopBack.next, what if the internal format was actually JSON Schema, and other formats could be translated to it in the way you described? This would make it easier to provide validation for all formats. I am actually experimenting with something like this right now for LoopBack 3.8, by patching |
@bajtos I just finished a first implementation of this for LB 3.8 by overriding the internal Do you think this is of interest for 3.8? Shall I open a PR for it? |
Interesting. Is your code on GitHub, so that we can take a look before you invest more time on a pull request? IMO, we need to carefully asses impact of such change, for example on loopback-swagger. |
It's not yet. The code is fairly modular and short, so I can easily move it to its own package and create a little test case illustrating how it's being used, as a base for further discussions both in LB 3.8 and 4 |
@bajtos I've finally moved my code into a separate module and put it up on Github: https://github.com/lehni/loopback-jsonschema-registry This still needs proper documentation, but for now there's an example in the README that should explain the based functioning of all this. I am happy to explain in more detail here, and curious to hear your thoughts! |
@lehni thank you for making your code public. I read through it and to be honest, I don't know what and how to review |
I meant to write more documentation to explain better what is going on there. Here a quick explanation, perhaps this can turn into proper README content later: So I decided to keep using the normal LB3 type JSON model files, but offer a couple of ways to extend them, and then use some preprocessing magic in which these new hybrid JSON modes files get translated to two things: 1. normal LB JSON models with only properties and value present that LB can actually understand, and 2. separate JSON schema descriptions for better validation. Some examples:
The same I can do with keywords, as shown with the There are many advantages and benefits for us using this approach, and in order to explain these I need to outline the functioning in more detail. But here some of the top of my head:
There are some potential problems with our approach to improve validation also, mainly: We had to monkey-patch We also needed to perform quite a few tricks to get the AJV validation errors added to the internal But before going into more detail: I just wanted to share this so you can see how we're currently embedding and using AJV, and for us some really nice things have come out of this. I'm not sure this should go into LB3, but I would be excited and happy to help if you thought it should! I do think I could maybe inform discussions on LB4, and perhaps we can look into how to smooth things out for LB3 to work better together with this package? |
@kjdelisle and me agreed to remove Validation from MVP scope. The current validation performed by Juggler should be good enough for CRUD applications which are our MVP target. |
@bajtos see PR #1489, I checked the items finished.
|
There are JSON-schema like languages to define models:
The JSON-schema itself can only be used define the |
@raymondfeng your comment seems out of topic of this issue, I cross-posted it in #699 - it seems like a more relevant place for that information, at least to me. |
Closing as done. |
Overview
In loopback/strong-remoting 3.x, we are validating input parameters against the types/schema defined in remoting metadata to ensure the client is passing valid values. We should offer similar capability in LoopBack.next.
Acceptance Criteria
Notes
If we run into any edge cases that aren't trivial, we should create new issues to handle them and address them after the fact, instead of blocking this task.
The text was updated successfully, but these errors were encountered: