Define remote methods using json schema definitions. Prototype for #209 - #1163
Define remote methods using json schema definitions. Prototype for #209#1163mrfelton wants to merge 4 commits into
Conversation
|
Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test." |
|
@mrfelton It's a great addition. Can you add some test cases? |
There was a problem hiding this comment.
Please rework this part according to #209 (comment), so that:
- key
prototype.methodNameis mapped toremoteMethod('methodName', { isStatic: false, ... }) - key
methodNameis mapped toremoteMethod('methodName', { isStatic: true, ... })
There was a problem hiding this comment.
@bajtos please consider the workspace implementation. Lets not make it impractical to implement the generator via the workspace. I'm not against prototype.methodName itself... but we might be making more work for ourselves in the workspace without much benefit.
I'd really like to see remote method creation support added to workspace alongside this addition... These JSON files are specifically designed to serve the workspace well so this new feature is no exception.
There was a problem hiding this comment.
Please consider the workspace implementation. Lets not make it impractical to implement the generator via the workspace.
Can you please elaborate more why my proposal is impractical for loopback-workspace to implement? Are you afraid of parsing prototype.{name} in the workspace?
We can modify the implementation as follows if you think it will make the workspace implementation simpler:
methodNameis mapped toisStatic:trueunless the config object provides a different valueprototype.methodNameis always mapped toisStatic:false, regardless of the value in the config object
// static methods
methods: { "work": { isStatic: true, /*...*/ } }
methods: { "work": { /*...*/ } }
// prototype methods
methods: { "work": { isStatic: false, /*...*/ } }
methods: { "prototype.work": { /*...*/ } }What I really want to avoid is adding more stuff that we will have to rework when fixing #209 and thus causing #209 to introduce even more breaking changes.
There was a problem hiding this comment.
Can you please elaborate more why my proposal is impractical for loopback-workspace to implement
The workspace uses keys as identifiers for entities (in the case a method would be an entity).
prototype.methodNameis always mapped to isStatic:false, regardless of the value in the config object
I like where you are going with this... but consider what the workspace does. It loads properties, and other Entities and also writes them back to files. We would have to store a bit that says "this method was defined using prototype.methodName" and recall that during serialization. Of course this is all possible... but probably not worth it to get rid of the annoying isStatic property.
|
Nice to have: rework built-in models in |
|
@slnode ok to test |
|
Besides adding tests, we also need you @mrfelton to sign our CLA: https://cla.strongloop.com/agreements/strongloop/loopback |
|
I've been wanting to add this for quite some time... 👍 |
…rongloop#209 Signed-off-by: Tom Kirkpatrick <tom@systemseed.com>
34c6432 to
27adc8e
Compare
|
Have added a basic test case to verify that remote methods defined via the json spec are properly added to the model. As for the handling of static vs prototype methods, I feel like that should be handled separately in #597 as it's a much wider change that would affect far more than what I was trying to do in #209 (making it possible to define remote methods in json). |
…e added to the model strongloop#209 Signed-off-by: Tom Kirkpatrick <tom@systemseed.com>
27adc8e to
caa2828
Compare
I really don't want people to start adding JSON metadata in the format that is already known to get changed in the near future. All I am asking is to modify the piece of code calling @ritch what's your opinion on this? If you agree with me, then I can add the necessary code on top of @mrfelton's patch to get the desired API. |
Agreed. Lets not be hasty in adding this to the format... there's a lot of downstream work when adding anything to the Regarding |
Because it's not additive, it's a breaking change as explained in #597. ATM, if you don't specify What I would like to see is that
I understand your concerns, we are building technical debt in the workspace API. On the other hand, I feel it's not fair to ask people contributing useful loopback core features to implement support for them in loopback-workspace too. |
|
@ritch what's your opinion on my comment above? It would be nice to come to an agreement to unblock progress of this pull request. If you are still not convinced about my proposal, then how these two alternatives?
|
|
@ritch ping, this pull request is waiting for your comment, can you please read #1163 (comment) and #1163 (comment) and let me know what solution do you consider as the best (or at least acceptable to you)? |
Once we add the nicer syntax we can make this not required if you specify the sugary syntax (prototype.foo). So I am in favor of this option to move this forward. |
I understand that its not fair to say "Thanks for the contribution, but we won't accept it unless you add support in x, y and z". But you also have to understand (as someone contributing to core) that their are upstream / downstream projects that were purposefully developed concurrently with loopback core to ensure that once a capability was designed it would function throughout the entire platform. In this case it is not a matter of technical debt. Its a matter of compatability. The reason we have these JSON files in the first place is because of the workspace. We've been bitten in the past by hastily designing syntax (cough.. ACLs cough...) without thinking about its use in JSON files. What we are talking about here is the other way around sure (we've got some good JSON syntax ideas) but we cannot gloss over the fact that this will be parsed by the workspace API, and eventually implemented in the composer UI. |
|
Closing in favour of #1366. |
Process `settings.methods` and `config.methods` as a key-value map
where the key is the method name and the value is an object describing
the method in the format expected by strong-remoting.
Example: a static method `Model.create`
"methods": {
"create": {
"isStatic": true,
"accepts": {
"arg": "data", "type": "Car",
"http": { "source": "body" }
},
"returns": { "arg": "data", "type": "Car", "root": true }
}
}
This patch is based on the code proposed by @mrfelton in #1163.
Enables remote methods to be defined in the json schema and applied automatically to the generated models. #209