Skip to content

Commit

Permalink
Fix array in query params
Browse files Browse the repository at this point in the history
  • Loading branch information
lan-tripla committed May 6, 2024
1 parent 988f87f commit 6769f2d
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def build_parameter_name(key, value)
if value.is_a?(Hash) && (value_keys = value.keys).size == 1
value_key = value_keys.first
build_parameter_name("#{key}[#{value_key}]", value[value_key])
elsif value.is_a?(Array)
"#{key}[]"
else
key
end
Expand Down
16 changes: 15 additions & 1 deletion spec/apps/rails/doc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,20 @@
"price": "0"
}
},
{
"name": "names[]",
"in": "query",
"required": false,
"schema": {
"type": "array",
"items": {
"type": "string"
}
},
"example": [
"Example Table"
]
},
{
"name": "page",
"in": "query",
Expand Down Expand Up @@ -1240,4 +1254,4 @@
}
},
"custom_field": "custom_value"
}
}
11 changes: 10 additions & 1 deletion spec/apps/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,15 @@ paths:
- price
example:
price: '0'
- name: names[]
in: query
required: false
schema:
type: array
items:
type: string
example:
- Example Table
- name: page
in: query
required: false
Expand All @@ -381,7 +390,7 @@ paths:
example: 10
responses:
'200':
description: with different deep query parameters
description: with array query parameters
headers:
X-Cursor:
schema:
Expand Down
5 changes: 5 additions & 0 deletions spec/requests/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@
get '/tables', params: { filter: { 'price' => 0 } }, headers: { authorization: 'k0kubun' }
expect(response.status).to eq(200)
end

it 'with array query parameters' do
get '/tables', params: { names: ['Example Table'] }, headers: { authorization: 'k0kubun' }
expect(response.status).to eq(200)
end
end

it 'has a request spec which does not make any request' do
Expand Down

0 comments on commit 6769f2d

Please sign in to comment.