|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'simple api with prefix' do |
| 4 | + |
| 5 | + before :all do |
| 6 | + class ApiWithPrefix < Grape::API |
| 7 | + prefix :api |
| 8 | + |
| 9 | + desc 'This gets apitest' |
| 10 | + get '/apitest' do |
| 11 | + { test: 'something' } |
| 12 | + end |
| 13 | + end |
| 14 | + |
| 15 | + class SimpleApiWithPrefix < Grape::API |
| 16 | + mount ApiWithPrefix |
| 17 | + add_swagger_documentation |
| 18 | + end |
| 19 | + |
| 20 | + end |
| 21 | + |
| 22 | + def app |
| 23 | + SimpleApiWithPrefix |
| 24 | + end |
| 25 | + |
| 26 | + it 'should not raise TypeError exception' do |
| 27 | + end |
| 28 | + |
| 29 | + it 'retrieves swagger-documentation on /swagger_doc that contains apitest' do |
| 30 | + get '/swagger_doc.json' |
| 31 | + expect(JSON.parse(last_response.body)).to eq( |
| 32 | + 'apiVersion' => '0.1', |
| 33 | + 'swaggerVersion' => '1.2', |
| 34 | + 'info' => {}, |
| 35 | + 'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq, |
| 36 | + 'apis' => [ |
| 37 | + { 'path' => '/apitest.{format}', 'description' => 'Operations about apitests' }, |
| 38 | + { 'path' => '/swagger_doc.{format}', 'description' => 'Operations about swagger_docs' } |
| 39 | + ] |
| 40 | + ) |
| 41 | + end |
| 42 | + |
| 43 | + context 'retrieves the documentation for apitest that' do |
| 44 | + it 'contains returns something in URL' do |
| 45 | + get '/swagger_doc/apitest.json' |
| 46 | + expect(JSON.parse(last_response.body)).to eq( |
| 47 | + 'apiVersion' => '0.1', |
| 48 | + 'swaggerVersion' => '1.2', |
| 49 | + 'basePath' => 'http://example.org', |
| 50 | + 'resourcePath' => '/apitest', |
| 51 | + 'produces' => Grape::ContentTypes::CONTENT_TYPES.values.uniq, |
| 52 | + 'apis' => [{ |
| 53 | + 'path' => '/api/apitest.{format}', |
| 54 | + 'operations' => [{ |
| 55 | + 'notes' => '', |
| 56 | + 'summary' => 'This gets apitest', |
| 57 | + 'nickname' => 'GET-api-apitest---format-', |
| 58 | + 'method' => 'GET', |
| 59 | + 'parameters' => [], |
| 60 | + 'type' => 'void' |
| 61 | + }] |
| 62 | + }] |
| 63 | + ) |
| 64 | + end |
| 65 | + end |
| 66 | + |
| 67 | +end |
0 commit comments