Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/rspec/openapi/schema_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,11 @@ def build_property(value, disposition: nil)

case value
when Array
property[:items] = build_property(value.first)
if value.empty?
property[:items] = {} # unknown
else
property[:items] = build_property(value.first)
end
when Hash
property[:properties] = {}.tap do |properties|
value.each do |key, v|
Expand Down
8 changes: 7 additions & 1 deletion spec/rails/app/controllers/tables_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class TablesController < ApplicationController
before_action :authenticate

def index
render json: [find_table]
render json: find_tables
end

def show
Expand Down Expand Up @@ -35,6 +35,12 @@ def authenticate
end
end

def find_tables
return [] if params.dig(:filter, :name) == 'Never Match'

[find_table]
end

def find_table(id = nil)
time = Time.parse('2020-07-17 00:00:00')
case id
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 @@ -42,6 +42,11 @@
end
end

it 'can return an empty array' do
get '/tables', params: { filter: { "name" => "Never Match" } }, headers: { authorization: 'k0kubun' }
expect(response.status).to eq(200)
end
Comment on lines +45 to +48
Copy link
Owner

@exoego exoego Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this test case passes on the current master branch without the changes on this PR.
I am afraid that the changes are not covered or probably I do not get the intention of this test.

Copy link
Owner

@exoego exoego Jul 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be clearer if the behavior change is covered in the fixture files (JSON/YAML).

          items:
            type: object
            properties:
              id:
                type: integer
              ...
            nullable: true

===>


          items:
            type: object
            properties:
              id:
                type: integer
              ...


it 'has a request spec which does not make any request' do
expect(request).to eq(nil)
end
Expand Down