Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix value of enum to be Array #850

Merged
merged 1 commit into from
Mar 6, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#### Fixes

* [#850](https://github.com/ruby-grape/grape-swagger/pull/850): Fix value of `enum` to be `Array` - [@takahashim](https://github.com/takahashim)
* Your contribution here.


Expand Down
1 change: 1 addition & 0 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Upgrading to >= 1.4.2

- `additionalProperties` has been deprecated and will be removed in a future version of `grape-swagger`. It has been replaced with `additional_properties`.
- The value of the `enum` attribute is now always an Array. If it has only one value, it will be a one-element Array.

### Upgrading to >= 1.4.0

Expand Down
4 changes: 3 additions & 1 deletion lib/grape-swagger/doc_methods/parse_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ def parse_enum_or_range_values(values)
parse_enum_or_range_values(values.call) if values.parameters.empty?
when Range
parse_range_values(values) if values.first.is_a?(Integer)
when Array
{ enum: values }
else
{ enum: values } if values
{ enum: [values] } if values
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/swagger_v2/param_values_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def first_parameter_info(request)
'name' => 'letter',
'type' => 'string',
'required' => true,
'enum' => 'string'
'enum' => %w[string]
}]
end
end
Expand Down