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-1.6.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.6.0 spec/issues/539_array_post_body_spec.rb
gitlab-grape-swagger-1.5.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.5.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.4.2 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.4.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.4.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.3.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.3.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.2.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.2.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.1.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-1.0.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.34.2 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.34.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.34.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.33.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.32.1 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.32.0 spec/issues/539_array_post_body_spec.rb
grape-swagger-0.31.1 spec/issues/539_array_post_body_spec.rb