openapi_first 2.9.0 → 2.9.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: c4ae98a82d67480a49874eaec264d200b53685f1fd7d28e09e4e3faf2fc86075
4
- data.tar.gz: e8d1166f2876dc7f5e909fe9290a03f0f8c530bc6469822a3c88583fa0a29047
3
+ metadata.gz: 77ee23a7f40889116a6ae239e51711460c21c9f134f7e85bef5c2869d91d7d26
4
+ data.tar.gz: 5b541d1727e879c8e1ace187679bd6bc708054e2675d127dfca718fc963fb10b
5
5
  SHA512:
6
- metadata.gz: dd927a3a8a9167e69b1fd2f795b333b232581cc1fb2ee805105f89d82125d58eddd951660fb06d300ac41555ef7ce6cfc2b680feda2d809c8fe64eebc8537b1b
7
- data.tar.gz: 456f6f1ccffc43d20b3ab51cdd4d392ac4dacf00e403bb92f8829f88e97c63fd48ac1ba316d5dc89662e1d32509f2ee6a92c60b7f327b261d428125bf8e2ec99
6
+ metadata.gz: 68e0311f5a70192b54a4d3c3654e1910b39bdfc420db4c5abcce38ba4dc2d2f4e78a278ac35be8a9796c59ba42428c3b67912adb08c1aeb469ba5d08f8223800
7
+ data.tar.gz: e43db82ccea7aeca33f58fa705f16844080f672dc0b157f72f10aa1e5fdf7ca4a71d6146c93622b46b226811b6e9cd09c61fa72fec6fb16831edfc606668089b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.9.2
6
+
7
+ - OpenapiFirst::Test reports all non-covered requests now
8
+ - Response validation: Improve content type mismatch exception message
9
+
10
+ ## 2.9.1
11
+
12
+ - Fix OpenapiFirst::Test's request validation to not always raise an error, but only for unknown requests
13
+
5
14
  ## 2.9.0
6
15
 
7
16
  - OpenapiFirst::Test now raises an error for unknown requests. You can deactivate with:
data/README.md CHANGED
@@ -368,6 +368,8 @@ use OpenapiFirst::Middlewares::RequestValidation, oad
368
368
 
369
369
  ## Development
370
370
 
371
+ Run `git submodule update --init` to initialize the git submodules.
372
+
371
373
  Run `bin/setup` to install dependencies.
372
374
 
373
375
  See `bundle exec rake` to run the linter and the tests.
@@ -16,20 +16,24 @@ module OpenapiFirst
16
16
  return Match.new(error: Failure.new(:response_not_found, message:), response: nil)
17
17
  end
18
18
  response = FindContent.call(contents, content_type)
19
- if response.nil?
20
- message = "#{content_error(content_type, request_method:,
21
- path:)} Content-Type should be #{contents.keys.join(' or ')}."
22
- return Match.new(error: Failure.new(:response_not_found, message:), response: nil)
23
- end
19
+ return response_not_found(content_type:, contents:, request_method:, path:) unless response
24
20
 
25
21
  Match.new(response:, error: nil)
26
22
  end
27
23
 
28
- def self.content_error(content_type, request_method:, path:)
29
- return 'Response Content-Type must not be empty.' if content_type.nil? || content_type.empty?
30
-
31
- "Response Content-Type #{content_type} is not defined for #{request_method} #{path}."
24
+ def self.response_not_found(content_type:, contents:, request_method:, path:)
25
+ empty_content = content_type.nil? || content_type.empty?
26
+ message =
27
+ "Content-Type should be #{contents.keys.join(' or ')}, " \
28
+ "but was #{empty_content ? 'empty' : content_type} for " \
29
+ "#{request_method.upcase} #{path}"
30
+
31
+ Match.new(
32
+ error: Failure.new(:response_not_found, message:),
33
+ response: nil
34
+ )
32
35
  end
36
+ private_class_method :response_not_found
33
37
 
34
38
  def self.find_status(responses, status)
35
39
  # According to OAS status has to be a string,
@@ -33,14 +33,17 @@ module OpenapiFirst
33
33
  @out.print(string)
34
34
  end
35
35
 
36
- def format_plan(plan)
36
+ def format_plan(plan) # rubocop:disable Metrics/PerceivedComplexity
37
37
  puts ['', "API validation coverage for #{plan.api_identifier}: #{plan.coverage}%"]
38
38
  return if plan.done? && !verbose
39
39
 
40
+ requested_routes_count = plan.routes.count { |route| route.requests.any?(&:requested?) }
41
+ focused_route = requested_routes_count <= 1 && focused
42
+
40
43
  plan.routes.each do |route|
41
44
  next if route.finished? && !verbose
42
45
 
43
- next if route.requests.none?(&:requested?) && focused
46
+ next if route.requests.none?(&:requested?) && focused_route
44
47
 
45
48
  format_requests(route.requests)
46
49
 
@@ -102,8 +102,6 @@ module OpenapiFirst
102
102
  @after_request_validation = config.after_request_validation do |validated_request, oad|
103
103
  raise validated_request.error.exception if raise_request_error?(validated_request)
104
104
 
105
- configuration.ignore_unknown_requests && validated_request.known?
106
-
107
105
  Coverage.track_request(validated_request, oad)
108
106
  end
109
107
 
@@ -120,7 +118,7 @@ module OpenapiFirst
120
118
 
121
119
  def self.raise_request_error?(validated_request)
122
120
  return false if validated_request.valid?
123
- return true if validated_request.known?
121
+ return false if validated_request.known?
124
122
 
125
123
  !configuration.ignore_unknown_requests
126
124
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.9.0'
4
+ VERSION = '2.9.2'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.9.0
4
+ version: 2.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller