Sushil Damdhere
Mar 17, 2018 · 2 min read
  • With language agnostic declarative specification clients can understand and consume services without knowledge of server implementation or access to the server code backed by plenty of open sourced resources available online.
  • Applications implemented based on OpenAPI interface (fka Swagger Specification) can automatically generate documentation of methods, parameters and models.
  • This helps keep the documentation, client libraries, and source code to be in sync.
  • Provides sandbox UI (swagger-ui) to allow developer and non developer to interact with APIs.
  • Comes with a tool (Swagger-Codegen) which contains a template-driven engine to generate documentation, API clients and server stubs in different languages by parsing the OpenAPI definition.

Rails API only

Let’s create minimal application structure to generate well known (in Swagger ecosystem) minimal Pet store example.

rails new swagger-demo --api
rails generate model Pet name photo_url status
rails generate scaffold_controller api/v1/pets

Setup rswag gem

  1. Add rswag and rspec-rails gems to Gemfile
bundle install
rails generate rspec:install
rails g rswag:install
rake rswag:specs:swaggerize

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade