Skip to content

Commit

Permalink
Assign :example param on array properties (#903)
Browse files Browse the repository at this point in the history
* Assign :example param on array properties

* Update CHANGELOG
  • Loading branch information
VladMomotov authored Sep 11, 2023
1 parent 55267ac commit a56b56a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
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

* [#903](https://github.com/ruby-grape/grape-swagger/pull/903): Accept `example` documentation parameter for arrays - [@VladMomotov](https://github.com/VladMomotov)
* Your contribution here.


Expand Down
1 change: 1 addition & 0 deletions lib/grape-swagger/doc_methods/move_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ def document_as_array(param)
{}.tap do |property|
property[:type] = 'array'
property[:description] = param.delete(:description) unless param[:description].nil?
property[:example] = param.delete(:example) unless param[:example].nil?
property[:items] = document_as_property(param)[:items]
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/swagger_v2/params_array_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
# cause it could not be distinguished anymore, so this would be translated to one array,
# see also next example for the difference
params do
requires :array_of_string, type: Array[String], documentation: { param_type: 'body', desc: 'nested array of strings' }
requires :array_of_string, type: Array[String], documentation: { param_type: 'body', desc: 'nested array of strings', example: %w[a b] }
requires :array_of_integer, type: Array[Integer], documentation: { param_type: 'body', desc: 'nested array of integers' }
end

Expand Down Expand Up @@ -123,7 +123,7 @@
'type' => 'object',
'properties' => {
'array_of_string' => {
'items' => { 'type' => 'string' }, 'type' => 'array', 'description' => 'nested array of strings'
'items' => { 'type' => 'string' }, 'type' => 'array', 'description' => 'nested array of strings', 'example' => %w[a b]
},
'array_of_integer' => {
'items' => { 'type' => 'integer', 'format' => 'int32' }, 'type' => 'array', 'description' => 'nested array of integers'
Expand Down

0 comments on commit a56b56a

Please sign in to comment.