mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-25 15:22:56 +00:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0aca50c66c | ||
|
|
9644a16bce | ||
|
|
52939874d6 | ||
|
|
7ef900ec1d | ||
|
|
c0142093d4 | ||
|
|
1f4ecb3c10 | ||
|
|
aa4e6f2070 | ||
|
|
eadaf34ef6 | ||
|
|
cbaf6cd3e4 | ||
|
|
670c94cc44 | ||
|
|
b86d3063a8 | ||
|
|
9916d3f0b0 | ||
|
|
56eec5948e | ||
|
|
7b01ae1aa1 |
18
CHANGELOG.md
18
CHANGELOG.md
@@ -4,15 +4,25 @@ All notable changes to this project will be documented in this file.
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
## [2.4.0] - 2021-02-09
|
||||
### Added
|
||||
- Added `SWAGGER_DRY_RUN` env variable [#274](https://github.com/rswag/rswag/pull/274)
|
||||
|
||||
## [2.3.3] - 2021-02-07
|
||||
|
||||
### Fixed
|
||||
- Include response examples [#394](https://github.com/rswag/rswag/pull/394)
|
||||
|
||||
### Changed
|
||||
- Update swagger-ui to 3.42.0
|
||||
|
||||
## [2.3.2] - 2021-01-27
|
||||
### Added
|
||||
- RequestBody now supports the `required` flag [#342](https://github.com/rswag/rswag/pull/342)
|
||||
### Changed
|
||||
### Deprecated
|
||||
### Removed
|
||||
### Fixed
|
||||
- Fix response example rendering [#330](https://github.com/rswag/rswag/pull/330)
|
||||
- Fix empty content block [#347](https://github.com/rswag/rswag/pull/347)
|
||||
### Security
|
||||
|
||||
## [2.3.1] - 2020-04-08
|
||||
### Fixed
|
||||
|
||||
13
README.md
13
README.md
@@ -18,7 +18,7 @@ Once you have an API that can describe itself in Swagger, you've opened the trea
|
||||
|
||||
|Rswag Version|Swagger (OpenAPI) Spec.|swagger-ui|
|
||||
|----------|----------|----------|
|
||||
|[master](https://github.com/rswag/rswag/tree/master)|3.0.3|3.28.0|
|
||||
|[master](https://github.com/rswag/rswag/tree/master)|3.0.3|3.42.0|
|
||||
|[2.3.0](https://github.com/rswag/rswag/tree/2.3.0)|3.0.3|3.23.11|
|
||||
|[2.2.0](https://github.com/rswag/rswag/tree/2.2.0)|2.0|3.18.2|
|
||||
|[1.6.0](https://github.com/rswag/rswag/tree/1.6.0)|2.0|2.2.5|
|
||||
@@ -616,15 +616,12 @@ after do |example|
|
||||
end
|
||||
```
|
||||
|
||||
You need to disable --dry-run option for Rspec > 3
|
||||
#### Dry Run Option ####
|
||||
|
||||
<!-- This is now enabled by default in rswag.
|
||||
You need to set the ``` config.swagger_dry_run = false``` value in the spec/spec_helper.rb file.
|
||||
This is one of the more powerful features of rswag. When rswag runs your integration test suite via ```bundle exec rspec```, it will capture the request and response bodies and output those values in the examples section.
|
||||
These integration tests are usually written with ```let``` variables for post body parameters, and since its an integration test the service is returning actual values.
|
||||
We might as well re-use these values and embed them into the generated swagger to provide a more real world example for request/response examples. -->
|
||||
The `--dry-run` option is enabled by default for Rspec 3, but if you need to
|
||||
disable it you can use the environment varible `SWAGGER_DRY_RUN=0` during the
|
||||
generation command or add the following to your `config/environments/test.rb`:
|
||||
|
||||
Add to config/environments/test.rb:
|
||||
```ruby
|
||||
RSpec.configure do |config|
|
||||
config.swagger_dry_run = false
|
||||
|
||||
@@ -28,9 +28,11 @@ module Rswag
|
||||
end
|
||||
|
||||
def swagger_dry_run
|
||||
@swagger_dry_run ||= begin
|
||||
@rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
|
||||
return @swagger_dry_run if defined? @swagger_dry_run
|
||||
if ENV.key?('SWAGGER_DRY_RUN')
|
||||
@rspec_config.swagger_dry_run = ENV['SWAGGER_DRY_RUN'] == '1'
|
||||
end
|
||||
@swagger_dry_run = @rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
|
||||
end
|
||||
|
||||
def swagger_format
|
||||
|
||||
@@ -132,9 +132,8 @@ module Rswag
|
||||
def upgrade_content!(mime_list, target_node)
|
||||
schema = target_node[:schema]
|
||||
return if mime_list.empty? || schema.nil?
|
||||
target_node[:content] ||= {}
|
||||
target_node.merge!(content: {})
|
||||
|
||||
target_node[:content] ||= {}
|
||||
mime_list.each do |mime_type|
|
||||
# TODO upgrade to have content-type specific schema
|
||||
(target_node[:content][mime_type] ||= {}).merge!(schema: schema)
|
||||
|
||||
@@ -28,10 +28,11 @@ module Rswag
|
||||
{
|
||||
path_item: { template: '/blogs', parameters: [{ type: :string }] },
|
||||
operation: { verb: :post, summary: 'Creates a blog', parameters: [{ type: :string }] },
|
||||
response: { code: '201', description: 'blog created', headers: { type: :string }, schema: { '$ref' => '#/definitions/blog' } },
|
||||
response: response_metadata,
|
||||
document: document
|
||||
}
|
||||
end
|
||||
let(:response_metadata) { { code: '201', description: 'blog created', headers: { type: :string }, schema: { '$ref' => '#/definitions/blog' } } }
|
||||
|
||||
context 'with the document tag set to false' do
|
||||
let(:swagger_doc) { { swagger: '2.0' } }
|
||||
@@ -129,6 +130,47 @@ module Rswag
|
||||
)
|
||||
end
|
||||
|
||||
context 'with response example' do
|
||||
let(:response_metadata) do
|
||||
{
|
||||
code: '201',
|
||||
description: 'blog created',
|
||||
headers: { type: :string },
|
||||
content: { 'application/json' => { example: { foo: :bar } } },
|
||||
schema: { '$ref' => '#/definitions/blog' }
|
||||
}
|
||||
end
|
||||
|
||||
it 'adds example to definition' do
|
||||
expect(swagger_doc.slice(:paths)).to match(
|
||||
paths: {
|
||||
'/blogs' => {
|
||||
parameters: [{ schema: { type: :string } }],
|
||||
post: {
|
||||
parameters: [{ schema: { type: :string } }],
|
||||
summary: 'Creates a blog',
|
||||
responses: {
|
||||
'201' => {
|
||||
content: {
|
||||
'application/vnd.my_mime' => {
|
||||
schema: { '$ref' => '#/definitions/blog' }
|
||||
},
|
||||
'application/json' => {
|
||||
schema: { '$ref' => '#/definitions/blog' },
|
||||
example: { foo: :bar }
|
||||
}
|
||||
},
|
||||
description: 'blog created',
|
||||
headers: { schema: { type: :string } }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with empty content' do
|
||||
let(:swagger_doc) do
|
||||
{
|
||||
|
||||
6
rswag-ui/package-lock.json
generated
6
rswag-ui/package-lock.json
generated
@@ -5,9 +5,9 @@
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
"swagger-ui-dist": {
|
||||
"version": "3.28.0",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.28.0.tgz",
|
||||
"integrity": "sha512-aPkfTzPv9djSiZI1NUkWr5HynCUsH+jaJ0WSx+/t19wq7MMGg9clHm9nGoIpAtqml1G51ofI+I75Ym72pukzFg=="
|
||||
"version": "3.42.0",
|
||||
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.42.0.tgz",
|
||||
"integrity": "sha512-hTNX6cX7KWtBZgk6ZQSOzsBJhqdCmD5NOIjb6dBPKSnYZidSkIXOcaPMR3+kwxLrj8bDC881bSDlNbLsHikacg=="
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"swagger-ui-dist": "3.28.0"
|
||||
"swagger-ui-dist": "3.42.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,6 +221,12 @@
|
||||
},
|
||||
"content": {
|
||||
"application/json": {
|
||||
"example": {
|
||||
"id": 1,
|
||||
"title": "Hello world!",
|
||||
"content": "Hello world and hello universe. Thank you all very much!!!",
|
||||
"thumbnail": "thumbnail.png"
|
||||
},
|
||||
"schema": {
|
||||
"$ref": "#/definitions/blog"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user