openapi_rspec 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +47 -0
- data/lib/openapi_rspec/documentation_validator.rb +16 -0
- data/lib/openapi_rspec/matchers.rb +14 -0
- data/lib/openapi_rspec/request_validator.rb +68 -0
- data/lib/openapi_rspec/version.rb +3 -0
- data/lib/openapi_rspec.rb +22 -0
- metadata +148 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b9f9ec3e1e0cb9018ac93737caeac7449033514d8394f2059e3f7f26b9e75d0
|
4
|
+
data.tar.gz: acfb5e12dec63680f74203c8e8d3356b4421952f969237bd3ba5b32c7f74c8d4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4cba7fc2504377bcb3a975d62c6d04bb8f5bcd8409fc9571a90fc65748427af5feac6c927c3992f57be463e431855b2d4f62628783fd0c13b71d572d58e2c7f1
|
7
|
+
data.tar.gz: a86a7efecf68cf4330d8efa5bcfa9b86eb6229488f85f6d33eb35d9a69e69dde8c87ed710a5c48a7437134e816084bf01920625cf13a9e4e475c178a537501db
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 Svyatoslav Kryukov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
[gem]: https://rubygems.org/gems/openapi_rspec
|
2
|
+
[travis]: https://travis-ci.org/llcmedsolutions/openapi_rspec
|
3
|
+
[codeclimate]: https://codeclimate.com/github/llcmedsolutions/openapi_rspec
|
4
|
+
|
5
|
+
# openapi_rspec
|
6
|
+
[][gem]
|
7
|
+
[][travis]
|
8
|
+
[][codeclimate]
|
9
|
+
[][codeclimate]
|
10
|
+
|
11
|
+
Test your API against OpenApi v3 documentation
|
12
|
+
|
13
|
+
Inspired by [Apivore](https://github.com/westfieldlabs/apivore)
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
Add this line to your application's Gemfile:
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'openapi_rspec'
|
21
|
+
```
|
22
|
+
|
23
|
+
And then execute:
|
24
|
+
|
25
|
+
$ bundle
|
26
|
+
|
27
|
+
Or install it yourself as:
|
28
|
+
|
29
|
+
$ gem install openapi_rspec
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
TODO: Write usage instructions here
|
34
|
+
|
35
|
+
## Development
|
36
|
+
|
37
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
38
|
+
|
39
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/llcmedsolutions/openapi_rspec.
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module OpenapiRspec
|
2
|
+
class DocumentationValidator
|
3
|
+
def matches?(doc)
|
4
|
+
@result = doc.validate_documentation
|
5
|
+
@result.valid?
|
6
|
+
end
|
7
|
+
|
8
|
+
def description
|
9
|
+
"be a valid documentation"
|
10
|
+
end
|
11
|
+
|
12
|
+
def failure_message
|
13
|
+
@result.errors.join("\n")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "openapi_rspec/documentation_validator"
|
2
|
+
require "openapi_rspec/request_validator"
|
3
|
+
|
4
|
+
module OpenapiRspec
|
5
|
+
module Matchers
|
6
|
+
def validate_documentation
|
7
|
+
DocumentationValidator.new
|
8
|
+
end
|
9
|
+
|
10
|
+
def validate_request(**attrs)
|
11
|
+
RequestValidator.new(**attrs)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require "rack/test"
|
2
|
+
require "uri"
|
3
|
+
|
4
|
+
module OpenapiRspec
|
5
|
+
class RequestValidator
|
6
|
+
include Rack::Test::Methods
|
7
|
+
|
8
|
+
def app
|
9
|
+
OpenapiRspec.app
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(path:, method:, code:, params: {}, query: {}, headers: {})
|
13
|
+
@path = path
|
14
|
+
@method = method
|
15
|
+
@code = code
|
16
|
+
@query = query
|
17
|
+
@headers = headers
|
18
|
+
@params = params
|
19
|
+
end
|
20
|
+
|
21
|
+
attr_reader :method, :path, :code, :query, :headers, :params
|
22
|
+
|
23
|
+
def matches?(doc)
|
24
|
+
@result = doc.validate_request(path: path, method: method, code: code)
|
25
|
+
return false unless @result.valid?
|
26
|
+
|
27
|
+
headers.each do |key, value|
|
28
|
+
header key, value
|
29
|
+
end
|
30
|
+
request(request_uri(doc), method: method, **request_params)
|
31
|
+
response = last_response
|
32
|
+
@result.validate_response(body: response.body, code: response.status)
|
33
|
+
@result.valid?
|
34
|
+
end
|
35
|
+
|
36
|
+
def request_uri(doc)
|
37
|
+
path.scan(/\{([^\}]*)\}/).each do |param|
|
38
|
+
key = param.first.to_sym
|
39
|
+
if params && params[key]
|
40
|
+
@path = path.gsub "{#{key}}", params.delete(key).to_s
|
41
|
+
else
|
42
|
+
raise URI::InvalidURIError, "No substitution data found for {#{key}}"\
|
43
|
+
" to test the path #{path}."
|
44
|
+
end
|
45
|
+
end
|
46
|
+
"#{doc.api_base_path}#{path}?#{URI.encode_www_form(query)}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def request_params
|
50
|
+
{
|
51
|
+
headers: headers,
|
52
|
+
params: params,
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def description
|
57
|
+
"return valid response with code #{code} on `#{method.to_s.upcase} #{path}`"
|
58
|
+
end
|
59
|
+
|
60
|
+
def failure_message
|
61
|
+
if last_response
|
62
|
+
(%W(Response: #{last_response.body}) + @result.errors).join("\n")
|
63
|
+
else
|
64
|
+
@result.errors.join("\n")
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "dry-configurable"
|
2
|
+
require "openapi_validator"
|
3
|
+
require "openapi_builder"
|
4
|
+
require "rspec"
|
5
|
+
|
6
|
+
require "openapi_rspec/matchers"
|
7
|
+
require "openapi_rspec/version"
|
8
|
+
|
9
|
+
module OpenapiRspec
|
10
|
+
extend Dry::Configurable
|
11
|
+
|
12
|
+
setting :app, reader: true
|
13
|
+
|
14
|
+
def self.api(doc, build: false, **params)
|
15
|
+
doc = OpenapiBuilder.call(doc).data if build
|
16
|
+
OpenapiValidator.call(doc, **params)
|
17
|
+
end
|
18
|
+
|
19
|
+
RSpec.configure do |config|
|
20
|
+
config.include Matchers
|
21
|
+
end
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: openapi_rspec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Svyatoslav Kryukov
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-04-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: dry-configurable
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.8'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: openapi_builder
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.1'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: openapi_validator
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rack-test
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.1'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.1'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rake
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '10.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '10.0'
|
111
|
+
description:
|
112
|
+
email:
|
113
|
+
- s.g.kryukov@yandex.ru
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- LICENSE.txt
|
119
|
+
- README.md
|
120
|
+
- lib/openapi_rspec.rb
|
121
|
+
- lib/openapi_rspec/documentation_validator.rb
|
122
|
+
- lib/openapi_rspec/matchers.rb
|
123
|
+
- lib/openapi_rspec/request_validator.rb
|
124
|
+
- lib/openapi_rspec/version.rb
|
125
|
+
homepage: https://github.com/llcmedsolutions/openapi_rspec
|
126
|
+
licenses:
|
127
|
+
- MIT
|
128
|
+
metadata: {}
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
require_paths:
|
132
|
+
- lib
|
133
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
134
|
+
requirements:
|
135
|
+
- - ">="
|
136
|
+
- !ruby/object:Gem::Version
|
137
|
+
version: '2.4'
|
138
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
requirements: []
|
144
|
+
rubygems_version: 3.0.3
|
145
|
+
signing_key:
|
146
|
+
specification_version: 4
|
147
|
+
summary: Test your API against OpenApi v3 documentation
|
148
|
+
test_files: []
|