Skip to content
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

"using" in an entity without declaring an OpenAPI array #46

Open
davel opened this issue Sep 21, 2018 · 4 comments
Open

"using" in an entity without declaring an OpenAPI array #46

davel opened this issue Sep 21, 2018 · 4 comments

Comments

@davel
Copy link
Contributor

davel commented Sep 21, 2018

Hello,

I am trying to use Raisin for an API which returns a single row of data, read by calling DBIx::Class's ->find(). I am having trouble making the generated OpenAPI / Swagger schema agree with the generated JSON.

I have two Raisin::Entity classes. One represents the row from DBIx::Class. The other represents the JSON data presented by an endpoint. It refers to the first via expose 'data', using => .... When the Swagger schema is generated, it declared the data is an array, when it is in fact an object represented by a hash.

Is there a way to make Raisin generate a schema matching the returned data?

Many thanks,
Dave

@khrt
Copy link
Owner

khrt commented Sep 23, 2018

Hi,

that happens, because DBIx::Class's ->find() returns DBIx::Class::ResultSet as result.

If you could provide me with sample data and application maybe I might help then.

Thanks.

davel added a commit to davel/Raisin that referenced this issue Sep 24, 2018
In order to demonstrate khrt#46
davel added a commit to davel/Raisin that referenced this issue Sep 24, 2018
@davel
Copy link
Contributor Author

davel commented Sep 24, 2018

The problem is that swagger.json does not agree with the generated output. For example in the music app, swagger.json claims that /artists returns data described by,

               "200" : {
                  "description" : "List",
                  "schema" : {
                     "$ref" : "#/definitions/MusicApp::Entity::Artist-302668EB84"
                  }
               },

However, MusicApp::Entity::Artist is not what is returned. Instead, we get a hash with elements count and data.

 `{"count":2,"data":[{"hash":"10","artist":"Nirvana", ...

You can fix this when an array is returned, eg.
davel@bb5fb43

.... but you cannot fix this where a single object is returned, such as with the /artists{id} endpoint. This change,
davel@c4f9eda

Causes data to be described as an array, which is incorrect.

Is there some way I can get the generated swagger to agree with the returned data for the /artists/{id} endpoint?

@khrt
Copy link
Owner

khrt commented Sep 24, 2018

From what I understand now, it is not possible to reach the agreement between Swagger and the presenter.

As a solution to that we can introduce an argument to Entitie's expose to say the field is HASH or ARRAY.

What do you think?

@davel
Copy link
Contributor Author

davel commented Sep 24, 2018

That would make sense to me. Also potentially useful for representing a has_one relationship from DBix::Class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants