schema_conformist 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2ff4a7d2a77af891612e63f5a51da3e81d5e54092723668cd90f951427f454f
4
- data.tar.gz: 38581d5e2e0b1b0f7677002f51efaaa1ee90c31188c23678ec51e2b9ea32a3dd
3
+ metadata.gz: 0f371fda7f28311396661b5eabe38e3630fdcf7957654b9bd9066c904adb82f8
4
+ data.tar.gz: 5a7b206ae48f4124c207f16fc0cf299e5caa1f4734c4c084ca27aff85fad5167
5
5
  SHA512:
6
- metadata.gz: 575c431682aa802a57f0302ff80b837db47ee1eafc5047a9fd1917617b85b68b4c504db2db6675b65aadb35e73c8c6edaf8aa07ff51430a158659ef98dc497a8
7
- data.tar.gz: 5beb3ee32ae2ad67ddac088a9f54b586e9208e5a9b01f31dbe9111690af4ff36589b199acfca6a83b006cb01658d6127532f6b51e79ac9f7c10f3e5bca5a46fc
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 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).
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) and [Committee::Rails](https://github.com/willnet/committee-rails) to validate JSONs and is assumed that used with API mode Rails.
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 either JSON Hyper Schema or OpenAPI 2. For now, the default driver is set to JSON Hyper Schema and default schema paths are following:
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
- Example:
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
 
@@ -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,47 +1,27 @@
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 ||= driver.parse(schema_hash)
5
+ def committee_options
6
+ { schema: committee_schema }
7
7
  end
8
8
 
9
- def schema_hash(schema_data = File.read(schema_path))
10
- if %w(.yaml .yml).include?(File.extname(schema_path))
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 schema_path
18
- if schema_path = Rails.application.config.schema_conformist.schema_path
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
- def driver
33
- case driver_name
34
- when :hyper_schema
35
- Committee::Drivers::HyperSchema.new
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 driver_name
44
- Rails.application.config.schema_conformist.driver
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
- Rails.application.config.schema_conformist.ignored_api_paths.any? { |regex| path =~ regex }
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
@@ -1,3 +1,3 @@
1
1
  module SchemaConformist
2
- VERSION = '0.2.2'
2
+ VERSION = '0.3.0'
3
3
  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.2.2
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-03-27 00:00:00.000000000 Z
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: 2.5.1
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: 2.5.1
40
+ version: 3.0.1
55
41
  - !ruby/object:Gem::Dependency
56
42
  name: sqlite3
57
43
  requirement: !ruby/object:Gem::Requirement