Sha256: 076470d71766a72412d147417b89a24bc41f115f900230609ec9fbe9e1b832a2

Contents?: true

Size: 1.82 KB

Versions: 9

Compression:

Stored size: 1.82 KB

Contents

require 'spec_helper'

describe 'document hash and array' do
  include_context "#{MODEL_PARSER} swagger example"

  before :all do
    module TheApi
      class TestApi < Grape::API
        format :json

        documentation = ::Entities::DocumentedHashAndArrayModel.documentation if ::Entities::DocumentedHashAndArrayModel.respond_to?(:documentation)

        desc 'This returns something'
        namespace :arbitrary do
          params do
            requires :id, type: Integer
          end
          route_param :id do
            desc 'Timeless treasure'
            params do
              requires :body, using: documentation unless documentation.nil?
              requires :raw_hash, type: Hash, documentation: { param_type: 'body' } if documentation.nil?
              requires :raw_array, type: Array, documentation: { param_type: 'body' } if documentation.nil?
            end
            put '/id_and_hash' do
              {}
            end
          end
        end

        add_swagger_documentation
      end
    end
  end

  def app
    TheApi::TestApi
  end

  subject do
    get '/swagger_doc'
    JSON.parse(last_response.body)
  end
  describe 'generated request definition' do
    it 'has hash' do
      expect(subject['definitions'].keys).to include('putArbitraryIdIdAndHash')
      expect(subject['definitions']['putArbitraryIdIdAndHash']['properties'].keys).to include('raw_hash')
    end

    it 'has array' do
      expect(subject['definitions'].keys).to include('putArbitraryIdIdAndHash')
      expect(subject['definitions']['putArbitraryIdIdAndHash']['properties'].keys).to include('raw_array')
    end

    it 'does not have the path parameter' do
      expect(subject['definitions'].keys).to include('putArbitraryIdIdAndHash')
      expect(subject['definitions']['putArbitraryIdIdAndHash']).to_not include('id')
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
grape-swagger-0.26.1 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.26.0 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.25.3 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.25.2 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.25.1 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.25.0 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.24.0 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.23.0 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb
grape-swagger-0.22.0 spec/swagger_v2/api_swagger_v2_hash_and_array_spec.rb