schema_conformist 0.1.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +20 -23
- data/lib/schema_conformist.rb +0 -1
- data/lib/schema_conformist/driver.rb +19 -31
- data/lib/schema_conformist/process_with_assertion.rb +18 -6
- data/lib/schema_conformist/railtie.rb +3 -2
- data/lib/schema_conformist/version.rb +1 -1
- metadata +12 -27
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e54cb66b8b3d2067cff927d88c713d3c6884451015d29ec012ef9de875843cc
|
4
|
+
data.tar.gz: 2244d52ab6750d662b79c1f0e6343a80a773cf82f5cb68ef5b181b92aa6ab20b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fbb90f23972a201248b92b3b757d74fca5a40b249f6f3387963cca84ebd20075823619b4af7cbf106e7ebdb7e102350a8025b7a6223209311a39b2bb6aa3ae4
|
7
|
+
data.tar.gz: 71529b799490eb6818c8336a01d78b7930dc4c6ebad10f9d031e1e9fbc5bc15ca7add1b4da222e964ba7ae38e235cc6aa5e981350dde92f7213a556ce5aa575d
|
data/README.md
CHANGED
@@ -1,12 +1,14 @@
|
|
1
1
|
# SchemaConformist
|
2
2
|
|
3
|
-
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/schema_conformist.svg)](https://badge.fury.io/rb/schema_conformist) [![Build Status](https://github.com/kymmt90/schema_conformist/workflows/build/badge.svg)](https://github.com/kymmt90/schema_conformist/actions?workflow=build)
|
4
4
|
|
5
|
-
|
5
|
+
> An automatic JSON request/response validator for testing in Rails
|
6
6
|
|
7
|
-
|
7
|
+
SchemaConformist is an automatic JSON request/response validator for your API testing in Rails.
|
8
8
|
|
9
|
-
This library
|
9
|
+
This library automatically validates that JSON requests/responses are conformant with the schema. The schema can be described as one of [JSON Hyper Schema](http://json-schema.org/latest/json-schema-hypermedia.html), [OpenAPI 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md) and OpenAPI 3 (currently [3.0.2](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.2.md) is latest).
|
10
|
+
|
11
|
+
This library uses [Committee](https://github.com/interagent/committee) to validate JSONs.
|
10
12
|
|
11
13
|
## Usage
|
12
14
|
|
@@ -20,14 +22,17 @@ gem 'schema_conformist'
|
|
20
22
|
|
21
23
|
and execute `bundle install`.
|
22
24
|
|
23
|
-
|
25
|
+
Configure `schema_path` as follows (ex. using an OpenAPI 3 schema):
|
24
26
|
|
25
|
-
|
27
|
+
```ruby
|
28
|
+
Rails.application.config.schema_conformist.schema_path = Rails.root.join('doc', 'openapi.yaml')
|
29
|
+
```
|
30
|
+
|
31
|
+
That's all. Then all JSON requests/responses in integration-test/request-spec are validated according to your schema.
|
26
32
|
|
27
|
-
|
33
|
+
### Writing the Schema
|
28
34
|
|
29
|
-
|
30
|
-
- OpenAPI 2: `public/swagger.json`
|
35
|
+
Write your API schema in one of JSON Hyper Schema, OpenAPI 2 and OpenAPI 3.
|
31
36
|
|
32
37
|
See [`test/dummy`](https://github.com/kymmt90/schema_conformist/tree/master/test/dummy) app for examples.
|
33
38
|
|
@@ -35,21 +40,13 @@ See [`test/dummy`](https://github.com/kymmt90/schema_conformist/tree/master/test
|
|
35
40
|
|
36
41
|
Configuration options are following:
|
37
42
|
|
38
|
-
- `schema_conformist.driver`
|
39
|
-
- `:hyper_schema`: Use JSON Hyper Schema as schema format
|
40
|
-
- `:open_api_2`: Use OpenAPI 2 as schema format
|
41
|
-
- `schema_conformist.ignored_api_paths`
|
42
|
-
- The array of API paths not to validate. Each path can be described in regular expression.
|
43
43
|
- `schema_conformist.schema_path`
|
44
|
-
- The path where the schema is placed
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
Rails.application.config.schema_conformist.ignored_api_paths << /private/
|
51
|
-
Rails.application.config.schema_conformist.schema_path = Rails.root.join('doc', 'swagger.json')
|
52
|
-
```
|
44
|
+
- Required. The path where the schema is placed
|
45
|
+
- `schema_conformist.ignored_api_paths`
|
46
|
+
- Optional. The array of API paths not to validate. Each path can be described in String literal (used for prefix search) or regular expression.
|
47
|
+
- `schema_conformist.committee.old_assert_behavior`
|
48
|
+
- Optional. Set `true` if you want to skip validating request parameters. The default value is `false`.
|
49
|
+
- cf. ["Test Assertions" in Committee README](https://github.com/interagent/committee#test-assertions)
|
53
50
|
|
54
51
|
## Contributing
|
55
52
|
|
data/lib/schema_conformist.rb
CHANGED
@@ -1,43 +1,31 @@
|
|
1
1
|
module SchemaConformist
|
2
2
|
module Driver
|
3
|
-
include Committee::
|
3
|
+
include Committee::Test::Methods
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
begin
|
8
|
-
schema_hash = JSON.parse(File.read(schema_path))
|
9
|
-
driver.parse(schema_hash)
|
10
|
-
end
|
5
|
+
def committee_options
|
6
|
+
{ schema: committee_schema }.merge(schema_conformist_committee_options)
|
11
7
|
end
|
12
8
|
|
13
|
-
def
|
14
|
-
|
15
|
-
schema_path
|
16
|
-
else
|
17
|
-
case driver_name
|
18
|
-
when :hyper_schema
|
19
|
-
Rails.root.join('public', 'schema.json')
|
20
|
-
when :open_api_2
|
21
|
-
Rails.root.join('public', 'swagger.json')
|
22
|
-
else
|
23
|
-
raise SchemaConformist::Error.new("#{driver_name} is unknown driver")
|
24
|
-
end
|
25
|
-
end
|
9
|
+
def request_object
|
10
|
+
request
|
26
11
|
end
|
27
12
|
|
28
|
-
def
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
13
|
+
def response_data
|
14
|
+
[response.status, response.headers, response.body]
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
def committee_schema
|
20
|
+
@commitee_schema ||= Committee::Drivers::load_from_file(schema_path)
|
21
|
+
end
|
22
|
+
|
23
|
+
def schema_path
|
24
|
+
Rails.application.config.schema_conformist.schema_path
|
37
25
|
end
|
38
26
|
|
39
|
-
def
|
40
|
-
Rails.application.config.schema_conformist.
|
27
|
+
def schema_conformist_committee_options
|
28
|
+
Rails.application.config.schema_conformist.committee
|
41
29
|
end
|
42
30
|
end
|
43
31
|
end
|
@@ -2,17 +2,29 @@ module SchemaConformist
|
|
2
2
|
module ProcessWithAssertion
|
3
3
|
include SchemaConformist::Driver
|
4
4
|
|
5
|
-
def process(
|
6
|
-
super
|
5
|
+
def process(method, path, **kwargs)
|
6
|
+
super
|
7
7
|
|
8
|
-
|
9
|
-
return if ignored?(path)
|
8
|
+
return if schema_conformist_ignored_path?(path)
|
10
9
|
|
11
10
|
assert_schema_conform
|
12
11
|
end
|
13
12
|
|
14
|
-
|
15
|
-
|
13
|
+
private
|
14
|
+
|
15
|
+
def schema_conformist_ignored_path?(path)
|
16
|
+
schema_conformist_ignored_api_paths.any? do |pattern|
|
17
|
+
case pattern
|
18
|
+
when String
|
19
|
+
path.start_with?(pattern)
|
20
|
+
when Regexp
|
21
|
+
path.match?(pattern)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def schema_conformist_ignored_api_paths
|
27
|
+
Rails.application.config.schema_conformist.ignored_api_paths
|
16
28
|
end
|
17
29
|
end
|
18
30
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module SchemaConformist
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
config.before_configuration do
|
4
|
-
config.schema_conformist =
|
5
|
-
config.schema_conformist.driver = :hyper_schema
|
4
|
+
config.schema_conformist = ActiveSupport::OrderedOptions.new
|
6
5
|
config.schema_conformist.ignored_api_paths = []
|
7
6
|
config.schema_conformist.schema_path = nil
|
7
|
+
config.schema_conformist.committee = ActiveSupport::OrderedOptions.new
|
8
|
+
config.schema_conformist.committee.old_assert_behavior = false
|
8
9
|
end
|
9
10
|
end
|
10
11
|
end
|
metadata
CHANGED
@@ -1,57 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_conformist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kohei Yamamoto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: committee
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: 2.0.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: committee-rails
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.2.0
|
33
|
+
version: 4.0.0
|
48
34
|
type: :runtime
|
49
35
|
prerelease: false
|
50
36
|
version_requirements: !ruby/object:Gem::Requirement
|
51
37
|
requirements:
|
52
38
|
- - "~>"
|
53
39
|
- !ruby/object:Gem::Version
|
54
|
-
version: 0.
|
40
|
+
version: 4.0.0
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: sqlite3
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,8 +52,8 @@ dependencies:
|
|
66
52
|
- - ">="
|
67
53
|
- !ruby/object:Gem::Version
|
68
54
|
version: '0'
|
69
|
-
description: SchemaConformist is an automatic JSON response validator for
|
70
|
-
testing in Rails.
|
55
|
+
description: SchemaConformist is an automatic JSON request/response validator for
|
56
|
+
your API testing in Rails.
|
71
57
|
email:
|
72
58
|
- kymmt90@gmail.com
|
73
59
|
executables: []
|
@@ -103,9 +89,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
89
|
- !ruby/object:Gem::Version
|
104
90
|
version: '0'
|
105
91
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.6.13
|
92
|
+
rubygems_version: 3.1.2
|
108
93
|
signing_key:
|
109
94
|
specification_version: 4
|
110
|
-
summary: An automatic JSON response validator for testing in Rails
|
95
|
+
summary: An automatic JSON request/response validator for testing in Rails
|
111
96
|
test_files: []
|