openapi_first 2.9.1 → 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: 6b40040b17718d7e8f1c98bfbdc1182e0d1bb454ff3e2c6c54424c8acdf40ca0
4
- data.tar.gz: f41d5ab780eb888cdec6edbc9bd7d017368af07148ca65a1c09139c88ce9cad9
3
+ metadata.gz: 77ee23a7f40889116a6ae239e51711460c21c9f134f7e85bef5c2869d91d7d26
4
+ data.tar.gz: 5b541d1727e879c8e1ace187679bd6bc708054e2675d127dfca718fc963fb10b
5
5
  SHA512:
6
- metadata.gz: 178a990a3ad830e51f1ef9e2fdc15154722ec21ce7d03d9f9592be04226acc45c357a10a956dec8aeb341daaef95bf24c955004800d22ed53b4460111656aeb3
7
- data.tar.gz: c6784c5566dd25bc9e633793aa63574d5e663c135169542d5d3c7137f6cdec6f50892059a5f20cad5fba17ba353339f4b23cd654820accaaa5450417ade30bb9
6
+ metadata.gz: 68e0311f5a70192b54a4d3c3654e1910b39bdfc420db4c5abcce38ba4dc2d2f4e78a278ac35be8a9796c59ba42428c3b67912adb08c1aeb469ba5d08f8223800
7
+ data.tar.gz: e43db82ccea7aeca33f58fa705f16844080f672dc0b157f72f10aa1e5fdf7ca4a71d6146c93622b46b226811b6e9cd09c61fa72fec6fb16831edfc606668089b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
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
+
5
10
  ## 2.9.1
6
11
 
7
12
  - Fix OpenapiFirst::Test's request validation to not always raise an error, but only for unknown requests
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.9.1'
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.1
4
+ version: 2.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller