Compare commits

...

29 Commits

Author SHA1 Message Date
Greg Myers
16e40bfcf3
Merge pull request #475 from rswag/fix/workflow
Fix GH Actions being unable to bundle
2022-01-22 22:13:43 +00:00
Greg Myers
8c6aed4a9e
Fix correct gem command
upgrade vs update
2022-01-22 22:12:27 +00:00
Greg Myers
8e59d2b2f2
Fix GH Actions being unable to bundle
Error looks similar to https://github.com/rubygems/rubygems/issues/5150
2022-01-22 22:10:24 +00:00
Greg Myers
a813b63bcc
Merge pull request #450 from marksiemers/master
Loosen gemspec requirement to allow rails 7.0
2021-12-03 22:41:41 +00:00
Greg Myers
076f71388c
Merge pull request #453 from jswk/update-swagger-ui
Update swagger-ui to 3.52.5
2021-12-03 22:39:57 +00:00
Greg Myers
9cfb5bc557
Merge pull request #441 from jaydorsey/jay/better_error_message
Better error message for missing let
2021-12-03 22:39:27 +00:00
Jakub Sawicki
6cafc0c0e5 Update swagger-ui to 3.52.5 2021-10-15 12:06:55 +02:00
Jay Dorsey
86c512f639 Add single quotes around parameter name 2021-09-24 16:11:44 -04:00
Jay Dorsey
32638062d7 Better error message for missing let
I've run into this problem a number of times. The original error message
is actually a `NoMethodError` and it's not always immediately clear what
the solution is, particuarly if you're new to rspec or rswag

Wanted to see if this kind of behavior is something that the rswag team
would be interested in adopting. I have a few other of these in mind
(will do as small PRs, with tests)
2021-09-24 16:10:40 -04:00
Mark Siemers
dd6530b718 Loosen gemspec requirement to allow rails 7.0 2021-09-22 17:32:58 -04:00
Blake Erickson
095906da58
Merge pull request #442 from jaydorsey/jay/mini_racer
Replace therubyracer with mini_racer
2021-08-10 07:12:13 -06:00
Jay Dorsey
a40a06646f Remove therubyracer from contributing 2021-08-08 23:00:40 -04:00
Jay Dorsey
42c8e123a8 Replace therubyracer with mini_racer
therubyracer doesn't appear to be under active development

I didn't need this for PRs that I was doing, but a `bundle install`
failed because of it. I know I can specify the groups as a workaround
but replacing this seems like it might reduce a small barrier to
contributing
2021-08-08 22:40:33 -04:00
Greg Myers
c85fa3b37a
Update README.md 2021-06-16 14:46:04 +01:00
Blake Erickson
985f444834
Merge pull request #426 from smridge/add-reference-to-contributing-doc
Update Contributing Doc with Bundle Install Troubleshooting
2021-05-13 05:09:51 -06:00
Sarah Ridge
1d2a25e231 Update Contributing Doc with Bundle Install Troubleshooting 2021-05-11 09:47:08 -04:00
Blake Erickson
a0680506e2
Merge pull request #416 from mynnx/docs-include-multiple-tags
Document using multiple tags
2021-04-22 17:27:18 -06:00
mynnx
4a32108f78 Document using multiple tags 2021-04-08 15:44:07 -07:00
Blake Erickson
05e22c3bd7
Merge pull request #407 from rswag/revert-300-master
Revert "Add a macro for complexes multiparts"
2021-03-06 14:57:46 -07:00
Blake Erickson
989aab656f
Revert "Add a macro for complexes multiparts" 2021-03-06 14:52:49 -07:00
Blake Erickson
f7036b7e5a
Merge pull request #300 from sobrinho/master
Add a macro for complexes multiparts
2021-03-06 10:22:54 -07:00
Blake Erickson
84ab7a9e4c
Merge pull request #405 from gogainda/master
Add Truffleruby head to CI
2021-03-06 10:01:05 -07:00
Blake Erickson
0169fbab66
Merge pull request #404 from Wolfer/patch-1
Allow use #/components/parameters and other in inherited $refs
2021-03-06 09:58:10 -07:00
Blake Erickson
4c42ad5f97
Merge pull request #406 from mynnx/specs-print-failed-body
Show the response body for comparison when schema checks fail
2021-03-06 09:30:48 -07:00
Blake Erickson
b91b6e5f1e Fix bundler warning
Move rswag-specs under development and test to resolve this warning:

