mirror of
https://github.com/ditkrg/rswag.git
synced 2026-01-26 07:42:58 +00:00
Compare commits
16 Commits
2.3.3
...
revert-300
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
989aab656f | ||
|
|
f7036b7e5a | ||
|
|
84ab7a9e4c | ||
|
|
0169fbab66 | ||
|
|
4c42ad5f97 | ||
|
|
b91b6e5f1e | ||
|
|
a34c931bb6 | ||
|
|
4b7ab9d381 | ||
|
|
3d3d93f3ab | ||
|
|
0aca50c66c | ||
|
|
9644a16bce | ||
|
|
52939874d6 | ||
|
|
f8dbd98bbc | ||
|
|
9916d3f0b0 | ||
|
|
56eec5948e | ||
|
|
7b01ae1aa1 |
2
.github/workflows/ruby.yml
vendored
2
.github/workflows/ruby.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
ruby: [2.6, 2.7]
|
ruby: [2.6, 2.7, truffleruby-head]
|
||||||
rails: [5.2.4.4, 6.0.3.4]
|
rails: [5.2.4.4, 6.0.3.4]
|
||||||
env:
|
env:
|
||||||
RAILS_VERSION: ${{ matrix.rails }}
|
RAILS_VERSION: ${{ matrix.rails }}
|
||||||
|
|||||||
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|||||||
|
|
||||||
## [Unreleased]
|
## [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
|
## [2.3.3] - 2021-02-07
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
6
Gemfile
6
Gemfile
@@ -25,18 +25,20 @@ end
|
|||||||
gem 'rswag-api', path: './rswag-api'
|
gem 'rswag-api', path: './rswag-api'
|
||||||
gem 'rswag-ui', path: './rswag-ui'
|
gem 'rswag-ui', path: './rswag-ui'
|
||||||
|
|
||||||
|
group :development, :test do
|
||||||
|
gem 'rswag-specs', path: './rswag-specs'
|
||||||
|
end
|
||||||
|
|
||||||
group :test do
|
group :test do
|
||||||
gem 'capybara'
|
gem 'capybara'
|
||||||
gem 'geckodriver-helper'
|
gem 'geckodriver-helper'
|
||||||
gem 'generator_spec'
|
gem 'generator_spec'
|
||||||
gem 'rspec-rails'
|
gem 'rspec-rails'
|
||||||
gem 'selenium-webdriver'
|
gem 'selenium-webdriver'
|
||||||
gem 'rswag-specs', path: './rswag-specs'
|
|
||||||
gem 'test-unit'
|
gem 'test-unit'
|
||||||
end
|
end
|
||||||
|
|
||||||
group :development do
|
group :development do
|
||||||
gem 'rswag-specs', path: './rswag-specs'
|
|
||||||
gem 'rubocop'
|
gem 'rubocop'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
11
README.md
11
README.md
@@ -616,15 +616,12 @@ after do |example|
|
|||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
You need to disable --dry-run option for Rspec > 3
|
#### Dry Run Option ####
|
||||||
|
|
||||||
<!-- This is now enabled by default in rswag.
|
The `--dry-run` option is enabled by default for Rspec 3, but if you need to
|
||||||
You need to set the ``` config.swagger_dry_run = false``` value in the spec/spec_helper.rb file.
|
disable it you can use the environment varible `SWAGGER_DRY_RUN=0` during the
|
||||||
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.
|
generation command or add the following to your `config/environments/test.rb`:
|
||||||
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. -->
|
|
||||||
|
|
||||||
Add to config/environments/test.rb:
|
|
||||||
```ruby
|
```ruby
|
||||||
RSpec.configure do |config|
|
RSpec.configure do |config|
|
||||||
config.swagger_dry_run = false
|
config.swagger_dry_run = false
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ module Rswag
|
|||||||
end
|
end
|
||||||
|
|
||||||
def swagger_dry_run
|
def swagger_dry_run
|
||||||
@swagger_dry_run ||= begin
|
return @swagger_dry_run if defined? @swagger_dry_run
|
||||||
@rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
|
if ENV.key?('SWAGGER_DRY_RUN')
|
||||||
|
@rspec_config.swagger_dry_run = ENV['SWAGGER_DRY_RUN'] == '1'
|
||||||
end
|
end
|
||||||
|
@swagger_dry_run = @rspec_config.swagger_dry_run.nil? || @rspec_config.swagger_dry_run
|
||||||
end
|
end
|
||||||
|
|
||||||
def swagger_format
|
def swagger_format
|
||||||
|
|||||||
@@ -50,7 +50,11 @@ module Rswag
|
|||||||
.merge(schemas)
|
.merge(schemas)
|
||||||
|
|
||||||
errors = JSON::Validator.fully_validate(validation_schema, body)
|
errors = JSON::Validator.fully_validate(validation_schema, body)
|
||||||
raise UnexpectedResponse, "Expected response body to match schema: #{errors[0]}" if errors.any?
|
return unless errors.any?
|
||||||
|
|
||||||
|
raise UnexpectedResponse,
|
||||||
|
"Expected response body to match schema: #{errors[0]}\n" \
|
||||||
|
"Response body: #{JSON.pretty_generate(JSON.parse(body))}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def definitions_or_component_schemas(swagger_doc, version)
|
def definitions_or_component_schemas(swagger_doc, version)
|
||||||
@@ -62,7 +66,7 @@ module Rswag
|
|||||||
swagger_doc.slice(:definitions)
|
swagger_doc.slice(:definitions)
|
||||||
else
|
else
|
||||||
components = swagger_doc[:components] || {}
|
components = swagger_doc[:components] || {}
|
||||||
{ components: { schemas: components[:schemas] } }
|
{ components: components }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user