Skip to content

Commit a56b56a

Browse files
authored
Assign :example param on array properties (#903)
* Assign :example param on array properties * Update CHANGELOG
1 parent 55267ac commit a56b56a

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#### Fixes
88

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

1112

lib/grape-swagger/doc_methods/move_params.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ def document_as_array(param)
9797
{}.tap do |property|
9898
property[:type] = 'array'
9999
property[:description] = param.delete(:description) unless param[:description].nil?
100+
property[:example] = param.delete(:example) unless param[:example].nil?
100101
property[:items] = document_as_property(param)[:items]
101102
end
102103
end

spec/swagger_v2/params_array_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
# cause it could not be distinguished anymore, so this would be translated to one array,
4040
# see also next example for the difference
4141
params do
42-
requires :array_of_string, type: Array[String], documentation: { param_type: 'body', desc: 'nested array of strings' }
42+
requires :array_of_string, type: Array[String], documentation: { param_type: 'body', desc: 'nested array of strings', example: %w[a b] }
4343
requires :array_of_integer, type: Array[Integer], documentation: { param_type: 'body', desc: 'nested array of integers' }
4444
end
4545

@@ -123,7 +123,7 @@
123123
'type' => 'object',
124124
'properties' => {
125125
'array_of_string' => {
126-
'items' => { 'type' => 'string' }, 'type' => 'array', 'description' => 'nested array of strings'
126+
'items' => { 'type' => 'string' }, 'type' => 'array', 'description' => 'nested array of strings', 'example' => %w[a b]
127127
},
128128
'array_of_integer' => {
129129
'items' => { 'type' => 'integer', 'format' => 'int32' }, 'type' => 'array', 'description' => 'nested array of integers'

0 commit comments

Comments
 (0)