-
Notifications
You must be signed in to change notification settings - Fork 31
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
Swagger Schema Expected Response and Actual Response Do Not Match #74
Comments
Hi @coldfission, there is a bug in Swagger implementation. If you take a look at If it brakes production code and causes a serious issues on your side you can workaround it by creating a new entity which which will wrap everything with Something like this: expose 'data', desc => 'Base object', using => 'MusicApp::Entity::Artist'; |
Thanks for your response @khrt . Thinking about this for quite a while now. There are two approaches that I can see:
I'm leaning toward the first approach with the optional |
First approach looks like a nice solution if you don't want to brake existing code and make it optional. And that should work fine until all your endpoints use Second approach looks more valid as it makes result match to reality, fixing a bug, but potentially is a braking change as there might be software relaying on existing behaviour. In a long-term perspective I think second approach is more beneficial as it actually fixes a bug, while the first approach is mitigating a problem. |
What is your reason for this? I see that JSON API Spec shows that all responses contain a top-level |
My reason for this, is that as long as you're free to return any data back Imagine you define: api_format_startkey 'data';
get '/one' => { { 'data' => { .. } };
get '/two' => { 'result' => { .. } };
I believe the reason all those from the above have success responses wrapped with |
I've noticed with the music-app example, the response is contained within an object with key "data". But, when interpreting the Swagger Schema ( visually and with swagger-ui tool ), there is no hint that the top-level object with key "data" should ever exist. See below image for swagger-ui schema showing the mismatch in expected schema response data structure and actual server response data structure. Do you have any ideas on how to make schema-expected and actual responses match when using Entities? I have some rough ideas on how to solve this with a change to Raisin source, but could potentially introduce breaking-changes for others. Here is one idea:
Replace Line 57 in Raisin::Middleware::Formatter with:
if ( defined $r->body->{data} and ref $r->body->{data} ) { $r->body($s->serialize($r->body->{data})); } else { $r->body($s->serialize($r->body)); }
The text was updated successfully, but these errors were encountered: