Skip to content

Commit

Permalink
Generate enum property if values key is passed in documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Lordnibbler committed Jul 29, 2016
1 parent b8b99c4 commit 196a4cf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions lib/grape-swagger/entity/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def parse_grape_entity_params(params)
}
end

if entity_options[:values] && entity_options[:values].is_a?(Array)
memo[entity_name][:enum] = entity_options[:values]
if entity_options[:documentation] && entity_options[:documentation][:values]
values = entity_options[:documentation][:values]
memo[entity_name][:enum] = values if values.is_a?(Array)
end

if entity_options[:documentation] && entity_options[:documentation][:is_array]
Expand Down
8 changes: 4 additions & 4 deletions spec/grape-swagger/entities/response_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ def app
end
end

describe 'should build definition from given entity' do
describe 'building definitions from given entities' do
before :all do
module TheseApi
module Entities
class Kind < Grape::Entity
expose :id, documentation: { type: Integer, desc: 'Title of the kind.' }
expose :id, documentation: { type: Integer, desc: 'Title of the kind.', values: [1, 2] }
end

class Relation < Grape::Entity
Expand Down Expand Up @@ -187,12 +187,12 @@ def app
JSON.parse(last_response.body)
end

it 'it prefer entity over others' do
it 'prefers entity over other `using` values' do
expect(subject['definitions']).to eql(
'Kind' => {
'type' => 'object',
'properties' => {
'id' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'Title of the kind.' }
'id' => { 'type' => 'integer', 'format' => 'int32', 'description' => 'Title of the kind.', 'enum' => [1, 2] }
}
},
'Tag' => { 'type' => 'object', 'properties' => { 'name' => { 'type' => 'string', 'description' => 'Name' } } },
Expand Down

0 comments on commit 196a4cf

Please sign in to comment.