Ruby
Get an OpenAPI spec from Ruby on Rails
Have request specs? rspec-openapi writes the file when you run them. Otherwise use rswag.
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
Step 1: Add the gem to the test group
In your Gemfile:
Gemfilegem 'rspec-openapi', group: :testTerminalbundle installStep 2: Optional: set the title and server
In spec/rails_helper.rb, after require 'rspec/rails':
spec/rails_helper.rbRSpec::OpenAPI.title = 'My API' RSpec::OpenAPI.servers = [{ url: 'https://api.example.com' }]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/requestsTerminal (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.
Step 1: Install
Add the gems and run the installer.
Gemfilegem 'rswag-api' gem 'rswag-ui' group :development, :test do gem 'rspec-rails' gem 'rswag-specs' endTerminalbundle install rails g rswag:installStep 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.rbrequire '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 endStep 3: Generate the file
It is written to swagger/v1/swagger.yaml unless your helper file says otherwise.
Terminalrake 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
More guides for MCP and OpenAPI
- OpenAPI to MCP serverHow a spec maps to MCP tools, which endpoints to keep, and how auth works.
- REST API to MCP serverConvert any API, with or without a spec: Postman, cURL, code, plus a worked example.
- Get an OpenAPI spec from your frameworkExport an OpenAPI (Swagger) file from 11 frameworks, step by step.
- OpenAPI spec from FastAPINothing to install: FastAPI already serves your spec at /openapi.json.
- OpenAPI spec from ExpressThe packages, code and commands to produce a spec from an Express app.