-
Notifications
You must be signed in to change notification settings - Fork 64
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
Build deeply nested parameters #29
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,10 +26,18 @@ def normalize_keys(spec) | |
# Should we probably force-merge `summary` regardless of manual modifications? | ||
def deep_reverse_merge!(base, spec) | ||
spec.each do |key, value| | ||
if base[key].is_a?(Hash) && value.is_a?(Hash) | ||
deep_reverse_merge!(base[key], value) | ||
base_key_value = base[key] | ||
if base_key_value.is_a?(Hash) && value.is_a?(Hash) | ||
deep_reverse_merge!(base_key_value, value) | ||
elsif !base.key?(key) | ||
base[key] = value | ||
elsif base_key_value.is_a?(Array) && value.is_a?(Array) | ||
if key == "parameters" | ||
# merge arrays | ||
base[key] |= value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2️⃣ allow multiple parameter members to be built in the same request document |
||
end | ||
else | ||
nil # no-op | ||
end | ||
end | ||
base | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,24 @@ paths: | |
schema: | ||
type: integer | ||
example: 10 | ||
- name: filter[name] | ||
in: query | ||
schema: | ||
type: object | ||
properties: | ||
name: | ||
type: string | ||
example: | ||
name: Example Table | ||
- name: filter[price] | ||
in: query | ||
schema: | ||
type: object | ||
properties: | ||
price: | ||
type: string | ||
example: | ||
price: '0' | ||
responses: | ||
'200': | ||
description: returns a list of tables | ||
|
@@ -63,7 +81,7 @@ paths: | |
database: | ||
id: 2 | ||
name: production | ||
null_sample: | ||
null_sample: | ||
storage_size: 12.3 | ||
created_at: '2020-07-17T00:00:00+00:00' | ||
updated_at: '2020-07-17T00:00:00+00:00' | ||
|
@@ -135,7 +153,7 @@ paths: | |
database: | ||
id: 2 | ||
name: production | ||
null_sample: | ||
null_sample: | ||
storage_size: 12.3 | ||
created_at: '2020-07-17T00:00:00+00:00' | ||
updated_at: '2020-07-17T00:00:00+00:00' | ||
|
@@ -151,6 +169,12 @@ paths: | |
schema: | ||
type: integer | ||
example: 1 | ||
- name: id | ||
in: path | ||
required: true | ||
schema: | ||
type: integer | ||
example: 2 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bug when parameters are otherwise the same but have different examples |
||
responses: | ||
'200': | ||
description: returns a table | ||
|
@@ -188,7 +212,7 @@ paths: | |
database: | ||
id: 2 | ||
name: production | ||
null_sample: | ||
null_sample: | ||
storage_size: 12.3 | ||
created_at: '2020-07-17T00:00:00+00:00' | ||
updated_at: '2020-07-17T00:00:00+00:00' | ||
|
@@ -273,7 +297,7 @@ paths: | |
database: | ||
id: 2 | ||
name: production | ||
null_sample: | ||
null_sample: | ||
storage_size: 12.3 | ||
created_at: '2020-07-17T00:00:00+00:00' | ||
updated_at: '2020-07-17T00:00:00+00:00' | ||
|
@@ -325,7 +349,7 @@ paths: | |
database: | ||
id: 2 | ||
name: production | ||
null_sample: | ||
null_sample: | ||
storage_size: 12.3 | ||
created_at: '2020-07-17T00:00:00+00:00' | ||
updated_at: '2020-07-17T00:00:00+00:00' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,9 +13,21 @@ | |
|
||
RSpec.describe 'Tables', type: :request do | ||
describe '#index' do | ||
it 'returns a list of tables' do | ||
get '/tables', params: { page: '1', per: '10' }, headers: { authorization: 'k0kubun' } | ||
expect(response.status).to eq(200) | ||
context it 'returns a list of tables' do | ||
it 'with flat query parameters' do | ||
get '/tables', params: { page: '1', per: '10' }, headers: { authorization: 'k0kubun' } | ||
expect(response.status).to eq(200) | ||
end | ||
|
||
it 'with deep query parameters' do | ||
get '/tables', params: { filter: { "name" => "Example Table" } }, headers: { authorization: 'k0kubun' } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's just a guess, but maybe the test is passing ignoring this because the above test generates parameters, and running this probably doesn't override it. So copying the same endpoint to somewhere else and calling it from this spec might fix the test issue. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True enough, though I'd like to be able to generate a spec like openapi: 3.0.3
info:
title: rspec-openapi
version: 1.0.0
paths:
"/tables":
get:
summary: index
tags:
- Table
parameters:
- name: page
in: query
schema:
type: integer
example: 1
- name: per
in: query
schema:
type: integer
example: 10
- name: "filter[name]"
in: query
schema:
type: string
example: Example Table
- name: "filter[price]"
in: query
schema:
type: integer
example: 0
responses:
'200':
description: returns a list of tables
content:
application/json:
schema:
anyOf:
- type: array
items:
type: object
# etc it's been a while since I studied the oas spec, so perhaps I'm misunderstanding it... https://swagger.io/docs/specification/describing-responses/
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (If I remove the 'with flat query parameters' spec and rm spec/rails/doc/openapi.yaml and run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree. That's something we should fix as well. But if you're not trying to address that, maybe we should separate that for now and possibly merge them in a PR that addresses the problem. |
||
expect(response.status).to eq(200) | ||
end | ||
|
||
it 'with different deep query parameters' do | ||
get '/tables', params: { filter: { "price" => 0 } }, headers: { authorization: 'k0kubun' } | ||
expect(response.status).to eq(200) | ||
end | ||
end | ||
|
||
it 'has a request spec which does not make any request' do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1️⃣ build
{ "filter" => { "name" => "Benjamin" } }
asfilter[name]
instead offilter