2017-03-08 16:32:31 +08:00
|
|
|
# frozen_string_literal: true
|
2017-03-28 17:15:33 +08:00
|
|
|
|
2017-02-01 05:37:03 +08:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe '#537 enum values spec' do
|
|
|
|
let(:app) do
|
|
|
|
Class.new(Grape::API) do
|
2017-02-06 00:20:41 +08:00
|
|
|
namespace :issue_537 do
|
2017-02-01 05:37:03 +08:00
|
|
|
class Spec < Grape::Entity
|
2017-04-07 03:26:40 +08:00
|
|
|
expose :enum_property, documentation: { values: %i[foo bar] }
|
|
|
|
expose :enum_property_default, documentation: { values: %w[a b c], default: 'c' }
|
2017-02-04 00:35:34 +08:00
|
|
|
expose :own_format, documentation: { format: 'log' }
|
2017-02-01 05:37:03 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'create account',
|
|
|
|
success: Spec
|
|
|
|
get do
|
2020-11-01 22:36:52 +08:00
|
|
|
{ message: 'hi' }
|
2017-02-01 05:37:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
add_swagger_documentation format: :json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
subject do
|
|
|
|
get '/swagger_doc'
|
|
|
|
JSON.parse(last_response.body)
|
|
|
|
end
|
|
|
|
|
2017-02-04 00:35:34 +08:00
|
|
|
let(:property) { subject['definitions']['Spec']['properties']['enum_property'] }
|
2017-02-01 05:37:03 +08:00
|
|
|
specify do
|
|
|
|
expect(property).to include 'enum'
|
2017-04-07 03:26:40 +08:00
|
|
|
expect(property['enum']).to eql %w[foo bar]
|
2017-02-01 05:37:03 +08:00
|
|
|
end
|
2017-02-04 00:35:34 +08:00
|
|
|
|
|
|
|
let(:property_default) { subject['definitions']['Spec']['properties']['enum_property_default'] }
|
|
|
|
specify do
|
|
|
|
expect(property_default).to include 'enum'
|
2017-04-07 03:26:40 +08:00
|
|
|
expect(property_default['enum']).to eql %w[a b c]
|
2017-02-04 00:35:34 +08:00
|
|
|
expect(property_default).to include 'default'
|
|
|
|
expect(property_default['default']).to eql 'c'
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:own_format) { subject['definitions']['Spec']['properties']['own_format'] }
|
|
|
|
specify do
|
|
|
|
expect(own_format).to include 'format'
|
|
|
|
expect(own_format['format']).to eql 'log'
|
|
|
|
end
|
2017-02-01 05:37:03 +08:00
|
|
|
end
|