open_api-schema_validator 0.1.1 → 0.2.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/.reek.yml +11 -0
- data/Gemfile.lock +3 -3
- data/README.md +8 -4
- data/lib/open_api/json_schemas/oas_v3_schema.json +1654 -0
- data/lib/open_api/schema_validator.rb +25 -4
- data/lib/open_api/schema_validator/version.rb +1 -1
- metadata +5 -4
- data/.reek +0 -6
|
@@ -5,22 +5,43 @@ require 'json-schema'
|
|
|
5
5
|
|
|
6
6
|
module OpenApi
|
|
7
7
|
module SchemaValidator
|
|
8
|
-
def self.validate!(json)
|
|
9
|
-
|
|
8
|
+
def self.validate!(json, version = 2)
|
|
9
|
+
case version
|
|
10
|
+
when 2
|
|
11
|
+
validate_schema!(swagger, json)
|
|
12
|
+
when 3
|
|
13
|
+
validate_schema!(oas3, json)
|
|
14
|
+
end
|
|
10
15
|
end
|
|
11
16
|
|
|
12
17
|
def self.validate_schema!(schema, json, opts = {})
|
|
13
18
|
JSON::Validator.add_schema(draft_four_schema)
|
|
14
19
|
JSON::Validator.add_schema(swagger_schema)
|
|
20
|
+
JSON::Validator.add_schema(oas3_schema)
|
|
15
21
|
JSON::Validator.validate!(schema, json, opts)
|
|
16
22
|
end
|
|
17
23
|
|
|
24
|
+
def self.oas3
|
|
25
|
+
@oas3 ||= JSON.parse(File.read(oas3_file))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.oas3_file
|
|
29
|
+
File.expand_path('json_schemas/oas_v3_schema.json', __dir__)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def self.oas3_schema
|
|
33
|
+
@oas3_schema ||= JSON::Schema.new(
|
|
34
|
+
oas3,
|
|
35
|
+
Addressable::URI.parse('https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/schemas/v3.0/schema.json')
|
|
36
|
+
)
|
|
37
|
+
end
|
|
38
|
+
|
|
18
39
|
def self.swagger
|
|
19
40
|
@swagger ||= JSON.parse(File.read(swagger_file))
|
|
20
41
|
end
|
|
21
42
|
|
|
22
43
|
def self.swagger_file
|
|
23
|
-
File.expand_path('
|
|
44
|
+
File.expand_path('json_schemas/swagger_schema.json', __dir__)
|
|
24
45
|
end
|
|
25
46
|
|
|
26
47
|
def self.swagger_schema
|
|
@@ -35,7 +56,7 @@ module OpenApi
|
|
|
35
56
|
end
|
|
36
57
|
|
|
37
58
|
def self.draft_four_file
|
|
38
|
-
File.expand_path('
|
|
59
|
+
File.expand_path('json_schemas/json_schema_v4.json', __dir__)
|
|
39
60
|
end
|
|
40
61
|
|
|
41
62
|
def self.draft_four_schema
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: open_api-schema_validator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ryan Hansen
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-07-17 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -144,7 +144,7 @@ extensions: []
|
|
|
144
144
|
extra_rdoc_files: []
|
|
145
145
|
files:
|
|
146
146
|
- ".gitignore"
|
|
147
|
-
- ".reek"
|
|
147
|
+
- ".reek.yml"
|
|
148
148
|
- ".rspec"
|
|
149
149
|
- ".rubocop.yml"
|
|
150
150
|
- ".travis.yml"
|
|
@@ -161,6 +161,7 @@ files:
|
|
|
161
161
|
- bin/rubocop
|
|
162
162
|
- bin/setup
|
|
163
163
|
- lib/open_api/json_schemas/json_schema_v4.json
|
|
164
|
+
- lib/open_api/json_schemas/oas_v3_schema.json
|
|
164
165
|
- lib/open_api/json_schemas/swagger_schema.json
|
|
165
166
|
- lib/open_api/schema_validator.rb
|
|
166
167
|
- lib/open_api/schema_validator/version.rb
|
|
@@ -183,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
183
184
|
- !ruby/object:Gem::Version
|
|
184
185
|
version: '0'
|
|
185
186
|
requirements: []
|
|
186
|
-
rubygems_version: 3.0.
|
|
187
|
+
rubygems_version: 3.0.3
|
|
187
188
|
signing_key:
|
|
188
189
|
specification_version: 4
|
|
189
190
|
summary: JSON Schema Validator for OpenAPI
|