From 196a4cf4197c8ace6448cdc376fa19943f453e2d Mon Sep 17 00:00:00 2001 From: Ben Radler Date: Thu, 28 Jul 2016 17:08:04 -0700 Subject: [PATCH] Generate enum property if values key is passed in documentation --- lib/grape-swagger/entity/parser.rb | 5 +++-- spec/grape-swagger/entities/response_model_spec.rb | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/grape-swagger/entity/parser.rb b/lib/grape-swagger/entity/parser.rb index 11a16ac..ace31e8 100644 --- a/lib/grape-swagger/entity/parser.rb +++ b/lib/grape-swagger/entity/parser.rb @@ -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] diff --git a/spec/grape-swagger/entities/response_model_spec.rb b/spec/grape-swagger/entities/response_model_spec.rb index f43b57d..2366b7f 100644 --- a/spec/grape-swagger/entities/response_model_spec.rb +++ b/spec/grape-swagger/entities/response_model_spec.rb @@ -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 @@ -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' } } },