schema_conformist 0.1.1 → 0.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 29e3c7aae3756274d33870d4738b44d712aeae2a
4
- data.tar.gz: 886f45cbbe1c9fee58773637c52cfb4a9cae7f67
2
+ SHA256:
3
+ metadata.gz: 5e54cb66b8b3d2067cff927d88c713d3c6884451015d29ec012ef9de875843cc
4
+ data.tar.gz: 2244d52ab6750d662b79c1f0e6343a80a773cf82f5cb68ef5b181b92aa6ab20b
5
5
  SHA512:
6
- metadata.gz: 98e7eb8623de0081ce52e6208b94f52d3b91028fce5e3a962254eb424bb6a47f0a5443d8d6f1ba71da4ac46333da20566dfdb8aae7cec7976ee16898499f6492
7
- data.tar.gz: 4195bcd58d4547822e907a81306d0cd9e77aba240fd38f4a9f7dc2ab22cfa9d7ddde9a7f79bce93d158e797d47d97df62adf4e75bfa5912be648dc9277a62b59
6
+ metadata.gz: 5fbb90f23972a201248b92b3b757d74fca5a40b249f6f3387963cca84ebd20075823619b4af7cbf106e7ebdb7e102350a8025b7a6223209311a39b2bb6aa3ae4
7
+ data.tar.gz: 71529b799490eb6818c8336a01d78b7930dc4c6ebad10f9d031e1e9fbc5bc15ca7add1b4da222e964ba7ae38e235cc6aa5e981350dde92f7213a556ce5aa575d
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # SchemaConformist
2
2
 
3
- > An automatic JSON response validator for testing in Rails
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
- SchemaConformist is an automatic JSON response validator for your API testing in Rails.
5
+ > An automatic JSON request/response validator for testing in Rails
6
6
 
7
- This library automatically validates that JSON responses are conformant with the schema. The schema can be described as either [JSON Hyper Schema](http://json-schema.org/latest/json-schema-hypermedia.html) or [OpenAPI 2.0](https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md).
7
+ SchemaConformist is an automatic JSON request/response validator for your API testing in Rails.
8
8
 
9
- This library uses [Committee](https://github.com/interagent/committee) and [Committee::Rails](https://github.com/willnet/committee-rails) to validate JSONs and is assumed that used with API mode Rails.
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
- That's all. Then all JSON responses in integration-test/request-spec are validated according to your schema.
25
+ Configure `schema_path` as follows (ex. using an OpenAPI 3 schema):
24
26
 
25
- ### Writing the Schema
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
- Write your API schema in either JSON Hyper Schema or OpenAPI 2. For now, the default driver is set to JSON Hyper Schema and default schema paths are following:
33
+ ### Writing the Schema
28
34
 
29
- - JSON Hyper Schema: `public/schema.json`
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
- Example:
47
-
48
- ```ruby
49
- Rails.application.config.schema_conformist.driver = :open_api_2
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
 
@@ -1,5 +1,4 @@
1
1
  require 'committee'
2
- require 'committee/rails'
3
2
  require 'schema_conformist/railtie'
4
3
  require 'schema_conformist/driver'
5
4
  require 'schema_conformist/process_with_assertion'
@@ -1,43 +1,31 @@
1
1
  module SchemaConformist
2
2
  module Driver
3
- include Committee::Rails::Test::Methods
3
+ include Committee::Test::Methods
4
4
 
5
- def committee_schema
6
- @committee_schema ||=
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 schema_path
14
- if schema_path = Rails.application.config.schema_conformist.schema_path
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 driver
29
- case driver_name
30
- when :hyper_schema
31
- Committee::Drivers::HyperSchema.new
32
- when :open_api_2
33
- Committee::Drivers::OpenAPI2.new
34
- else
35
- raise SchemaConformist::Error.new("#{driver_name} is unknown driver")
36
- end
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 driver_name
40
- Rails.application.config.schema_conformist.driver
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(*args)
6
- super *args
5
+ def process(method, path, **kwargs)
6
+ super
7
7
 
8
- path = args[1]
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
- def ignored?(path)
15
- Rails.application.config.schema_conformist.ignored_api_paths.any? { |regex| path =~ regex }
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 = Configuration.new
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
@@ -1,3 +1,3 @@
1
1
  module SchemaConformist
2
- VERSION = '0.1.1'
2
+ VERSION = '0.4.0'
3
3
  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.1.1
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: 2017-11-06 00:00:00.000000000 Z
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: 5.1.0
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: 5.1.0
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: 2.0.0
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.2.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 your API
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
- rubyforge_project:
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: []