Build deeply nested parameters - #29
Conversation
and test building out multiple parameters
51e61da to
37277f7
Compare
Yeah, I'm curious about why the test is passing without any changes too. |
|
Since neither rspec nor rake ran all the specs, I ran |
|
I didn't really dig into how the merging works, but I confirmed on my local that it's still creating only one (❤️ for this project. I also liked the https://github.com/r7kamura/autodoc quite a bit. 🙌 ) |
|
I can also write a unit test in the meantime if you'd like. I tried to follow the pattern of the repo. |
🤝 |
| end | ||
|
|
||
| it 'with deep query parameters' do | ||
| get '/tables', params: { filter: { "name" => "Example Table" } }, headers: { authorization: 'k0kubun' } |
There was a problem hiding this comment.
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.
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
# etcit's been a while since I studied the oas spec, so perhaps I'm misunderstanding it...
https://swagger.io/docs/specification/describing-responses/
Can I have different responses based on a request parameter? Such as:
GET /something -> {200, schema_1}
GET /something?foo=bar -> {200, schema_2}
In OpenAPI 3.0, you can use `oneOf` to specify alternate schemas for the response and document possible dependencies verbally in the response description. However, there is no way to link specific schemas to certain parameter combinations.
There was a problem hiding this comment.
(If I remove the 'with flat query parameters' spec and rm spec/rails/doc/openapi.yaml and run OPENAPI=1 bundle exec rspec spec/requests/rails_spec.rb it generates a new spec but still with only one param. )
There was a problem hiding this comment.
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.
|
|
||
| def build_parameter_name(key, value) | ||
| key = key.to_s | ||
| if value.is_a?(Hash) && (value_keys = value.keys).size == 1 |
There was a problem hiding this comment.
1️⃣ build { "filter" => { "name" => "Benjamin" } } as filter[name] instead of filter
| 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.
2️⃣ allow multiple parameter members to be built in the same request document
| required: true | ||
| schema: | ||
| type: integer | ||
| example: 2 |
There was a problem hiding this comment.
bug when parameters are otherwise the same but have different examples
Build deeply nested parameters
e.g. with query params { "filter" => { "name" => "Benjamin" } }
now:
build_parameter_name("filter", { "name" => "Benjamin" })#=> filter[name]before:
"filter".to_s#=> filterfailing test building out multiple parameters. (I'm not yet sure why it didn't rebuild to the yaml or test it)
xref OAI/OpenAPI-Specification#1706 https://github.com/ahx/openapi_first/pull/75/files