rubysinatrarackrswag

How to see absolute paths in swagger for sinatra (rswag)


Setup

    # Gemfile
    gem 'rspec-swag'


    # config.ru
    map '/orders' do 
    run Web::OrdersApp 
    end

    map '/admin/orders' do 
    run Web::AdminOrdersApp 
    end

    # rspec 
    describe OrdersApp, :vcr, type: :request do
      let(:described_class) { OrdersApp }

      path '/index' do
        get '' do
        ....
        end
      end 
    end

Problem

rspec-swag generates docs for /index, map is ignored.
So, it isn't possible to test API via Swagger web UI. I need /orders/index in docs.

How to change code in order to make Swagger docs usable?


Solution

  • Solution: use method.

    It found here Architecture for a modular, component-based Sinatra Application

    # config.ru
    run App
    
    # app.ru
    class App < Sinatra::Base
      use OrdersApp
      use AdminOrdersApp
    end
    
    class OrdersApp < Sinatra::Base
      get '/orders'
    end
    
    class AdminOrdersApp < Admin::Base
      get '/admin/orders'
    end