|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe 'document hash and array' do |
| 6 | + include_context "#{MODEL_PARSER} swagger example" |
| 7 | + |
| 8 | + before :all do |
| 9 | + module TheApi |
| 10 | + class TestApi < Grape::API |
| 11 | + format :json |
| 12 | + |
| 13 | + documentation = ::Entities::DocumentedHashAndArrayModel.documentation if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation) |
| 14 | + |
| 15 | + desc 'This returns something' |
| 16 | + namespace :arbitrary do |
| 17 | + params do |
| 18 | + requires :id, type: Integer |
| 19 | + end |
| 20 | + route_param :id do |
| 21 | + desc 'Timeless treasure' |
| 22 | + params do |
| 23 | + requires :body, using: documentation unless documentation.nil? |
| 24 | + requires :raw_hash, type: Hash, documentation: { param_type: 'body' } if documentation.nil? |
| 25 | + requires :raw_array, type: Array, documentation: { param_type: 'body' } if documentation.nil? |
| 26 | + end |
| 27 | + put '/id_and_hash' do |
| 28 | + {} |
| 29 | + end |
| 30 | + end |
| 31 | + end |
| 32 | + |
| 33 | + add_swagger_documentation openapi_version: '3.0' |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + |
| 38 | + def app |
| 39 | + TheApi::TestApi |
| 40 | + end |
| 41 | + |
| 42 | + subject do |
| 43 | + get '/swagger_doc' |
| 44 | + JSON.parse(last_response.body) |
| 45 | + end |
| 46 | + describe 'generated request definition' do |
| 47 | + it 'has hash' do |
| 48 | + expect(subject['components']['schemas'].keys).to include('putArbitraryIdIdAndHash') |
| 49 | + expect(subject['components']['schemas']['putArbitraryIdIdAndHash']['properties'].keys).to include('raw_hash') |
| 50 | + end |
| 51 | + |
| 52 | + it 'has array' do |
| 53 | + expect(subject['components']['schemas'].keys).to include('putArbitraryIdIdAndHash') |
| 54 | + expect(subject['components']['schemas']['putArbitraryIdIdAndHash']['properties'].keys).to include('raw_array') |
| 55 | + end |
| 56 | + |
| 57 | + it 'does not have the path parameter' do |
| 58 | + expect(subject['components']['schemas'].keys).to include('putArbitraryIdIdAndHash') |
| 59 | + expect(subject['components']['schemas']['putArbitraryIdIdAndHash']).to_not include('id') |
| 60 | + end |
| 61 | + end |
| 62 | +end |
0 commit comments