Skip to content
Merged
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 @@ -125,7 +125,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
10 changes: 10 additions & 0 deletions spec/rails/app/controllers/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,14 @@ def show
QBoAAAAASUVORK5CYII='.unpack('m').first
send_data png, type: 'image/png', disposition: 'inline'
end

def index
list = [
{
'name': 'file.png',
'tags': [], # Keep this empty to check empty array is accepted
}
]
render json: list
end
end
2 changes: 1 addition & 1 deletion spec/rails/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

defaults format: 'json' do
resources :tables, only: [:index, :show, :create, :update, :destroy]
resources :images, only: [:show]
resources :images, only: [:index, :show]

get '/test_block' => ->(_env) { [200, { 'Content-Type' => 'text/plain' }, ['A TEST']] }
end
Expand Down
41 changes: 41 additions & 0 deletions spec/rails/doc/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,47 @@
}
}
}
},
"/images": {
"get": {
"summary": "index",
"tags": [
"Image"
],
"responses": {
"200": {
"description": "can return an object with an attribute of empty array",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"tags": {
"type": "array",
"items": {
}
}
}
}
},
"example": [
{
"name": "file.png",
"tags": [

]
}
]
}
}
}
}
}
}
}
}
33 changes: 28 additions & 5 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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'
Expand Down Expand Up @@ -169,7 +169,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'
Expand Down Expand Up @@ -222,7 +222,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'
Expand Down Expand Up @@ -314,7 +314,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'
Expand Down Expand Up @@ -366,7 +366,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'
Expand Down Expand Up @@ -426,3 +426,26 @@ paths:
schema:
type: string
example: AN ENGINE TEST
"/images":
get:
summary: index
tags:
- Image
responses:
'200':
description: can return an object with an attribute of empty array
content:
application/json:
schema:
type: array
items:
type: object
properties:
name:
type: string
tags:
type: array
items: {}
example:
- name: file.png
tags: []
7 changes: 7 additions & 0 deletions spec/requests/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@
expect(response.status).to eq(200)
end
end

describe '#index' do
it 'can return an object with an attribute of empty array' do
get '/images'
expect(response.status).to eq(200)
end
end
end

RSpec.describe 'Extra routes', type: :request do
Expand Down