grape-swagger/spec/swagger_v2/api_swagger_v2_global_confi...

57 lines
1.8 KiB
Ruby
Raw Permalink Normal View History

# frozen_string_literal: true
2016-03-16 00:53:03 +08:00
require 'spec_helper'
describe 'global configuration stuff' do
before :all do
module TheApi
class ConfigurationApi < Grape::API
format :json
version 'v3', using: :path
desc 'This returns something',
2016-05-07 03:00:36 +08:00
failure: [{ code: 400, message: 'NotFound' }]
2016-03-16 00:53:03 +08:00
params do
requires :foo, type: Integer
end
get :configuration do
2016-05-07 03:00:36 +08:00
{ 'declared_params' => declared(params) }
2016-03-16 00:53:03 +08:00
end
add_swagger_documentation format: :json,
doc_version: '23',
schemes: 'https',
2016-03-16 00:53:03 +08:00
host: -> { 'another.host.com' },
base_path: -> { 'somewhere/over/the/rainbow' },
mount_path: 'documentation',
add_base_path: true,
add_version: true,
security_definitions: { api_key: { foo: 'bar' } },
security: [{ api_key: [] }]
2016-03-16 00:53:03 +08:00
end
end
end
def app
TheApi::ConfigurationApi
end
2016-05-07 03:00:36 +08:00
describe 'shows documentation paths' do
2016-03-16 00:53:03 +08:00
subject do
get '/v3/documentation'
JSON.parse(last_response.body)
end
specify do
expect(subject['info']['version']).to eql '23'
2016-03-16 00:53:03 +08:00
expect(subject['host']).to eql 'another.host.com'
expect(subject['basePath']).to eql 'somewhere/over/the/rainbow'
expect(subject['paths'].keys.first).to eql '/somewhere/over/the/rainbow/v3/configuration'
expect(subject['schemes']).to eql ['https']
expect(subject['securityDefinitions'].keys).to include('api_key')
expect(subject['securityDefinitions']['api_key']).to include('foo' => 'bar')
expect(subject['security']).to include('api_key' => [])
2016-03-16 00:53:03 +08:00
end
end
end