schema_conformist 0.2.2 → 0.3.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 +12 -20
- data/lib/schema_conformist.rb +0 -1
- data/lib/schema_conformist/driver.rb +13 -33
- data/lib/schema_conformist/process_with_assertion.rb +12 -1
- data/lib/schema_conformist/railtie.rb +0 -1
- data/lib/schema_conformist/version.rb +1 -1
- metadata +4 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0f371fda7f28311396661b5eabe38e3630fdcf7957654b9bd9066c904adb82f8
|
4
|
+
data.tar.gz: 5a7b206ae48f4124c207f16fc0cf299e5caa1f4734c4c084ca27aff85fad5167
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf5f6565891b81181b6126d98f96399e0cfaba547c3aa6f6f01fcb8493d02c7701bc558e28522e482246e5f9f8ae25f1eb662906944ab26caf3ffac8aca38278
|
7
|
+
data.tar.gz: b62c4a71d1d3efb3d9f801bd9b384326e9e49edb87b9477c84f15d0783e6ea8a58f79606c7aa668d92643c859f0fed2025df6b61d1313f08008201fe4db56ad5
|
data/README.md
CHANGED
@@ -6,9 +6,9 @@
|
|
6
6
|
|
7
7
|
SchemaConformist is an automatic JSON response validator for your API testing in Rails.
|
8
8
|
|
9
|
-
This library automatically validates that JSON responses are conformant with the schema. The schema can be described as
|
9
|
+
This library automatically validates that JSON 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
10
|
|
11
|
-
This library uses [Committee](https://github.com/interagent/committee)
|
11
|
+
This library uses [Committee](https://github.com/interagent/committee) to validate JSONs.
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
@@ -22,14 +22,17 @@ gem 'schema_conformist'
|
|
22
22
|
|
23
23
|
and execute `bundle install`.
|
24
24
|
|
25
|
+
Configure `schema_path` as follows (ex. using an OpenAPI 3 schema):
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
Rails.application.config.schema_conformist.schema_path = Rails.root.join('doc', 'openapi.yaml')
|
29
|
+
```
|
30
|
+
|
25
31
|
That's all. Then all JSON responses in integration-test/request-spec are validated according to your schema.
|
26
32
|
|
27
33
|
### Writing the Schema
|
28
34
|
|
29
|
-
Write your API schema in
|
30
|
-
|
31
|
-
- JSON Hyper Schema: `public/schema.json`
|
32
|
-
- OpenAPI 2: `public/swagger.json`
|
35
|
+
Write your API schema in one of JSON Hyper Schema, OpenAPI 2 and OpenAPI 3.
|
33
36
|
|
34
37
|
See [`test/dummy`](https://github.com/kymmt90/schema_conformist/tree/master/test/dummy) app for examples.
|
35
38
|
|
@@ -37,21 +40,10 @@ See [`test/dummy`](https://github.com/kymmt90/schema_conformist/tree/master/test
|
|
37
40
|
|
38
41
|
Configuration options are following:
|
39
42
|
|
40
|
-
- `schema_conformist.driver`
|
41
|
-
- `:hyper_schema`: Use JSON Hyper Schema as schema format
|
42
|
-
- `:open_api_2`: Use OpenAPI 2 as schema format (both JSON and YAML are available as schema files)
|
43
|
-
- `schema_conformist.ignored_api_paths`
|
44
|
-
- The array of API paths not to validate. Each path can be described in regular expression.
|
45
43
|
- `schema_conformist.schema_path`
|
46
|
-
- The path where the schema is placed
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
```ruby
|
51
|
-
Rails.application.config.schema_conformist.driver = :open_api_2
|
52
|
-
Rails.application.config.schema_conformist.ignored_api_paths << /private/
|
53
|
-
Rails.application.config.schema_conformist.schema_path = Rails.root.join('doc', 'swagger.yaml')
|
54
|
-
```
|
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.
|
55
47
|
|
56
48
|
## Contributing
|
57
49
|
|
data/lib/schema_conformist.rb
CHANGED
@@ -1,47 +1,27 @@
|
|
1
1
|
module SchemaConformist
|
2
2
|
module Driver
|
3
|
-
include Committee::
|
3
|
+
include Committee::Test::Methods
|
4
4
|
|
5
|
-
def
|
6
|
-
|
5
|
+
def committee_options
|
6
|
+
{ schema: committee_schema }
|
7
7
|
end
|
8
8
|
|
9
|
-
def
|
10
|
-
|
11
|
-
YAML.safe_load(schema_data)
|
12
|
-
else
|
13
|
-
JSON.parse(schema_data)
|
14
|
-
end
|
9
|
+
def request_object
|
10
|
+
request
|
15
11
|
end
|
16
12
|
|
17
|
-
def
|
18
|
-
|
19
|
-
schema_path
|
20
|
-
else
|
21
|
-
case driver_name
|
22
|
-
when :hyper_schema
|
23
|
-
Rails.root.join('public', 'schema.json')
|
24
|
-
when :open_api_2
|
25
|
-
Rails.root.join('public', 'swagger.json')
|
26
|
-
else
|
27
|
-
raise SchemaConformist::Error.new("#{driver_name} is unknown driver")
|
28
|
-
end
|
29
|
-
end
|
13
|
+
def response_data
|
14
|
+
[response.status, response.headers, response.body]
|
30
15
|
end
|
31
16
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
when :open_api_2
|
37
|
-
Committee::Drivers::OpenAPI2.new
|
38
|
-
else
|
39
|
-
raise SchemaConformist::Error.new("#{driver_name} is unknown driver")
|
40
|
-
end
|
17
|
+
private
|
18
|
+
|
19
|
+
def committee_schema
|
20
|
+
@commitee_schema ||= Committee::Drivers::load_from_file(schema_path)
|
41
21
|
end
|
42
22
|
|
43
|
-
def
|
44
|
-
Rails.application.config.schema_conformist.
|
23
|
+
def schema_path
|
24
|
+
Rails.application.config.schema_conformist.schema_path
|
45
25
|
end
|
46
26
|
end
|
47
27
|
end
|
@@ -12,7 +12,18 @@ module SchemaConformist
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def ignored?(path)
|
15
|
-
|
15
|
+
ignored_api_paths.any? do |pattern|
|
16
|
+
case pattern
|
17
|
+
when String
|
18
|
+
path.start_with?(pattern)
|
19
|
+
when Regexp
|
20
|
+
path.match?(pattern)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def ignored_api_paths
|
26
|
+
Rails.application.config.schema_conformist.ignored_api_paths
|
16
27
|
end
|
17
28
|
end
|
18
29
|
end
|
@@ -2,7 +2,6 @@ module SchemaConformist
|
|
2
2
|
class Railtie < Rails::Railtie
|
3
3
|
config.before_configuration do
|
4
4
|
config.schema_conformist = Configuration.new
|
5
|
-
config.schema_conformist.driver = :hyper_schema
|
6
5
|
config.schema_conformist.ignored_api_paths = []
|
7
6
|
config.schema_conformist.schema_path = nil
|
8
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_conformist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2019-
|
11
|
+
date: 2019-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -24,34 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: committee-rails
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - ">="
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - ">="
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: committee
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
44
30
|
requirements:
|
45
31
|
- - "~>"
|
46
32
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
33
|
+
version: 3.0.1
|
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:
|
40
|
+
version: 3.0.1
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: sqlite3
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|