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.
@@ -5,22 +5,43 @@ require 'json-schema'
5
5
 
6
6
  module OpenApi
7
7
  module SchemaValidator
8
- def self.validate!(json)
9
- validate_schema!(swagger, json)
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('../json_schemas/swagger_schema.json', __FILE__)
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('../json_schemas/json_schema_v4.json', __FILE__)
59
+ File.expand_path('json_schemas/json_schema_v4.json', __dir__)
39
60
  end
40
61
 
41
62
  def self.draft_four_schema
@@ -2,6 +2,6 @@
2
2
 
3
3
  module OpenApi
4
4
  module SchemaValidator
5
- VERSION = '0.1.1'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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.1.1
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-01-08 00:00:00.000000000 Z
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.2
187
+ rubygems_version: 3.0.3
187
188
  signing_key:
188
189
  specification_version: 4
189
190
  summary: JSON Schema Validator for OpenAPI
data/.reek DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- IrresponsibleModule:
3
- enabled: false
4
-
5
- exclude_paths:
6
- - vendor/bundle