Sha256: b9550da3029ce30d8b93044870b5c298655fadf6190bbf832dd8390df905fbe1

Contents?: true

Size: 974 Bytes

Versions: 1

Compression:

Stored size: 974 Bytes

Contents

# frozen_string_literal: true

require 'spec_helper'

describe 'Boolean Params' do
  def app
    Class.new(Grape::API) do
      format :json

      desc 'splines' do
        consumes ['application/x-www-form-urlencoded']
      end
      params do
        requires :a_boolean, type: Grape::API::Boolean
        optional :another_boolean, type: Grape::API::Boolean, default: false
      end
      post :splines do
        { message: 'hi' }
      end

      add_swagger_documentation
    end
  end

  subject do
    get '/swagger_doc/splines'
    expect(last_response.status).to eq 200
    body = JSON.parse last_response.body
    body['paths']['/splines']['post']['parameters']
  end

  it 'converts boolean types' do
    expect(subject).to eq [
      { 'in' => 'formData', 'name' => 'a_boolean', 'type' => 'boolean', 'required' => true },
      { 'in' => 'formData', 'name' => 'another_boolean', 'type' => 'boolean', 'required' => false, 'default' => false }
    ]
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gitlab-grape-swagger-1.5.0 spec/swagger_v2/boolean_params_spec.rb