最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ruby - How to see absolute paths in swagger for sinatra (rswag) - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question edited Mar 13 at 9:48 gayavat asked Mar 13 at 9:29 gayavatgayavat 19.4k11 gold badges48 silver badges59 bronze badges 4
  • 1 Why would you not use path '/orders'? path is a just a helper the same as using describe '/index' there is no magic here so if you want /orders/index you need to tell it that e.g. path '/orders/index' – engineersmnky Commented Mar 13 at 13:11
  • Because I have a valid specs for swagger docs generation. And specs are failing if path is not match – gayavat Commented Mar 13 at 14:05
  • I wrote rswag rspec tests. Test is failed if path is /orders/index. I want to have successful test and valid docs =) – gayavat Commented Mar 13 at 23:22
  • I am not sure how rspec-swag generates the documentation but have you tried wrapping it in context '/orders'. E.g context '/orders' do; path '/index' do...? – engineersmnky Commented Mar 14 at 0:41
Add a comment  | 

1 Answer 1

Reset to default 1

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
发布评论

评论列表(0)

  1. 暂无评论