jsonschema-matchers 0.1.4 → 0.1.5
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 +165 -1
- data/jsonschema-matchers.gemspec +2 -0
- data/lib/jsonschema/matchers.rb +23 -3
- data/lib/jsonschema/matchers/configuration.rb +14 -0
- data/lib/jsonschema/matchers/match_jsonschema.rb +6 -2
- data/lib/jsonschema/matchers/version.rb +1 -1
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcecc26c13440bd38f15ad40ad312c181e41af0950095126bad000f70f3899d8
|
4
|
+
data.tar.gz: ccde3fd0477af5c0342e223c6d9e2a74779c7f4688f25583e6e21a86d457ee3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfd13418ee589571128f2444c9f77250162d25d1af9ca917ec6c6f529053ef89a8d05124f87bd2d6dd6fbaf33e1fb4817e65e3c1ae02b18868c1391e37f53b9f
|
7
|
+
data.tar.gz: b2677a218f124acd431cdbf1388da22fe92907fbcd7c75a4a11011566f7fb545f9fb2b2189b76ec47cc4d56240d67abb4eb8f478fe2f2cdaafc492edd0ef044d
|
data/README.md
CHANGED
@@ -22,8 +22,172 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
+
Json example
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
RSpec.describe 'Users Requests', type: :request do
|
29
|
+
describe 'GET index' do
|
30
|
+
before { create_list(:user, 5) }
|
31
|
+
|
32
|
+
it 'matches correct schema' do
|
33
|
+
get '/users'
|
34
|
+
expect(response.body).to match_jsonschema
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Will match/create schema
|
41
|
+
|
42
|
+
`spec/jsonschemas/Users_Requests/GET_index/matches_correct_schema.json`
|
43
|
+
|
44
|
+
```json
|
45
|
+
{
|
46
|
+
"title": "Root",
|
47
|
+
"type": "array",
|
48
|
+
"minItems": 5,
|
49
|
+
"maxItems": 5,
|
50
|
+
"items": {
|
51
|
+
"properties": {
|
52
|
+
"id": {
|
53
|
+
"type": "integer"
|
54
|
+
},
|
55
|
+
"email": {
|
56
|
+
"type": "string"
|
57
|
+
},
|
58
|
+
"password_digest": {
|
59
|
+
"type": "null"
|
60
|
+
},
|
61
|
+
"created_at": {
|
62
|
+
"type": "string"
|
63
|
+
},
|
64
|
+
"updated_at": {
|
65
|
+
"type": "string"
|
66
|
+
},
|
67
|
+
"posts": {
|
68
|
+
"type": "array",
|
69
|
+
"minItems": 0,
|
70
|
+
"maxItems": 0,
|
71
|
+
"items": {
|
72
|
+
}
|
73
|
+
}
|
74
|
+
},
|
75
|
+
"type": "object",
|
76
|
+
"required": [
|
77
|
+
"id",
|
78
|
+
"email",
|
79
|
+
"password_digest",
|
80
|
+
"created_at",
|
81
|
+
"updated_at",
|
82
|
+
"posts"
|
83
|
+
]
|
84
|
+
}
|
85
|
+
}
|
86
|
+
```
|
87
|
+
|
88
|
+
JsonApi example
|
89
|
+
|
90
|
+
```ruby
|
91
|
+
RSpec.describe 'Users Requests', type: :request do
|
92
|
+
describe 'GET show' do
|
93
|
+
let(:user) { create(:user) }
|
94
|
+
|
95
|
+
before { create(:post, user: user) }
|
96
|
+
|
97
|
+
it 'matches correct schema with jsonapi spec' do
|
98
|
+
get "/users/#{user.id}"
|
99
|
+
expect(response.body).to match_jsonschema
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
```
|
104
|
+
|
105
|
+
Will match/create schema
|
106
|
+
|
107
|
+
`spec/jsonschemas/Users_Requests/GET_show/matches_correct_schema_with_jsonapi_spec.json`
|
108
|
+
|
109
|
+
```json
|
110
|
+
{
|
111
|
+
"title": "Root",
|
112
|
+
"properties": {
|
113
|
+
"data": {
|
114
|
+
"properties": {
|
115
|
+
"id": {
|
116
|
+
"type": "string"
|
117
|
+
},
|
118
|
+
"type": {
|
119
|
+
"type": "string"
|
120
|
+
},
|
121
|
+
"attributes": {
|
122
|
+
"properties": {
|
123
|
+
"email": {
|
124
|
+
"type": "string"
|
125
|
+
}
|
126
|
+
},
|
127
|
+
"type": "object",
|
128
|
+
"required": [
|
129
|
+
"email"
|
130
|
+
]
|
131
|
+
},
|
132
|
+
"relationships": {
|
133
|
+
"properties": {
|
134
|
+
"posts": {
|
135
|
+
"properties": {
|
136
|
+
"data": {
|
137
|
+
"type": "array",
|
138
|
+
"minItems": 1,
|
139
|
+
"maxItems": 1,
|
140
|
+
"items": {
|
141
|
+
"properties": {
|
142
|
+
"id": {
|
143
|
+
"type": "string"
|
144
|
+
},
|
145
|
+
"type": {
|
146
|
+
"type": "string"
|
147
|
+
}
|
148
|
+
},
|
149
|
+
"type": "object",
|
150
|
+
"required": [
|
151
|
+
"id",
|
152
|
+
"type"
|
153
|
+
]
|
154
|
+
}
|
155
|
+
}
|
156
|
+
},
|
157
|
+
"type": "object",
|
158
|
+
"required": [
|
159
|
+
"data"
|
160
|
+
]
|
161
|
+
}
|
162
|
+
},
|
163
|
+
"type": "object",
|
164
|
+
"required": [
|
165
|
+
"posts"
|
166
|
+
]
|
167
|
+
}
|
168
|
+
},
|
169
|
+
"type": "object",
|
170
|
+
"required": [
|
171
|
+
"id",
|
172
|
+
"type",
|
173
|
+
"attributes",
|
174
|
+
"relationships"
|
175
|
+
]
|
176
|
+
}
|
177
|
+
},
|
178
|
+
"type": "object",
|
179
|
+
"required": [
|
180
|
+
"data"
|
181
|
+
]
|
182
|
+
}
|
183
|
+
```
|
184
|
+
|
185
|
+
## Configuration
|
186
|
+
|
25
187
|
```ruby
|
26
|
-
|
188
|
+
Jsonschema::Matchers.configure do |config|
|
189
|
+
config.schema_dir = 'spec/jsonschemas' # Default path
|
190
|
+
end
|
27
191
|
```
|
28
192
|
|
29
193
|
## Development
|
data/jsonschema-matchers.gemspec
CHANGED
@@ -49,4 +49,6 @@ Gem::Specification.new do |spec|
|
|
49
49
|
spec.add_development_dependency 'fakefs', '~> 0.18'
|
50
50
|
spec.add_development_dependency 'rake', '~> 10.0'
|
51
51
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
52
|
+
spec.add_development_dependency 'rubocop', '~> 0.72'
|
53
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.33'
|
52
54
|
end
|
data/lib/jsonschema/matchers.rb
CHANGED
@@ -8,13 +8,33 @@ require 'jsonschema/matchers/version'
|
|
8
8
|
require 'jsonschema/matchers/metadater'
|
9
9
|
require 'jsonschema/generator'
|
10
10
|
|
11
|
+
NO_SCHEMA_NAME_ERROR = 'No schema name provided'
|
12
|
+
|
13
|
+
require 'jsonschema/matchers/configuration'
|
14
|
+
|
11
15
|
module Jsonschema
|
12
|
-
#
|
16
|
+
# Main
|
13
17
|
module Matchers
|
14
18
|
class Error < StandardError; end
|
15
19
|
|
16
|
-
|
17
|
-
|
20
|
+
class << self
|
21
|
+
attr_writer :configuration
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configuration
|
25
|
+
@configuration ||= Configuration.new
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.configure
|
29
|
+
yield(configuration)
|
30
|
+
end
|
31
|
+
|
32
|
+
def match_jsonschema(name: nil)
|
33
|
+
schema_name = name || inspect.scan(/\"(.*?)\"/).join
|
34
|
+
|
35
|
+
raise Error, NO_SCHEMA_NAME_ERROR unless schema_name
|
36
|
+
|
37
|
+
MatchJsonschema.new(self.class.metadata, schema_name)
|
18
38
|
end
|
19
39
|
end
|
20
40
|
end
|
@@ -10,8 +10,8 @@ module Jsonschema
|
|
10
10
|
|
11
11
|
def initialize(metadata, name)
|
12
12
|
@metadata = metadata
|
13
|
-
@path = "
|
14
|
-
@name = name
|
13
|
+
@path = "#{root_dir}/#{Metadater.call(metadata)}"
|
14
|
+
@name = name.downcase.gsub(%r{[\/\s]}, '/' => '_', ' ' => '_')
|
15
15
|
end
|
16
16
|
|
17
17
|
def matches?(actual)
|
@@ -29,6 +29,10 @@ module Jsonschema
|
|
29
29
|
|
30
30
|
private
|
31
31
|
|
32
|
+
def root_dir
|
33
|
+
Jsonschema::Matchers.configuration.schema_dir
|
34
|
+
end
|
35
|
+
|
32
36
|
def record(actual)
|
33
37
|
json_schema = Jsonschema::Generator.call(actual)
|
34
38
|
file_name = "#{name}.json"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jsonschema-matchers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Bykov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-07-
|
11
|
+
date: 2019-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-schema
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.72'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.72'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '1.33'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '1.33'
|
97
125
|
description: Jsonschema matchers.
|
98
126
|
email:
|
99
127
|
- leksster@gmail.com
|
@@ -114,6 +142,7 @@ files:
|
|
114
142
|
- bin/setup
|
115
143
|
- jsonschema-matchers.gemspec
|
116
144
|
- lib/jsonschema/matchers.rb
|
145
|
+
- lib/jsonschema/matchers/configuration.rb
|
117
146
|
- lib/jsonschema/matchers/match_jsonschema.rb
|
118
147
|
- lib/jsonschema/matchers/metadater.rb
|
119
148
|
- lib/jsonschema/matchers/version.rb
|
@@ -140,7 +169,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
169
|
- !ruby/object:Gem::Version
|
141
170
|
version: '0'
|
142
171
|
requirements: []
|
143
|
-
rubygems_version: 3.0.
|
172
|
+
rubygems_version: 3.0.3
|
144
173
|
signing_key:
|
145
174
|
specification_version: 4
|
146
175
|
summary: Jsonschema matchers
|