Sha256: 10d8fc7feac05f36097d245ea650bca954e6e835bb6b868284e444650c782881

Contents?: true

Size: 1.46 KB

Versions: 29

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe '#539 post params given as array' do
  let(:app) do
    Class.new(Grape::API) do
      namespace :issue_539 do
        class Element < Grape::Entity
          expose :id
          expose :description
          expose :role
        end

        class ArrayOfElements < Grape::Entity
          expose :elements,
                 documentation: {
                   type: Element, is_array: true, param_type: 'body', required: true
                 }
        end

        desc 'create account',
             params: ArrayOfElements.documentation
        post do
          present params
        end
      end

      add_swagger_documentation format: :json
    end
  end

  subject do
    get '/swagger_doc'
    JSON.parse(last_response.body)
  end

  let(:parameters) { subject['paths']['/issue_539']['post']['parameters'] }
  let(:definitions) { subject['definitions'] }

  specify do
    expect(parameters).to eql(
      [
        {
          'in' => 'body', 'name' => 'elements', 'required' => true, 'schema' => {
            'type' => 'array', 'items' => { '$ref' => '#/definitions/Element' }
          }
        }
      ]
    )
  end

  specify do
    expect(definitions).to eql(
      'Element' => {
        'type' => 'object',
        'properties' => {
          'id' => { 'type' => 'string' },
          'description' => { 'type' => 'string' },
          'role' => { 'type' => 'string' }
        }
      }
    )
  end
end

Version data entries

29 entries across 29 versions & 2 rubygems

Version Path
grape-swagger-0.31.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.30.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.30.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.29.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.28.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.27.3 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.27.2 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.27.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.27.0 spec/issues/539_array_post_body_spec.rb