GithubHelp home page GithubHelp logo

Comments (5)

khrt avatar khrt commented on July 30, 2024

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.

coldfission avatar coldfission commented on July 30, 2024

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 detect data 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 config api_format_startkey ( ex: api_format_startkey 'data'; )
  • Modify Raisin::Plugin::Swagger to specify that data 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.

khrt avatar khrt commented on July 30, 2024

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.

coldfission avatar coldfission commented on July 30, 2024

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.

khrt avatar khrt commented on July 30, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.