openapi_validator 0.3.1 → 0.3.2

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
2
  SHA256:
3
- metadata.gz: c77d8c4333e1c630e7bb47b6b3c48dab8f62ac63f3f84a1f94af542751ff922e
4
- data.tar.gz: 71d27fc8274125b78a6811980564b0a6a2b95154b177a0929db2fb170e889752
3
+ metadata.gz: 03d06da470bc735d01636c06b916e5247d961cb6c1ba45927bed48b052ea8063
4
+ data.tar.gz: a1eb96abfb80219e9bf1019b6210a9b92a47a56be8db4887c6d6fdc59e97af6d
5
5
  SHA512:
6
- metadata.gz: 4e6ca867e985782198c5179ed0870b448c06e52032f5493bff26c00a46828435150af228e5cea278236baad6c9fe2ae19d227eef53feb654aabb8720e681e31e
7
- data.tar.gz: 83605a6384b31ca09de743fb7af868a67e8244cb8b934ae9f623a62cbdf70aeb648e7c6e3d8ea6f7a08f1e38391bb46ce9779e220d8c83f3a09aec9dac5ec872
6
+ metadata.gz: f8136a756581e5409821f4ca8d3ea10f9e1334b47dd1027af66415ab850f5db96bd69ed996d9e647ac41712bd22c7e6f0408c0fffef6c8a0edfef7a5f01d70f6
7
+ data.tar.gz: 607e50ebd480b4e0b2cdb6f91494ead6c33e781ca290b901f457fc3731e118a17366fac841811ae5f6755856726c4d96bfbf9bc62ad4082da4b53ad193798cd9
data/README.md CHANGED
@@ -1,14 +1,14 @@
1
1
  [gem]: https://rubygems.org/gems/openapi_validator
2
- [travis]: https://travis-ci.org/llcmedsolutions/openapi_validator
3
- [codeclimate]: https://codeclimate.com/github/llcmedsolutions/openapi_validator
2
+ [travis]: https://travis-ci.org/medsolutions/openapi_validator
3
+ [codeclimate]: https://codeclimate.com/github/medsolutions/openapi_validator
4
4
 
5
5
  # openapi_validator
6
6
  [![Gem Version](https://badge.fury.io/rb/openapi_validator.svg)][gem]
7
- [![Build Status](https://travis-ci.org/llcmedsolutions/openapi_validator.svg?branch=master)][travis]
8
- [![Code Climate](https://codeclimate.com/github/llcmedsolutions/openapi_validator/badges/gpa.svg)][codeclimate]
9
- [![Test Coverage](https://codeclimate.com/github/llcmedsolutions/openapi_validator/badges/coverage.svg)][codeclimate]
7
+ [![Build Status](https://travis-ci.org/medsolutions/openapi_validator.svg?branch=master)][travis]
8
+ [![Code Climate](https://codeclimate.com/github/medsolutions/openapi_validator/badges/gpa.svg)][codeclimate]
9
+ [![Test Coverage](https://codeclimate.com/github/medsolutions/openapi_validator/badges/coverage.svg)][codeclimate]
10
10
 
11
- Validator used for [openapi_rspec](https://github.com/llcmedsolutions/openapi_rspec)
11
+ Validator used for [openapi_rspec](https://github.com/medsolutions/openapi_rspec)
12
12
 
13
13
  ## Installation
14
14
 
@@ -38,7 +38,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
38
38
 
39
39
  ## Contributing
40
40
 
41
- Bug reports and pull requests are welcome on GitHub at https://github.com/llcmedsolutions/openapi_validator.
41
+ Bug reports and pull requests are welcome on GitHub at https://github.com/medsolutions/openapi_validator.
42
42
 
43
43
  ## License
44
44
 
@@ -6,6 +6,10 @@ module OpenapiValidator
6
6
 
7
7
  extend Forwardable
8
8
 
9
+ def empty_schema?
10
+ @empty_schema || false
11
+ end
12
+
9
13
  def path
10
14
  [path_key, method, @schema_code]
11
15
  end
@@ -39,6 +43,10 @@ module OpenapiValidator
39
43
  end
40
44
 
41
45
  def validate_path_exists
46
+ if code_schema.nil?
47
+ @empty_schema = true
48
+ return
49
+ end
42
50
  code_schema.dig(media_type) ||
43
51
  raise(Error, "OpenAPI documentation does not have a documented response"\
44
52
  " for #{media_type} media-type at path #{method.upcase} #{path_key}")
@@ -86,11 +94,16 @@ module OpenapiValidator
86
94
  end
87
95
 
88
96
  def build_fragment
89
- if @fragment_path
90
- @fragment_path.split("/") + ["content", media_type, "schema"]
91
- else
92
- ["#", "paths", path_key, method, "responses", @schema_code, "content", media_type, "schema"]
93
- end
97
+ fragment =
98
+ if @fragment_path
99
+ @fragment_path.split("/")
100
+ else
101
+ ["#", "paths", path_key, method, "responses", @schema_code]
102
+ end
103
+
104
+ fragment += ["content", media_type, "schema"] unless @empty_schema
105
+
106
+ fragment
94
107
  end
95
108
  end
96
109
  end
@@ -22,7 +22,13 @@ module OpenapiValidator
22
22
  if request.code != code.to_s
23
23
  @errors << "Path #{request.path} did not respond with expected status code. Expected #{request.code} got #{code}"
24
24
  end
25
- @errors += JSON::Validator.fully_validate(validator.api_doc, body, fragment: path_validator.fragment)
25
+
26
+ if path_validator.empty_schema?
27
+ @errors << "Path #{request.path} should return empty response." unless body.empty?
28
+ else
29
+ @errors += JSON::Validator.fully_validate(validator.api_doc, body, fragment: path_validator.fragment)
30
+ end
31
+
26
32
  validator.remove_validated_path(path_validator.path) if @errors.empty?
27
33
  self
28
34
  end
@@ -39,9 +39,12 @@ module OpenapiValidator
39
39
 
40
40
  # @return [Array]
41
41
  def build_unvalidated_requests
42
+ http_methods = %w[get put post delete options head patch trace]
42
43
  requests = []
43
44
  api_doc["paths"] && api_doc["paths"].each do |path, methods|
44
45
  methods.each do |method, values|
46
+ next unless http_methods.include?(method)
47
+
45
48
  values["responses"] && values["responses"].each_key do |code|
46
49
  requests << [path, method, code]
47
50
  end
@@ -1,3 +1,3 @@
1
1
  module OpenapiValidator
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_validator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-16 00:00:00.000000000 Z
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json-schema
@@ -86,7 +86,7 @@ files:
86
86
  - lib/openapi_validator/request_validator.rb
87
87
  - lib/openapi_validator/validator.rb
88
88
  - lib/openapi_validator/version.rb
89
- homepage: https://github.com/llcmedsolutions/openapi_validator
89
+ homepage: https://github.com/medsolutions/openapi_validator
90
90
  licenses:
91
91
  - MIT
92
92
  metadata: {}