Comments (5)
Hi @coldfission, there is a bug in Swagger implementation.
If you take a look at
https://github.com/khrt/Raisin/blob/master/lib/Raisin/API.pm#L196 and https://github.com/khrt/Raisin/blob/master/lib/Raisin/Plugin/Swagger.pm#L225 you'll see that Raisin knows nothing about the data
key which wraps everything.
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 data
.
Something like this:
expose 'data', desc => 'Base object', using => 'MusicApp::Entity::Artist';
from raisin.
Thanks for your response @khrt . Thinking about this for quite a while now. There are two approaches that I can see:
- Modify
Raisin::Middleware::Formatter
to detectdata
key and start encoding at that key's value. To avoid breaking-changes for other implementation, we could make this functionality optional by introducing an app configapi_format_startkey
( ex:api_format_startkey 'data';
) - Modify
Raisin::Plugin::Swagger
to specify thatdata
key and value is expected in the response
I'm leaning toward the first approach with the optional api_format_startkey
config. What do you think? I can work on a Pull Request based on our decision.
from raisin.
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 data
as a top level object. But if different endpoint have different top level object then it won't work with a globacl api_format_startkey
.
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.
from raisin.
should work fine until all your endpoints use data as a top level object
What is your reason for this? I see that JSON API Spec shows that all responses contain a top-level data
object. But, there is no mention of this requirement in the OpenAPI Spec. Keep in mind that the Kubernetes OpenAPI Schema does not use a top-level data
object. This is just one example of a popular OpenAPI Schema implementation.
from raisin.
What is your reason for this?
My reason for this, is that as long as you're free to return any data back api_format_startkey
won't reflect reality.
Imagine you define:
api_format_startkey 'data';
get '/one' => { { 'data' => { .. } };
get '/two' => { 'result' => { .. } };
But, there is no mention of this requirement in the OpenAPI Spec. Keep in mind that the Kubernetes OpenAPI Schema does not use a top-level data object. This is just one example of a popular OpenAPI Schema implementation.
I believe the reason all those from the above have success responses wrapped with data
is because they are good guys which are compliant to JSON API and it has no connection to OpenAPI.
from raisin.
Related Issues (20)
- Optional params that fail type constraints do not return "Invalid Parameters" response.
- Encoder/Decoder are unable to cope with UTF-8 / wide characters.
- t/unit/plugin/swagger.t fails (with Type::Tiny 1.006000?) HOT 5
- Feature Request: Swagger schemes
- $count in SYNOPSIS HOT 1
- Please include VERSION in all modules HOT 4
- Authentication module in Raisin HOT 3
- Disable the route extension. HOT 2
- Ideas to discuss HOT 4
- Improvement: allow swagger to reside behind a reverse proxy
- Request for clarification HOT 3
- Reverse proxy not done correctly HOT 7
- escaping colon in resource path
- Presenting DBIx::Class::ResultSet does not work correctly HOT 6
- please tag recent CPAN releases in git HOT 1
- Regex check in Raisin::Entity flags numbers as strings for JSON::XS
- Bump version to 0.94 please? HOT 3
- route_param regex is broken by R::Routes::Endpoint::_build_regex if contains quantifiers...
- Participate in hacktoberfest?
- question: can Raisin handle file uploads ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from raisin.