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

How to use rabl with swagger? #707

Open
arparthasarathi opened this issue Apr 15, 2018 · 2 comments
Open

How to use rabl with swagger? #707

arparthasarathi opened this issue Apr 15, 2018 · 2 comments

Comments

@arparthasarathi
Copy link

I am using grape-swagger and swagger-ui for documentation of REST APIs in my RAILS application. I would like to document the response examples for the APIs. I couldn't find a way to use Rabl along with Swagger to document my JSON responses.

@arparthasarathi arparthasarathi changed the title How can use rabl with swagger? How to use rabl with swagger? Apr 15, 2018
@EpiphanyMachine
Copy link

EpiphanyMachine commented Dec 17, 2018

Its possible, but it wasn't really simple:

We use a custom rake tasks that builds response examples using rabl + factory bot

We use factory girl to seed data based on a custom "for_docs" trait. Then loop through our rabl files and generate a response json from rabl for each of our views and save them as files. Those files are referenced by name in our api definitions swagger yaml file. Finally we combine all separate/referenced files into one and use that as our swagger file.

Here are some code snippets. We do this over a several different files so its not an easy copy paste of the full code.

      Rabl.render(
        object,
        @public_api_document.template_short_path,
        view_path: HintApi::Application.root.join('app', 'views'),
        format: :hash,
      )
built = JSONRef.new('index.yaml', input_format: :yaml, base_path: File.join(Rails.root, 'public', 'swagger')).expand
...
file.write(JSON.pretty_generate(built))

@Amerr
Copy link

Amerr commented Apr 13, 2019

@EpiphanyMachine is it possible to give a detailed explanation or separate repo illustrating this implementation .

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

3 participants