|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe '#942 route param documentation' do |
| 6 | + let(:documentation) { { format: 'uuid' } } |
| 7 | + |
| 8 | + let(:app) do |
| 9 | + docs = documentation |
| 10 | + |
| 11 | + another_app = Class.new(Grape::API) do |
| 12 | + get '/list' do |
| 13 | + [] |
| 14 | + end |
| 15 | + end |
| 16 | + |
| 17 | + Class.new(Grape::API) do |
| 18 | + route_param :account_id, type: String, desc: 'id of account', documentation: docs do |
| 19 | + mount another_app |
| 20 | + |
| 21 | + get '/another-list' do |
| 22 | + [] |
| 23 | + end |
| 24 | + end |
| 25 | + |
| 26 | + add_swagger_documentation |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + subject do |
| 31 | + get '/swagger_doc' |
| 32 | + JSON.parse(last_response.body) |
| 33 | + end |
| 34 | + |
| 35 | + context 'when documenting route_param of mounted endpoint' do |
| 36 | + let(:parameters) { subject['paths']['/{account_id}/list']['get']['parameters'] } |
| 37 | + |
| 38 | + specify do |
| 39 | + account_id_param = parameters.find { |param| param['name'] == 'account_id' } |
| 40 | + expect(account_id_param['type']).to eq 'string' |
| 41 | + expect(account_id_param['format']).to eq 'uuid' |
| 42 | + expect(account_id_param['description']).to eq 'id of account' |
| 43 | + end |
| 44 | + end |
| 45 | + |
| 46 | + context 'when documenting route_param of nested endpoint' do |
| 47 | + let(:parameters) { subject['paths']['/{account_id}/another-list']['get']['parameters'] } |
| 48 | + |
| 49 | + specify do |
| 50 | + account_id_param = parameters.find { |param| param['name'] == 'account_id' } |
| 51 | + expect(account_id_param['type']).to eq 'string' |
| 52 | + expect(account_id_param['format']).to eq 'uuid' |
| 53 | + expect(account_id_param['description']).to eq 'id of account' |
| 54 | + end |
| 55 | + end |
| 56 | + |
| 57 | + context 'when documentation overrides description' do |
| 58 | + let(:documentation) { { desc: 'another description' } } |
| 59 | + |
| 60 | + let(:parameters) { subject['paths']['/{account_id}/list']['get']['parameters'] } |
| 61 | + |
| 62 | + specify do |
| 63 | + account_id_param = parameters.find { |param| param['name'] == 'account_id' } |
| 64 | + expect(account_id_param['type']).to eq 'string' |
| 65 | + expect(account_id_param['description']).to eq 'another description' |
| 66 | + end |
| 67 | + end |
| 68 | +end |
0 commit comments