keep examples content

This commit is contained in:
Oleg Yakovenko 2020-06-04 16:21:43 +03:00
parent 7ceedab4cb
commit 9c297317b2
3 changed files with 30 additions and 23 deletions

View File

@ -597,7 +597,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
```
@ -900,4 +904,3 @@ docker run -d -p 80:8080 swaggerapi/swagger-editor
```
This will run the swagger editor in the docker daemon and can be accessed
at ```http://localhost```. From here, you can use the UI to load the generated swagger.json to validate the output.

View File

@ -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

View File

@ -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