RoR: Swagger does not update api-docs - ruby-on-rails

I have swagger-ui_rails integrated in my existing Rails app. I have added a new model "Book" in my application and now want to update my api-docs. How can I do that ?
I am trying rake swagger:docs but that does not change anything.
Also there is no books_controller in app/controller/api/v1/ direcotry, where other controller exists already.
I am new to Rails and Swagger, so please ignore if i am missing something basic.

Since you mention you define your controllers for the API, I presume you have a home-brewn API. This is ok, but then you will have to generate the swagger documentation by hand. That is ok, but not something I can help you with.
However if you use grape for your api, you can then use the grape-swagger gem. Grape will replace your controllers for the API for you. It is more like a DSL describing your API, which includes the code to be executed. The grape-swagger gem will automatically parse the grape definition and convert it to swagger documentation.
It offers extra options too, like write descriptions in Markdown. The grape-swagger gem is awesome :)
I like this approach, I build a normal rails app, and use grape to serve the API part. My controllers for the UI and API would be different anyway.

Related

Is there a way to generate an interactive documentation for Rails APIs?

I mean something like the interactive documentation that generate FastApi, but for a Rails API. I know there is rswag, but to use this I need to write the Rspec files with the description of my endpoints in others files and then generate the json or xml for to be interpreted by rswag-ui or something like that. And what about if a have my tests already all with minitest? Rewrite it for Rspec?
But Is there a short way to do this? Like, write the method name and description on my controller for to be read for an OAS generator? And don't care about update my OAS JSON file every time I change some parameters for my controller, a route or a response because it will be updated automatically. And of course including the UI in the project.
Already exists some magical tool like this? Or a project in initial state trying to do something similar?
i used Apipie that generates swagger file and local documentation as you can see in its demo. You basically write ruby code to generate documentation.

Setting up ruby on rails gem ga_events

I am relatively new to web dev and I am trying to set up the ruby on rails gem ga_events (https://github.com/Nix-wie-weg/ga_events). I am doing this because I need to have google analytics event tracking within controllers and this gem seems like a good way to do it. The issue I am having is where the readme says, "After requiring ga_events.js, you have to choose an adapter." I am using Google Universal Analytics and thus I would like to choose that one. It doesn't say specifically how to do this. Where do I put that code block (https://github.com/Nix-wie-weg/ga_events#google-universal-analytics-analyticsjs)? Do I need to make a new file somewhere?
I'm assuming it's obvious for a more experienced developer. More detailed instructions+explanation would be really helpful. Thanks.
I'm using Rails 4.0.13 and Ruby 2.0.0p643.
I was having the same issue here! Turns out, it is just javascript code.
I put mine under application.js since it's a code that need to be on every page.

Does grape provide a template to build services

https://github.com/intridea/grape
Is there a way to automatically generate a template for an application which will use grape to provide REST like interfaces. I am looking for something like "rails new app" which will provide me the skeleton to build on. If not what should I be using?
Not that I know of, but there are several example apps with different stacks and functionality on their wiki.
You can mix and match from what you see there, or just clone one of them to get started.
Also, Grape's DSL itself will guide you towards REST. You declare resources and then use the http verbs to define the requests.
grape-starter seems to be what you're looking for.
Install the gem (gem install grape-starter) and create your new API with grape-starter new awesome_api.
For more options, such as choosing an ORM, or setting the prefix, use grape-starter -h. I recommend to have a look on the README.

Able to update an API documentation automatically

I'm working on a web site which provides API for external developers.
Whenever the API is updated (i.e. modified parameters, new end points, etc), I have to update the documentation manually.
So I'm looking at how this process can be be done automatically. Here is what I hope to acheive: once my source code is updated and committed to my source control, some sort of an API Registry will be updated. So my documentation can be an app which refers to the registry and shows the viewers with the latest API.
My site is based on Ruby on Rails.
RDoc is automatically generated based on your source code, and it comes default with Rails. Your code needs to be well-documented, but if it is, you can just run
bundle exec rake doc:app
and your app will generate documentation accessible from doc/app/index.html. I would look at that and see if such documentation fits your needs. Links in the "Class and Module Index" sidebar contain lists of all of your methods with expandable views of the source code for them.
I use a custom rake task that places all of that documentation in the Rails public folder for access directly from my website and allows me to add more than one custom page. I imagine it wouldn't be that hard for you to do something similar that only parsed your API files.
Links:
RDoc Syntax Help
Project on Github

Rspec, test Gems

I've developed a gem which is to use inside a model by adding acts_as_gmappable and it's possible to pass options in the declaration.
Now that I want to write tests with Rspec, I'm stuck for all model related functions:
check if geocoding was properly done
check I create a proper json from all database entries
etc ...
I know how to do these inside a Rails app but definitly not for a gem. Any track?
I managed to do this by reading the excellent book of Jose Valim:
http://plataformatec.com.br/crafting-rails-applications/
He describes how he tests his gem using his engine builder:
https://github.com/josevalim/enginex

Resources