All framework guides

Ruby

Get an OpenAPI spec from Ruby on Rails

Have request specs? rspec-openapi writes the file when you run them. Otherwise use rswag.

Tool
rspec-openapi or rswag
Time
5 minutes with request specs
You get
doc/openapi.yaml (OpenAPI 3.0)

How it works

Rails does not describe your API on its own. rspec-openapi watches your existing RSpec request specs run and writes down every request and response it sees.

It only includes endpoints your request specs call. If you have no request specs, the quickest route is From code (GitHub) in MCPEasy, which reads routes.rb and your controllers.

Step by step

  1. Step 1: Add the gem to the test group

    In your Gemfile:

    Gemfile
    gem 'rspec-openapi', group: :test
    Terminal
    bundle install
  2. Step 2: Optional: set the title and server

    In spec/rails_helper.rb, after require 'rspec/rails':

    spec/rails_helper.rb
    RSpec::OpenAPI.title = 'My API'
    RSpec::OpenAPI.servers = [{ url: 'https://api.example.com' }]
  3. Step 3: Run your request specs with OPENAPI=1

    This writes doc/openapi.yaml. Running again updates it; edits you make by hand are kept.

    Terminal (macOS / Linux)
    OPENAPI=1 bundle exec rspec spec/requests
    Terminal (Windows PowerShell)
    $env:OPENAPI = "1"; bundle exec rspec spec/requests

Check that it worked

  • doc/openapi.yaml lists every endpoint your request specs call, under paths:.

Give it to MCPEasy

Have a link? Paste it (best)

In MCPEasy, create a server, choose OpenAPI URL and paste the link, for example https://api.example.com/openapi.json. Later changes to your API can be picked up with a sync.

Have a file? Upload it

Choose Upload file and drop in the .json or .yaml file (up to 5 MB). MCPEasy turns each endpoint into a tool, and you review them all before anything goes live.

No request specs: rswag

rswag uses specs that you write to describe each endpoint. It takes a few minutes per endpoint, so it suits small APIs. For a large API without tests, From code (GitHub) in MCPEasy is faster.

  1. Step 1: Install

    Add the gems and run the installer.

    Gemfile
    gem 'rswag-api'
    gem 'rswag-ui'
    
    group :development, :test do
      gem 'rspec-rails'
      gem 'rswag-specs'
    end
    Terminal
    bundle install
    rails g rswag:install
  2. Step 2: Describe an endpoint

    Create a spec in spec/requests. The first line requires the helper the installer created: spec/swagger_helper.rb in most versions (spec/openapi_helper.rb in some newer ones).

    spec/requests/bookings_spec.rb
    require 'swagger_helper'
    
    RSpec.describe 'Bookings API', type: :request do
      path '/bookings' do
        post 'Create a booking' do
          tags 'Bookings'
          consumes 'application/json'
          parameter name: :booking, in: :body, schema: {
            type: :object,
            properties: {
              service_id: { type: :string },
              start_time: { type: :string, format: 'date-time' }
            },
            required: %w[service_id start_time]
          }
    
          response '201', 'booking created' do
            let(:booking) { { service_id: 'svc_1', start_time: '2026-12-01T10:00:00Z' } }
            run_test!
          end
        end
      end
    end
  3. Step 3: Generate the file

    It is written to swagger/v1/swagger.yaml unless your helper file says otherwise.

    Terminal
    rake rswag:specs:swaggerize

If something goes wrong

The file was not created.
OPENAPI=1 was not set for that command. On Windows use the PowerShell line in step 3.
Some endpoints are missing.
No request spec calls them. Add a spec, or use From code (GitHub) in MCPEasy.

Still stuck, or no time to set this up? In MCPEasy choose From code (GitHub): it reads your routes straight from the repository, read-only, and tests every tool against your live API before it goes live.

Official documentation

Other frameworks