Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ RSpec/DescribeClass:
# Offense count: 4
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 186
Max: 187

# Offense count: 24
RSpec/LeakyConstantDeclaration:
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Your contribution here.
* [#76](https://github.com/ruby-grape/grape-swagger-entity/pull/76): Update ci matrix and gemfile for multi-version grape testing - [@numbata](https://github.com/numbata).
* [#77](https://github.com/ruby-grape/grape-swagger-entity/pull/77): Allow proc for enum values in documentation - [@krororo](https://github.com/krororo).

#### Fixes

Expand Down
6 changes: 3 additions & 3 deletions lib/grape-swagger/entity/attribute_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ def document_data_type(documentation, data_type)

type[:format] = documentation[:format] if documentation.key?(:format)

if (values = documentation[:values]) && values.is_a?(Array)
type[:enum] = values
end
values = documentation[:values]
values = values.call if values.is_a?(Proc)
type[:enum] = values if values.is_a?(Array)

type
end
Expand Down
4 changes: 3 additions & 1 deletion spec/grape-swagger/entities/response_model_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class Values < Grape::Entity
expose :guid, documentation: { desc: 'Some values', values: %w[a b c], default: 'c' }
expose :uuid, documentation: { desc: 'customer uuid', type: String, format: 'own',
example: 'e3008fba-d53d-4bcc-a6ae-adc56dff8020' }
expose :color, documentation: { desc: 'Color', type: String, values: -> { %w[red blue] } }
end

class Kind < Grape::Entity
Expand Down Expand Up @@ -231,7 +232,8 @@ def app
'properties' => {
'guid' => { 'type' => 'string', 'enum' => %w[a b c], 'default' => 'c', 'description' => 'Some values' },
'uuid' => { 'type' => 'string', 'format' => 'own', 'description' => 'customer uuid',
'example' => 'e3008fba-d53d-4bcc-a6ae-adc56dff8020' }
'example' => 'e3008fba-d53d-4bcc-a6ae-adc56dff8020' },
'color' => { 'type' => 'string', 'enum' => %w[red blue], 'description' => 'Color' }
}
)
expect(subject['TheseApi_Entities_Kind']).to eql(
Expand Down
Loading