|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'namespace' do |
| 6 | + context 'at root level' do |
| 7 | + def app |
| 8 | + Class.new(Grape::API) do |
| 9 | + namespace :aspace do |
| 10 | + get '/', desc: 'Description for aspace' |
| 11 | + end |
| 12 | + add_swagger_documentation openapi_version: '3.0', format: :json |
| 13 | + end |
| 14 | + end |
| 15 | + |
| 16 | + subject do |
| 17 | + get '/swagger_doc' |
| 18 | + JSON.parse(last_response.body)['paths']['/aspace']['get'] |
| 19 | + end |
| 20 | + |
| 21 | + it 'shows the namespace summary in the json spec' do |
| 22 | + expect(subject['summary']).to eql('Description for aspace') |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + context 'with camel case namespace' do |
| 27 | + def app |
| 28 | + Class.new(Grape::API) do |
| 29 | + namespace :camelCases do |
| 30 | + get '/', desc: 'Look! An endpoint.' |
| 31 | + end |
| 32 | + add_swagger_documentation openapi_version: '3.0', format: :json |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + subject do |
| 37 | + get '/swagger_doc' |
| 38 | + JSON.parse(last_response.body)['paths']['/camelCases']['get'] |
| 39 | + end |
| 40 | + |
| 41 | + it 'shows the namespace summary in the json spec' do |
| 42 | + expect(subject['summary']).to eql('Look! An endpoint.') |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'mounted' do |
| 47 | + def app |
| 48 | + namespaced_api = Class.new(Grape::API) do |
| 49 | + namespace :bspace do |
| 50 | + get '/', desc: 'Description for aspace' |
| 51 | + end |
| 52 | + end |
| 53 | + |
| 54 | + Class.new(Grape::API) do |
| 55 | + mount namespaced_api |
| 56 | + add_swagger_documentation openapi_version: '3.0', format: :json |
| 57 | + end |
| 58 | + end |
| 59 | + |
| 60 | + subject do |
| 61 | + get '/swagger_doc' |
| 62 | + JSON.parse(last_response.body)['paths']['/bspace']['get'] |
| 63 | + end |
| 64 | + |
| 65 | + it 'shows the namespace summary in the json spec' do |
| 66 | + expect(subject['summary']).to eql('Description for aspace') |
| 67 | + end |
| 68 | + end |
| 69 | + |
| 70 | + context 'mounted under a route' do |
| 71 | + def app |
| 72 | + namespaced_api = Class.new(Grape::API) do |
| 73 | + namespace :bspace do |
| 74 | + get '/', desc: 'Description for aspace' |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + Class.new(Grape::API) do |
| 79 | + mount namespaced_api => '/mounted' |
| 80 | + add_swagger_documentation openapi_version: '3.0', format: :json |
| 81 | + end |
| 82 | + end |
| 83 | + |
| 84 | + subject do |
| 85 | + get '/swagger_doc' |
| 86 | + JSON.parse(last_response.body)['paths']['/mounted/bspace']['get'] |
| 87 | + end |
| 88 | + |
| 89 | + it 'shows the namespace summary in the json spec' do |
| 90 | + expect(subject['summary']).to eql('Description for aspace') |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + context 'arbitrary mounting' do |
| 95 | + def app |
| 96 | + inner_namespaced_api = Class.new(Grape::API) do |
| 97 | + namespace :bspace do |
| 98 | + get '/', desc: 'Description for aspace' |
| 99 | + end |
| 100 | + end |
| 101 | + |
| 102 | + outer_namespaced_api = Class.new(Grape::API) do |
| 103 | + mount inner_namespaced_api => '/mounted' |
| 104 | + end |
| 105 | + |
| 106 | + Class.new(Grape::API) do |
| 107 | + mount outer_namespaced_api => '/' |
| 108 | + add_swagger_documentation openapi_version: '3.0', format: :json |
| 109 | + end |
| 110 | + end |
| 111 | + |
| 112 | + subject do |
| 113 | + get '/swagger_doc' |
| 114 | + JSON.parse(last_response.body)['paths']['/mounted/bspace']['get'] |
| 115 | + end |
| 116 | + |
| 117 | + it 'shows the namespace summary in the json spec' do |
| 118 | + expect(subject['summary']).to eql('Description for aspace') |
| 119 | + end |
| 120 | + end |
| 121 | +end |
0 commit comments