```
Your Gemfile lists the gem rswag-specs (>= 0) more than once.
You should probably keep only one of them.
Remove any duplicate entries and specify the gem only once.
While it's not a problem now, it could cause errors if you change the version of one of them later.
```
2021-03-05 21:34:00 -07:00
mynnx
a34c931bb6 Show the response body for comparison when schema checks fail 2021-03-03 16:32:16 -08:00
Igor Victor
4b7ab9d381
Add Truffleruby head to CI 2021-02-26 17:58:30 +01:00
Serg F
3d3d93f3ab
Allow use #/components/parameters and other in inherited $refs 2021-02-19 15:15:44 +03:00
Gabriel Sobrinho
f8dbd98bbc
Add a macro for complexes multiparts
This will allow to describe multipart in a short way, like JSON payload:

Before:

    put 'Creates a blog with thumbnail' do
      consumes 'multipart/form-data'
      parameter name: :title, in: :formData, type: :string, required: true
      parameter name: :content, in: :formData, type: :string, required: true
      parameter name: :file, in: :formData, type: :file, required: true

      let(:blog) { FactoryBot.build(:blog) }
      let(:title) { blog.title }
      let(:content) { blog.content }
      let(:file) { blog.file }

      ...
    end

After:

    put 'Creates a blog with thumbnail' do
      consumes 'multipart/form-data'
      parameter name: :blog, in: :formData, schema: { '$ref' => '#/definitions/blog' }

      let(:blog) { FactoryBot.attributes_for(:blog) }

      ...
    end

Your mileage may vary but you can always choose the best option.
2020-04-16 22:38:35 -03:00
13 changed files with 71 additions and 20 deletions

View File

@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.6, 2.7]
ruby: [2.6, 2.7, truffleruby-head]
rails: [5.2.4.4, 6.0.3.4]
env:
RAILS_VERSION: ${{ matrix.rails }}
@ -31,6 +31,7 @@ jobs:
- name: Install dependencies
run: |
gem update --system
bundle install
cd rswag-ui && npm install

View File

