-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Support jsonapi.org #445
Comments
+1 |
+1 for this |
You can modify var sharedMethod = MyModel.sharedClass.find('findById', true);
sharedMethod.returns[0].root = false; Although I don't think this is a good long term solution. I think we should add the ability to define a global response format setting. What would be helpful is to know what other formats are useful. |
As far as supporting jsonapi, I'd like to see what else we need to change and if we can maintain computability with 2.x. Maybe a |
+1 |
+1 as well. |
+1, integration with ember apps would be cake walk if implemented. |
+1 |
+1, and happy Ember developers we would be! |
Does Ember include strong-remoting can already serve different response depending on what the client accepts, it should be reasonably easy to add a new case for The difficult part is how to determine the name of the root key (e.g. |
By default, Ember uses the following in the request header: However, the RESTAdapter can easily be extended to add For the root key, wouldn't the model's name / plural name be used? I see the difficulty with the hasManyThrough relationship, as the API explorer shows the incorrect model. (I've been meaning to see if I could fix that issue.) |
I would make the initial implementation easier if we could use a constant key name. The jsonapi spec explicitly supports that:
Does Ember support this too? |
Unfortunately, it seems Ember does not treat the generic key 'data' as a special key. I reviewed the code, and tested just to make sure. The following error message is generated as there is no 'data' model defined:
[NOTE: I am currently using Ember version 1.7.0, however, I do not see any changes in 1.8.1 that would use the generic key 'data'.] |
@bradplank hmm... Seems like the Ember Inflector is trying to pluralize the word "data". Try this: Ember.Inflector.inflector.uncountable('data'); |
👍 |
jsonapi will soon hit 1.0 and only backward compatible changes are planned after that. |
+1 |
Now that json api is 1.0, is there any further news on loopback support? And to note, there is strong movement ATM to make Ember Data natively handle json api. |
+1 |
IS there any update on this? |
👍 |
Very interested in this! |
+1 |
+1 👍 |
I've begun writing a bootscript to add jsonapi support. Couple questions: @bajtos @ritch
|
ATM, it's not possible to customise the list of content types at route (method) level - see https://github.com/strongloop/loopback-swagger/blob/8eb73acbaae2cd600d03a95dcf55aee6f7560980/lib/specgen/route-helper.js#L161-L162. However, you can customise this list at global level via
LoopBack explorer sends exactly the same HTTP verb which is specified in remoting metadata and used by the rest adapter. You should modify remoting data of your methods to specify a different HTTP verb (method), loopback-explorer will then pick it up automatically. |
Legend @bajtos, thanks! |
@bajtos earlier you mentioned:
I'd be happy to have a crack at submitting the PR for this. Any chance you can give me a bit of guidance? |
@bajtos @raymondfeng @ritch The only option I can think of at the moment is to detect Any chance I can submit a PR to add support for |
Sure. You should be able to add it as a |
@ritch awesome. Will do. |
@ritch PR submitted. strongloop/strong-remoting#249 |
Awesome! You can start looking here: https://github.com/strongloop/loopback-swagger/blob/b6e39252640732e31c26d6831bf86c5b6593aff7/lib/specgen/route-helper.js#L161-L162. The default list of produces/consumes types is initialised here and then used here. |
Nice! On my list! On Thu, 5 Nov 2015 at 17:02, Miroslav Bajtoš notifications@github.com
|
@bajtos I've been digging into this a bit. My first thought was to try something like this: var entry = {
path: routeHelper.convertPathFragments(route.path),
method: routeHelper.convertVerb(route.verb),
operation: {
tags: tags,
summary: typeConverter.convertText(route.description),
description: typeConverter.convertText(route.notes),
// [bajtos] We used to remove leading model name from the operation
// name for Swagger Spec 1.2. Swagger Spec 2.0 requires
// operation ids to be unique, thus we have to include the model name.
operationId: route.method,
// [bajtos] we are omitting consumes and produces, as they are same
// for all methods and they are already specified in top-level fields
parameters: accepts,
responses: responseMessages,
deprecated: !!route.deprecated,
// TODO: security
}
};
if (route.consumes) {
entry.operation.consumes = route.consumes;
}
if (route.produces) {
entry.operation.produces = route.produces;
} But 2 problems,
module.exports = function (app) {
let remotes = app.remotes();
let methods = remotes.methods();
methods.forEach(function (method) {
method.consumes = ['application/vnd.api+json'];
method.produces = ['application/vnd.api+json'];
});
} Perhaps I'm barking up the wrong tree and rather than trying to allow defining consumes and produces per method I should just be trying to allow a setting on app or strong-remoting setup? Pointers, suggestions appreciated. |
strong-remoting's
This is a problem with
Yes, that's what crossed my mind too. It looks like a good strategy, considering that JSON-API implementation almost certainly wants to change consumes/produces globally. We already have two global options that are related to your work: @digitalsadhu what do you think? |
Thanks @bajtos that makes sense, thanks for clarification. How were you imagining rest.jsonApi would work? Perhaps something like, if
Perhaps also:
|
@bajtos also, how hard is it to get access to strong-remoting rest options inside loopback-swagger? |
Your proposal above looks good to me.
I'd say it's easy. Swagger specgen has access to The handler has |
Ok excellent. I'll make that my next push. |
I'm waiting for this feature more than for a Christmas present. +100 |
@teckays It's not quite feature complete for use with ember. (Side loading in the works) and there are still most likely some bugs to work out but it's worth giving it a go. We'd certainly appreciate any big reports etc. |
@digitalsadhu I will definitely give it a try and report any bugs/improvements I find. Thank you. |
@teckays we released v0.11.0 of the component yesterday which adds support for side loading and that pretty much rounds out the main features needed for ember users. For anyone else reading this, https://github.com/digitalsadhu/loopback-component-jsonapi is ready for anyone willing to try it out and submit bugs and such. We are pretty quick to respond and keen to find and fix any issues so please give it a go. |
@bajtos I'm wondering if theres any chance anyone from Strongloop would have the time to have a look through https://github.com/digitalsadhu/loopback-component-jsonapi and offer any feedback? (I know you guys are busy and understand if it's not possible) Theres a lot of code improvement we'd like to do when we get a chance and we have a bank of integration tests in place so that we can refactor with confidence as needed. We'd also like to continue adding additional configuration options to make the component more flexible for various real world use cases. One thing i'm a bit worried about is that as loopback changes we may constantly end up fixing things that break (So far this hasn't happened) so in general i'm hoping theres ways we can make the code base a bit more robust. |
Just an update on loopback-component-jsonapi, we are getting pretty stable at version v0.17.2 |
+1 |
2 similar comments
+1 |
+1 |
Closing this issue as done - see https://www.npmjs.com/package/loopback-component-jsonapi |
Is there any way, or plans, to configure how JSON responses (and therefore requests) are serialized? For instance, it would be very nice to support a standard, such as http://jsonapi.org/ so that clients can take advantage of generalized tooling. Looking at the current API, it would appear to me the biggest thing would be for models to be serialized in root objects...
This:
As opposed to:
There would also be other considerations in how associations and relations are serialized.
The text was updated successfully, but these errors were encountered: