open_api-rspec 0.1.1 → 0.1.4
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 +4 -4
- data/Gemfile.lock +33 -1
- data/README.md +16 -15
- data/lib/open_api/rspec.rb +5 -3
- data/lib/open_api/rspec/matchers.rb +24 -0
- data/lib/open_api/rspec/{shared_examples/open_api.rb → shared_examples.rb} +3 -3
- data/lib/open_api/rspec/version.rb +2 -2
- data/open_api-rspec.gemspec +3 -1
- metadata +31 -3
- data/lib/open_api/rspec/matchers/open_api.rb +0 -26
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d794023cd314671660f9a383a6a5eaca9b594a670c1faf32057769c6dc4ac155
|
4
|
+
data.tar.gz: 85876684fd5f99d9d8fec1b8cebc56308a5075af61e8ff9d156805fc92971c43
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4cccf63d318af2996d9969537ecab716f4db2f9220fbf8d152f612b0443b34ffade3a0113cf961ceb05550dcf5cea32e68612775e8ff1ff80ae91e3e7371dee2
|
7
|
+
data.tar.gz: 912f041ca7834b155572c472dbbef6c755df25aba4189c686d9619205a5df9f80ca2958906d8db103d7693da75f166b11299e3f244004390acbc39f102ac3603
|
data/Gemfile.lock
CHANGED
@@ -1,13 +1,27 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
open_api-rspec (0.1.
|
4
|
+
open_api-rspec (0.1.4)
|
5
|
+
activesupport
|
5
6
|
open_api-schema_validator
|
6
7
|
rspec
|
7
8
|
|
8
9
|
GEM
|
9
10
|
remote: https://rubygems.org/
|
10
11
|
specs:
|
12
|
+
actionpack (5.1.5)
|
13
|
+
actionview (= 5.1.5)
|
14
|
+
activesupport (= 5.1.5)
|
15
|
+
rack (~> 2.0)
|
16
|
+
rack-test (>= 0.6.3)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
19
|
+
actionview (5.1.5)
|
20
|
+
activesupport (= 5.1.5)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubi (~> 1.4)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
11
25
|
activesupport (5.1.5)
|
12
26
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
27
|
i18n (~> 0.7)
|
@@ -21,6 +35,7 @@ GEM
|
|
21
35
|
ice_nine (~> 0.11.0)
|
22
36
|
thread_safe (~> 0.3, >= 0.3.1)
|
23
37
|
brakeman (4.2.0)
|
38
|
+
builder (3.2.3)
|
24
39
|
bundler-audit (0.6.0)
|
25
40
|
bundler (~> 1.2)
|
26
41
|
thor (~> 0.18)
|
@@ -31,11 +46,13 @@ GEM
|
|
31
46
|
coercible (1.0.0)
|
32
47
|
descendants_tracker (~> 0.0.1)
|
33
48
|
concurrent-ruby (1.0.5)
|
49
|
+
crass (1.0.3)
|
34
50
|
descendants_tracker (0.0.4)
|
35
51
|
thread_safe (~> 0.3, >= 0.3.1)
|
36
52
|
diff-lcs (1.3)
|
37
53
|
docile (1.1.5)
|
38
54
|
equalizer (0.0.11)
|
55
|
+
erubi (1.7.0)
|
39
56
|
httparty (0.16.0)
|
40
57
|
multi_xml (>= 0.5.2)
|
41
58
|
i18n (0.9.5)
|
@@ -53,9 +70,15 @@ GEM
|
|
53
70
|
rubocop
|
54
71
|
simplecov
|
55
72
|
thor
|
73
|
+
loofah (2.2.0)
|
74
|
+
crass (~> 1.0.2)
|
75
|
+
nokogiri (>= 1.5.9)
|
56
76
|
method_source (0.9.0)
|
77
|
+
mini_portile2 (2.3.0)
|
57
78
|
minitest (5.11.3)
|
58
79
|
multi_xml (0.6.0)
|
80
|
+
nokogiri (1.8.2)
|
81
|
+
mini_portile2 (~> 2.3.0)
|
59
82
|
open_api-schema_validator (0.1.0)
|
60
83
|
json-schema
|
61
84
|
parallel (1.12.1)
|
@@ -69,6 +92,14 @@ GEM
|
|
69
92
|
byebug (~> 10.0)
|
70
93
|
pry (~> 0.10)
|
71
94
|
public_suffix (3.0.2)
|
95
|
+
rack (2.0.4)
|
96
|
+
rack-test (0.8.2)
|
97
|
+
rack (>= 1.0, < 3)
|
98
|
+
rails-dom-testing (2.0.3)
|
99
|
+
activesupport (>= 4.2.0)
|
100
|
+
nokogiri (>= 1.6)
|
101
|
+
rails-html-sanitizer (1.0.3)
|
102
|
+
loofah (~> 2.0)
|
72
103
|
rainbow (2.2.2)
|
73
104
|
rake
|
74
105
|
rake (12.3.0)
|
@@ -119,6 +150,7 @@ PLATFORMS
|
|
119
150
|
ruby
|
120
151
|
|
121
152
|
DEPENDENCIES
|
153
|
+
actionpack
|
122
154
|
bundler
|
123
155
|
lois
|
124
156
|
open_api-rspec!
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# OpenApi::
|
1
|
+
# OpenApi::RSpec [](https://travis-ci.org/ketiko/open_api-rspec)
|
2
2
|
|
3
3
|
RSpec matchers and shared examples for OpenApi
|
4
4
|
|
@@ -20,6 +20,21 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
+
Add a file with the following:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
#file: spec/support/openapi_schema.rb
|
27
|
+
|
28
|
+
RSpec.shared_context "Shared OpenAPI JSON" do
|
29
|
+
let(:open_api_json) { '{my open api json schema'} }
|
30
|
+
end
|
31
|
+
|
32
|
+
RSpec.configure do |rspec|
|
33
|
+
rspec.include_context "Shared OpenAPI JSON", type: :request
|
34
|
+
rspec.include_context "Shared OpenAPI JSON", type: :controller
|
35
|
+
end
|
36
|
+
```
|
37
|
+
|
23
38
|
Test if your swagger.json endpoint is a valid schema.
|
24
39
|
|
25
40
|
```ruby
|
@@ -72,20 +87,6 @@ RSpec.describe UsersController, type: :request do
|
|
72
87
|
end
|
73
88
|
```
|
74
89
|
|
75
|
-
Note for the endpoint matcher to work you must declare something like the following:
|
76
|
-
|
77
|
-
```ruby
|
78
|
-
#file: spec/support/openapi_schema.rb
|
79
|
-
|
80
|
-
RSpec.shared_context "Shared OpenAPI JSON" do
|
81
|
-
let(:open_api_json) { '{my open api json schema'} }
|
82
|
-
end
|
83
|
-
|
84
|
-
RSpec.configure do |rspec|
|
85
|
-
rspec.include_context "Shared OpenAPI JSON", type: :request
|
86
|
-
end
|
87
|
-
```
|
88
|
-
|
89
90
|
## Development
|
90
91
|
|
91
92
|
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.
|
data/lib/open_api/rspec.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'rspec'
|
4
|
+
require 'active_support/core_ext/hash/except'
|
5
|
+
require 'active_support/core_ext/hash/indifferent_access'
|
4
6
|
require 'open_api/schema_validator'
|
5
7
|
require 'open_api/rspec/version'
|
6
8
|
require 'open_api/rspec/schema_parser'
|
7
|
-
require 'open_api/rspec/matchers
|
8
|
-
require 'open_api/rspec/shared_examples
|
9
|
+
require 'open_api/rspec/matchers'
|
10
|
+
require 'open_api/rspec/shared_examples'
|
9
11
|
|
10
12
|
module OpenApi
|
11
|
-
module
|
13
|
+
module RSpec
|
12
14
|
end
|
13
15
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module OpenApi
|
4
|
+
module RSpec
|
5
|
+
module Matchers
|
6
|
+
::RSpec::Matchers.define :match_openapi_response_schema do |schema|
|
7
|
+
match do |response|
|
8
|
+
::OpenApi::SchemaValidator.validate_schema!(
|
9
|
+
open_api_json,
|
10
|
+
response.is_a?(Hash) ? response : ::JSON.parse(response.body),
|
11
|
+
fragment: "#/definitions/#{schema}"
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
::RSpec::Matchers.define :be_valid_openapi_schema do
|
17
|
+
match do |string|
|
18
|
+
json = ::JSON.parse(string)
|
19
|
+
::OpenApi::SchemaValidator.validate!(json)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -5,7 +5,7 @@ module OpenApi
|
|
5
5
|
module SharedExamples
|
6
6
|
::RSpec.shared_examples_for :an_openapi_endpoint do
|
7
7
|
let(:schema_hash) { ::JSON.parse(open_api_json) }
|
8
|
-
let(:schema_parser) { SchemaParser.new(schema_hash, request, response) }
|
8
|
+
let(:schema_parser) { OpenApi::RSpec::SchemaParser.new(schema_hash, request, response) }
|
9
9
|
|
10
10
|
it 'has openapi documentation for url' do
|
11
11
|
expect(schema_parser.schema_for_url).not_to be_nil
|
@@ -50,11 +50,11 @@ module OpenApi
|
|
50
50
|
end
|
51
51
|
it 'matches the response schema' do
|
52
52
|
response_schema = schema_parser.schema_for_url_and_request_method_and_response_status
|
53
|
-
results = if response_schema[
|
53
|
+
results = if response_schema['schema']
|
54
54
|
::OpenApi::SchemaValidator.validate_schema!(
|
55
55
|
schema_hash,
|
56
56
|
::JSON.parse(response.body),
|
57
|
-
fragment: response_schema[
|
57
|
+
fragment: response_schema['schema']['$ref']
|
58
58
|
)
|
59
59
|
else
|
60
60
|
response_schema
|
data/open_api-rspec.gemspec
CHANGED
@@ -5,7 +5,7 @@ require "open_api/rspec/version"
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "open_api-rspec"
|
8
|
-
spec.version = OpenApi::
|
8
|
+
spec.version = OpenApi::RSpec::VERSION
|
9
9
|
spec.authors = ["Ryan Hansen"]
|
10
10
|
spec.email = ["ketiko@gmail.com"]
|
11
11
|
|
@@ -28,7 +28,9 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_development_dependency 'rubocop-rspec'
|
29
29
|
spec.add_development_dependency 'simplecov'
|
30
30
|
spec.add_development_dependency 'pry-byebug'
|
31
|
+
spec.add_development_dependency 'actionpack'
|
31
32
|
|
32
33
|
spec.add_dependency 'rspec'
|
33
34
|
spec.add_dependency 'open_api-schema_validator'
|
35
|
+
spec.add_dependency 'activesupport'
|
34
36
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_api-rspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Hansen
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: actionpack
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
- !ruby/object:Gem::Dependency
|
126
140
|
name: rspec
|
127
141
|
requirement: !ruby/object:Gem::Requirement
|
@@ -150,6 +164,20 @@ dependencies:
|
|
150
164
|
- - ">="
|
151
165
|
- !ruby/object:Gem::Version
|
152
166
|
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: activesupport
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
153
181
|
description: RSpec matchers and shared examples for OpenApi
|
154
182
|
email:
|
155
183
|
- ketiko@gmail.com
|
@@ -176,9 +204,9 @@ files:
|
|
176
204
|
- bin/rubocop
|
177
205
|
- bin/setup
|
178
206
|
- lib/open_api/rspec.rb
|
179
|
-
- lib/open_api/rspec/matchers
|
207
|
+
- lib/open_api/rspec/matchers.rb
|
180
208
|
- lib/open_api/rspec/schema_parser.rb
|
181
|
-
- lib/open_api/rspec/shared_examples
|
209
|
+
- lib/open_api/rspec/shared_examples.rb
|
182
210
|
- lib/open_api/rspec/version.rb
|
183
211
|
- open_api-rspec.gemspec
|
184
212
|
homepage: https://github.com/ketiko/open_api-rspec
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module OpenApi
|
4
|
-
module RSpec
|
5
|
-
module Matchers
|
6
|
-
module OpenApi
|
7
|
-
::RSpec::Matchers.define :match_openapi_response_schema do |schema|
|
8
|
-
match do |response|
|
9
|
-
::OpenApi::SchemaValidator.validate_schema!(
|
10
|
-
SwaggerSchema.to_h,
|
11
|
-
response.is_a?(Hash) ? response : ::JSON.parse(response.body),
|
12
|
-
fragment: "#/definitions/#{schema}"
|
13
|
-
)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
::RSpec::Matchers.define :be_valid_openapi_schema do
|
18
|
-
match do |string|
|
19
|
-
json = ::JSON.parse(string)
|
20
|
-
::OpenApi::SchemaValidator.validate!(json)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|