mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-22 22:06:43 +00:00
Merge remote-tracking branch 'olegkyz/bugfix/examples-content' into jamie
This commit is contained in:
commit
7e2c52b242
@ -608,7 +608,11 @@ To enable examples generation from responses add callback above run_test! like:
|
||||
|
||||
```
|
||||
after do |example|
|
||||
example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) }
|
||||
example.metadata[:response][:content] = {
|
||||
'application/json' => {
|
||||
example: JSON.parse(response.body, symbolize_names: true)
|
||||
}
|
||||
}
|
||||
end
|
||||
```
|
||||
|
||||
|
||||
@ -19,7 +19,11 @@ RSpec.describe '<%= controller_path %>', type: :request do
|
||||
<% end -%>
|
||||
|
||||
after do |example|
|
||||
example.metadata[:response][:examples] = { 'application/json' => JSON.parse(response.body, symbolize_names: true) }
|
||||
example.metadata[:response][:content] = {
|
||||
'application/json' => {
|
||||
example: JSON.parse(response.body, symbolize_names: true)
|
||||
}
|
||||
}
|
||||
end
|
||||
run_test!
|
||||
end
|
||||
|
||||
@ -72,7 +72,10 @@ module Rswag
|
||||
def examples(example = nil)
|
||||
return super() if example.nil?
|
||||
|
||||
metadata[:response][:examples] = example
|
||||
metadata[:response][:content] =
|
||||
example.each_with_object({}) do |(mime, example_object), memo|
|
||||
memo[mime] = { example: example_object }
|
||||
end
|
||||
end
|
||||
|
||||
def run_test!(&block)
|
||||
|
||||
@ -129,13 +129,13 @@ module Rswag
|
||||
end
|
||||
|
||||
def upgrade_content!(mime_list, target_node)
|
||||
target_node.merge!(content: {})
|
||||
target_node[:content] ||= {}
|
||||
schema = target_node[:schema]
|
||||
return if mime_list.empty? || schema.nil?
|
||||
|
||||
mime_list.each do |mime_type|
|
||||
# TODO upgrade to have content-type specific schema
|
||||
target_node[:content][mime_type] = { schema: schema }
|
||||
(target_node[:content][mime_type] ||= {}).merge!(schema: schema)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -137,9 +137,10 @@ module Rswag
|
||||
end
|
||||
|
||||
describe '#examples(example)' do
|
||||
let(:mime) { 'application/json' }
|
||||
let(:json_example) do
|
||||
{
|
||||
'application/json' => {
|
||||
mime => {
|
||||
foo: 'bar'
|
||||
}
|
||||
}
|
||||
@ -151,7 +152,11 @@ module Rswag
|
||||
end
|
||||
|
||||
it "adds to the 'response examples' metadata" do
|
||||
expect(api_metadata[:response][:examples]).to eq(json_example)
|
||||
expect(api_metadata[:response][:content]).to match(
|
||||
mime => {
|
||||
example: json_example[mime]
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -235,16 +235,14 @@
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"examples": {
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"id": 1,
|
||||
"title": "Hello world!",
|
||||
"content": "Hello world and hello universe. Thank you all very much!!!",
|
||||
"thumbnail": "thumbnail.png"
|
||||
}
|
||||
},
|
||||
"content": {
|
||||
"application/json": {
|
||||
"schema": {
|
||||
"$ref": "#/definitions/blog"
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user