@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
## [Unreleased]
### Changed
- Update swagger-ui to 3.52.5
## [2.4.0] - 2021-02-09
### Added
- Added `SWAGGER_DRY_RUN` env variable [#274](https://github.com/rswag/rswag/pull/274)

View File

@ -57,11 +57,11 @@ Push to your fork and [submit a Pull Request][pr].
## Updating Swagger UI
Find the latest versions of swagger-ui here:
Find the latest versions of swagger-ui here:
https://github.com/swagger-api/swagger-ui/releases
Update the swagger-ui-dist version in the rswag-ui dependencies
```
```
./rswag-ui/package.json
```

View File

@ -25,23 +25,25 @@ end
gem 'rswag-api', path: './rswag-api'
gem 'rswag-ui', path: './rswag-ui'
group :development, :test do
gem 'rswag-specs', path: './rswag-specs'
end
group :test do
gem 'capybara'
gem 'geckodriver-helper'
gem 'generator_spec'
gem 'rspec-rails'
gem 'selenium-webdriver'
gem 'rswag-specs', path: './rswag-specs'
gem 'test-unit'
end
group :development do
gem 'rswag-specs', path: './rswag-specs'
gem 'rubocop'
end
group :assets do
gem 'therubyracer'
gem 'mini_racer'
gem 'uglifier'
end

View File

@ -5,6 +5,8 @@ rswag
OpenApi 3.0 and Swagger 2.0 compatible!
Seeking maintainers! Got a pet-bug that needs fixing? Just let us know in your issue/pr that you'd like to step up to help.
Rswag extends rspec-rails "request specs" with a Swagger-based DSL for describing and testing API operations. You describe your API operations with a succinct, intuitive syntax, and it automaticaly runs the tests. Once you have green tests, run a rake task to auto-generate corresponding Swagger files and expose them as YAML or JSON endpoints. Rswag also provides an embedded version of the awesome [swagger-ui](https://github.com/swagger-api/swagger-ui) that's powered by the exposed file. This toolchain makes it seamless to go from integration specs, which youre probably doing in some form already, to living documentation for your API consumers.
Api Rswag creates [Swagger](http://swagger.io) tooling for Rails API's. Generate beautiful API documentation, including a UI to explore and test operations, directly from your rspec integration tests.
@ -18,7 +20,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.42.0|
|[master](https://github.com/rswag/rswag/tree/master)|3.0.3|3.52.5|
|[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|
@ -136,7 +138,7 @@ There is also a generator which can help get you started `rails generate rspec:s
path '/blogs/{id}' do
get 'Retrieves a blog' do
tags 'Blogs'
tags 'Blogs', 'Another Tag'
produces 'application/json', 'application/xml'
parameter name: :id, in: :path, type: :string

View File

@ -15,5 +15,5 @@ Gem::Specification.new do |s|
s.files = Dir['{lib}/**/*'] + ['MIT-LICENSE', 'Rakefile']
s.add_dependency 'railties', '>= 3.1', '< 7.0'
s.add_dependency 'railties', '>= 3.1', '< 7.1'
end

View File

@ -194,12 +194,36 @@ module Rswag
def build_json_payload(parameters, example)
body_param = parameters.select { |p| p[:in] == :body }.first
body_param ? example.send(body_param[:name]).to_json : nil
return nil unless body_param
raise(MissingParameterError, body_param[:name]) unless example.respond_to?(body_param[:name])
example.send(body_param[:name]).to_json
end
def doc_version(doc)
doc[:openapi] || doc[:swagger] || '3'
end
end
class MissingParameterError < StandardError
attr_reader :body_param
def initialize(body_param)
@body_param = body_param
end
def message
<<~MSG
Missing parameter '#{body_param}'
Please check your spec. It looks like you defined a body parameter,
but did not declare usage via let. Try adding:
let(:#{body_param}) {}
MSG
end
end
end
end

View File

@ -50,7 +50,11 @@ module Rswag
.merge(schemas)
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
def definitions_or_component_schemas(swagger_doc, version)
@ -62,7 +66,7 @@ module Rswag
swagger_doc.slice(:definitions)
else
components = swagger_doc[:components] || {}
{ components: { schemas: components[:schemas] } }
{ components: components }
end
end
end

View File

@ -15,7 +15,7 @@ Gem::Specification.new do |s|
s.files = Dir['{lib}/**/*'] + ['MIT-LICENSE', 'Rakefile']
s.add_dependency 'activesupport', '>= 3.1', '< 7.0'
s.add_dependency 'railties', '>= 3.1', '< 7.0'
s.add_dependency 'activesupport', '>= 3.1', '< 7.1'
s.add_dependency 'railties', '>= 3.1', '< 7.1'
s.add_dependency 'json-schema', '~> 2.2'
end

View File

@ -160,6 +160,21 @@ module Rswag
end
end
context 'missing body parameter' do
before do
metadata[:operation][:parameters] = [{ name: 'comment', in: :body, schema: { type: 'object' } }]
allow(example).to receive(:comment).and_raise(NoMethodError, "undefined method 'comment'")
allow(example).to receive(:respond_to?).with(:'Content-Type')
allow(example).to receive(:respond_to?).with('comment').and_return(false)
end
it 'uses the referenced metadata to build the request' do
expect do
request[:payload]
end.to raise_error(Rswag::Specs::MissingParameterError, /Missing parameter 'comment'/)
end
end
context 'form payload' do
before do
metadata[:operation][:consumes] = ['multipart/form-data']

View File

@ -5,9 +5,9 @@
"requires": true,
"dependencies": {
"swagger-ui-dist": {
"version": "3.42.0",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.42.0.tgz",
"integrity": "sha512-hTNX6cX7KWtBZgk6ZQSOzsBJhqdCmD5NOIjb6dBPKSnYZidSkIXOcaPMR3+kwxLrj8bDC881bSDlNbLsHikacg=="
"version": "3.52.5",
"resolved": "https://registry.npmjs.org/swagger-ui-dist/-/swagger-ui-dist-3.52.5.tgz",
"integrity": "sha512-8z18eX8G/jbTXYzyNIaobrnD7PSN7yU/YkSasMmajrXtw0FGS64XjrKn5v37d36qmU3o1xLeuYnktshRr7uIFw=="
}
}
}

View File

@ -3,6 +3,6 @@
"version": "1.0.0",
"private": true,
"dependencies": {
"swagger-ui-dist": "3.42.0"
"swagger-ui-dist": "3.52.5"
}
}

View File

@ -15,6 +15,6 @@ Gem::Specification.new do |s|
s.files = Dir.glob('{lib,node_modules}/**/*') + ['MIT-LICENSE', 'Rakefile' ]
s.add_dependency 'actionpack', '>=3.1', '< 7.0'
s.add_dependency 'railties', '>= 3.1', '< 7.0'
s.add_dependency 'actionpack', '>=3.1', '< 7.1'
s.add_dependency 'railties', '>= 3.1', '< 7.1'
end