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

[Question] Any hints on best way to support swagger response/model parsers? #4

Closed
rromanchuk opened this issue Feb 5, 2019 · 5 comments
Labels
question Further information is requested

Comments

@rromanchuk
Copy link
Contributor

Basically i want to be able to support https://github.com/ruby-grape/grape-swagger#response-documentation-

It looks like you can provide custom parsers, but I haven't really dug much more into this
https://github.com/ruby-grape/grape-swagger#model_parsers

Just wondering if you have tried adding response support for swagger + grape + fast_jsonapi, or if there is an approach that isn't going to end up being a major headache?

@EmCousin EmCousin added the question Further information is requested label Feb 5, 2019
@EmCousin
Copy link
Owner

EmCousin commented Feb 6, 2019

Hi @rromanchuk, unfortunately I haven't found any simple way to provide such support.
The Best way that I have figured is to code a custom model parser that would take a serializer (including Jsonapi::ObjectSerializer), get its attributes and returns a hash containing the schema with its attributes.

But the big problem with this approach is : Impossible to figure the attribute type directly from the serializer. If your serializer serializes a database model, then we have to manage the dependencies with the different ORMs... like you said, that's a headache.

I'll keep you posted if I manage to find a better solution, meanwhile, feel free to share any ideas you might have on that matter

@EmCousin
Copy link
Owner

EmCousin commented Feb 7, 2019

@rromanchuk I think you might be interested by this branch I've been working on. There is also an open pull request but it needs some testing and some reviews before merging.

When you have time, would you let me know if it is any close to answer your question?

# Gemfile
gem 'grape_fast_jsonapi', git: 'git://github.com/EmCousin/grape_fast_jsonapi.git', branch: 'feature/swagger_model_parser'

@rromanchuk
Copy link
Contributor Author

@EmCousin that's what i figured. i know it kind of defeats the entire purpose, but i'm almost tempted to make non-jsonapi decorator just for documentation purposes, although good luck to me keeping that maintained.

In context of my client code, the jsonapi response is actually obfuscated away and is flattened to be used in mapping the local object graph. I'm basically just trying to avoid (or non backend developers) having to look at serializer files to look at which properties/datatypes are returned. I mean i might be even overthinking it, i think swagger has an example property where i could even generate fixtures with a simple rake task and render some examples via fixtures. Right now i basically just execute the API call and inspect the live results/dump responses from client console/read the serializer.

@rromanchuk
Copy link
Contributor Author

sweet, looking now!

@rromanchuk
Copy link
Contributor Author

closing, tracked in #5

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

No branches or pull requests

2 participants