schema_conformist 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +60 -0
- data/Rakefile +33 -0
- data/lib/action_dispatch/integration.rb +7 -0
- data/lib/schema_conformist/driver.rb +43 -0
- data/lib/schema_conformist/process_with_assertion.rb +18 -0
- data/lib/schema_conformist/railtie.rb +13 -0
- data/lib/schema_conformist/version.rb +3 -0
- data/lib/schema_conformist.rb +10 -0
- data/lib/tasks/schema_conformist_tasks.rake +4 -0
- metadata +111 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: abd4ddfeec30a4b51b428d7f2b254dc563235a53
|
4
|
+
data.tar.gz: 1f6f6fb6d728cb13a79dbc723b9a37bec34c6bb7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f9e72c573dce8eef1ae369470b3c422d6e120cf6dd3abb66b2a5b85de15cc102fd724c351d7c3a2fdd6aafac9a96d06dd4aa9e523929bdad580126659416a151
|
7
|
+
data.tar.gz: 105eeaaec3432b13424f16726b60ca0303a9bbec6cbfd33befae89c1f9d078628519a9726985ab042f9b74e12d5ce5a93e2cbc2b8140aed92a55b733a5c88405
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017 Kohei Yamamoto
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
# SchemaConformist
|
2
|
+
|
3
|
+
> An automatic JSON response validator for testing in Rails
|
4
|
+
|
5
|
+
SchemaConformist is an automatic JSON response validator for your API testing in Rails.
|
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).
|
8
|
+
|
9
|
+
This library uses [Committee](https://github.com/interagent/committee) and [Committee::Rails](https://github.com/willnet/committee-rails) to validate JSONs.
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
### Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'schema_conformist'
|
19
|
+
```
|
20
|
+
|
21
|
+
and execute `bundle install`.
|
22
|
+
|
23
|
+
That's all. Then all JSON responses in integration-test/request-spec are validated according to your schema.
|
24
|
+
|
25
|
+
### Writing the Schema
|
26
|
+
|
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:
|
28
|
+
|
29
|
+
- JSON Hyper Schema: `public/schema.json`
|
30
|
+
- OpenAPI 2: `public/swagger.json`
|
31
|
+
|
32
|
+
See [`test/dummy`](https://github.com/kymmt90/schema_conformist/tree/master/test/dummy) app for examples.
|
33
|
+
|
34
|
+
### Configurations
|
35
|
+
|
36
|
+
Configuration options are following:
|
37
|
+
|
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
|
+
- `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
|
+
```
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/kymmt90/schema_conformist.
|
57
|
+
|
58
|
+
## License
|
59
|
+
|
60
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'SchemaConformist'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
task default: :test
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module SchemaConformist
|
2
|
+
module Driver
|
3
|
+
include Committee::Rails::Test::Methods
|
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
|
11
|
+
end
|
12
|
+
|
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
|
26
|
+
end
|
27
|
+
|
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
|
37
|
+
end
|
38
|
+
|
39
|
+
def driver_name
|
40
|
+
Rails.application.config.schema_conformist.driver
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module SchemaConformist
|
2
|
+
module ProcessWithAssertion
|
3
|
+
include SchemaConformist::Driver
|
4
|
+
|
5
|
+
def process(*args)
|
6
|
+
super *args
|
7
|
+
|
8
|
+
path = args[1]
|
9
|
+
return if ignored?(path)
|
10
|
+
|
11
|
+
assert_schema_conform
|
12
|
+
end
|
13
|
+
|
14
|
+
def ignored?(path)
|
15
|
+
Rails.application.config.schema_conformist.ignored_api_paths.any? { |regex| path =~ regex }
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module SchemaConformist
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
config.before_configuration do
|
4
|
+
config.schema_conformist = Configuration.new
|
5
|
+
end
|
6
|
+
|
7
|
+
initializer 'config.schema_conformist' do
|
8
|
+
config.schema_conformist.driver = :hyper_schema
|
9
|
+
config.schema_conformist.ignored_api_paths = []
|
10
|
+
config.schema_conformist.schema_path = nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
require 'committee'
|
2
|
+
require 'committee/rails'
|
3
|
+
require 'schema_conformist/railtie'
|
4
|
+
require 'schema_conformist/driver'
|
5
|
+
require 'schema_conformist/process_with_assertion'
|
6
|
+
require 'action_dispatch/integration'
|
7
|
+
|
8
|
+
module SchemaConformist
|
9
|
+
class Error < StandardError; end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: schema_conformist
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kohei Yamamoto
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-11-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: committee
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
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
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: sqlite3
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: SchemaConformist is an automatic JSON response validator for your API
|
70
|
+
testing in Rails.
|
71
|
+
email:
|
72
|
+
- kymmt90@gmail.com
|
73
|
+
executables: []
|
74
|
+
extensions: []
|
75
|
+
extra_rdoc_files: []
|
76
|
+
files:
|
77
|
+
- MIT-LICENSE
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- lib/action_dispatch/integration.rb
|
81
|
+
- lib/schema_conformist.rb
|
82
|
+
- lib/schema_conformist/driver.rb
|
83
|
+
- lib/schema_conformist/process_with_assertion.rb
|
84
|
+
- lib/schema_conformist/railtie.rb
|
85
|
+
- lib/schema_conformist/version.rb
|
86
|
+
- lib/tasks/schema_conformist_tasks.rake
|
87
|
+
homepage: https://github.com/kymmt90/schema_conformist
|
88
|
+
licenses:
|
89
|
+
- MIT
|
90
|
+
metadata: {}
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
requirements: []
|
106
|
+
rubyforge_project:
|
107
|
+
rubygems_version: 2.6.13
|
108
|
+
signing_key:
|
109
|
+
specification_version: 4
|
110
|
+
summary: An automatic JSON response validator for testing in Rails
|
111
|
+
test_files: []
|