openapi_contracts 0.4.2 → 0.6.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 +4 -4
- data/README.md +13 -0
- data/lib/openapi_contracts/doc/parser.rb +3 -3
- data/lib/openapi_contracts/doc.rb +2 -2
- data/lib/openapi_contracts/matchers/match_openapi_doc.rb +3 -2
- data/lib/openapi_contracts/matchers.rb +2 -2
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc0a8f6f92b0615788c15cd3d715fe4308e1058616c6f892140addbcae3b9232
|
4
|
+
data.tar.gz: f7328963227bc196797674e1bd5f04af471a05507d0ec848a8386da5a568c1aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 550501aa45c7e5b66dfa666ecc3354b41a5f8c49d067490c91a964b0bf338ca55b5e785ae578c0e82da15f5d5fdbe2bcd94c99e716fee81d7506ccd7cc05aa24
|
7
|
+
data.tar.gz: fa614dbb218e74bf497ac25d46d284bf32e6c9de9bda65a819f12f26a8172e405c9cd8ad1958fd760b69501e8e98214bdfb63c97e404bdfcb2590c47f1c21a8e
|
data/README.md
CHANGED
@@ -43,6 +43,19 @@ it 'responds with 200 and matches the doc' do
|
|
43
43
|
}
|
44
44
|
```
|
45
45
|
|
46
|
+
### Options
|
47
|
+
|
48
|
+
The `match_openapi_doc($doc)` method allows passing options as a 2nd argument.
|
49
|
+
This allows overriding the default request.path lookup in case this does not find
|
50
|
+
the correct response definition in your schema. This is especially important with
|
51
|
+
dynamic paths.
|
52
|
+
|
53
|
+
Example:
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
it { is_expected.to match_openapi_doc($api_doc, path: '/messages/{id}').with_http_status(:ok) }
|
57
|
+
```
|
58
|
+
|
46
59
|
### How it works
|
47
60
|
|
48
61
|
It uses the `request.path`, `request.method`, `status` and `headers` on the test subject (which must be the response) to find the response schema in the OpenAPI document. Then it does the following checks:
|
@@ -1,14 +1,14 @@
|
|
1
1
|
module OpenapiContracts
|
2
2
|
class Doc::Parser
|
3
|
-
def self.call(dir)
|
4
|
-
new(dir).parse(
|
3
|
+
def self.call(dir, filename)
|
4
|
+
new(dir).parse(filename)
|
5
5
|
end
|
6
6
|
|
7
7
|
def initialize(dir)
|
8
8
|
@dir = dir
|
9
9
|
end
|
10
10
|
|
11
|
-
def parse(path
|
11
|
+
def parse(path)
|
12
12
|
abs_path = @dir.join(path)
|
13
13
|
data = parse_file(abs_path, translate: false)
|
14
14
|
data.deep_merge! merge_components
|
@@ -5,8 +5,8 @@ module OpenapiContracts
|
|
5
5
|
autoload :Response, 'openapi_contracts/doc/response'
|
6
6
|
autoload :Schema, 'openapi_contracts/doc/schema'
|
7
7
|
|
8
|
-
def self.parse(dir)
|
9
|
-
new Parser.call(dir)
|
8
|
+
def self.parse(dir, filename = 'openapi.yaml')
|
9
|
+
new Parser.call(dir, filename)
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(schema)
|
@@ -1,8 +1,9 @@
|
|
1
1
|
module OpenapiContracts
|
2
2
|
module Matchers
|
3
3
|
class MatchOpenapiDoc
|
4
|
-
def initialize(doc)
|
4
|
+
def initialize(doc, options)
|
5
5
|
@doc = doc
|
6
|
+
@options = options
|
6
7
|
@errors = []
|
7
8
|
end
|
8
9
|
|
@@ -43,7 +44,7 @@ module OpenapiContracts
|
|
43
44
|
|
44
45
|
def response_spec
|
45
46
|
@response_spec ||= @doc.response_for(
|
46
|
-
@response.request.path,
|
47
|
+
@options.fetch(:path, @response.request.path),
|
47
48
|
@response.request.request_method.downcase,
|
48
49
|
@response.status.to_s
|
49
50
|
)
|
@@ -2,8 +2,8 @@ module OpenapiContracts
|
|
2
2
|
module Matchers
|
3
3
|
autoload :MatchOpenapiDoc, 'openapi_contracts/matchers/match_openapi_doc'
|
4
4
|
|
5
|
-
def match_openapi_doc(doc)
|
6
|
-
MatchOpenapiDoc.new(doc)
|
5
|
+
def match_openapi_doc(doc, options = {})
|
6
|
+
MatchOpenapiDoc.new(doc, options)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: openapi_contracts
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mkon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -50,70 +50,70 @@ dependencies:
|
|
50
50
|
requirements:
|
51
51
|
- - "~>"
|
52
52
|
- !ruby/object:Gem::Version
|
53
|
-
version:
|
53
|
+
version: 3.0.0
|
54
54
|
type: :development
|
55
55
|
prerelease: false
|
56
56
|
version_requirements: !ruby/object:Gem::Requirement
|
57
57
|
requirements:
|
58
58
|
- - "~>"
|
59
59
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
60
|
+
version: 3.0.0
|
61
61
|
- !ruby/object:Gem::Dependency
|
62
62
|
name: rspec
|
63
63
|
requirement: !ruby/object:Gem::Requirement
|
64
64
|
requirements:
|
65
65
|
- - "~>"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: 3.
|
67
|
+
version: 3.12.0
|
68
68
|
type: :development
|
69
69
|
prerelease: false
|
70
70
|
version_requirements: !ruby/object:Gem::Requirement
|
71
71
|
requirements:
|
72
72
|
- - "~>"
|
73
73
|
- !ruby/object:Gem::Version
|
74
|
-
version: 3.
|
74
|
+
version: 3.12.0
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: rubocop
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
78
78
|
requirements:
|
79
79
|
- - '='
|
80
80
|
- !ruby/object:Gem::Version
|
81
|
-
version: 1.
|
81
|
+
version: 1.44.1
|
82
82
|
type: :development
|
83
83
|
prerelease: false
|
84
84
|
version_requirements: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
86
|
- - '='
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: 1.
|
88
|
+
version: 1.44.1
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
90
|
name: rubocop-rspec
|
91
91
|
requirement: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - '='
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: 2.
|
95
|
+
version: 2.18.1
|
96
96
|
type: :development
|
97
97
|
prerelease: false
|
98
98
|
version_requirements: !ruby/object:Gem::Requirement
|
99
99
|
requirements:
|
100
100
|
- - '='
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 2.
|
102
|
+
version: 2.18.1
|
103
103
|
- !ruby/object:Gem::Dependency
|
104
104
|
name: simplecov
|
105
105
|
requirement: !ruby/object:Gem::Requirement
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: 0.
|
109
|
+
version: 0.22.0
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: 0.
|
116
|
+
version: 0.22.0
|
117
117
|
description:
|
118
118
|
email:
|
119
119
|
- konstantin@munteanu.de
|