Assign :example param on array properties (#903)

* Assign :example param on array properties

* Update CHANGELOG
This commit is contained in:
Vladislav Momatau 2023-09-11 10:54:22 +03:00 committed by GitHub
parent 55267acd39
commit a56b56aaf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 2 deletions

View File

@ -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.

View File

@ -97,6 +97,7 @@ module GrapeSwagger
{}.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

View File

@ -39,7 +39,7 @@ describe 'Group Params as Array' do
# 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
@ -123,7 +123,7 @@ describe 'Group Params as Array' do
'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'