openapi_first 2.2.0 → 2.2.1

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: b6f86609c16829b7f0f94d837167a44e4cf93b38a392ac34b93a9ff9d7a794fc
4
- data.tar.gz: 1524298280aa89e6cbae16ce80259ed1d0928b4018747eb6c3385ebed0e8db8b
3
+ metadata.gz: 9458fb5b815dcc64722a1829dc2082f60a92b36ce7af9fa8529c041544b190d4
4
+ data.tar.gz: 5f5982e1e71f5f1a150860be23291863ff3c431b3bce332899b01150e2c9fc11
5
5
  SHA512:
6
- metadata.gz: a0d30f3482838dd995f44b5ede610ada74ff1a5d2c2e29a1b3fa109da98cbc5cd42bf8616b4f7e6c79b558d1c16b77ca1eb85b4fc82bcbd9e40c6dcf75aea927
7
- data.tar.gz: 7f87349cd6fa98cef19f929db3deeb1c94a9b2eed759f23f592ba145c315726cfe8ff3f5fb3f50444b566a5d95b94370439015fd995554ecececc7029adff9ec
6
+ metadata.gz: c92c5cbda9bcd884299a265fcc713c0370e0766670e2b3199af9169dfe29855ed78ae5ad1a70fd98326a4f764403e0b9429132b97ee9f3b887d5d9af772acd69
7
+ data.tar.gz: '05083e92a954621b54667d8f99c133b2489e70eaa2b7332885c867053c81667a0eba0779ad210c150c8402814dff6d144044349271e8fe06808bafe0e5ad94ca'
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.2.1
6
+
7
+ - Fix issue with $ref resolving paths poiting outside directories `$ref: '../a/b.yaml'` (https://github.com/ahx/openapi_first/issues/313)
8
+ - Remove warning about missing assertions when using assert_api_conform (https://github.com/ahx/openapi_first/issues/313)
9
+
5
10
  ## 2.2.0
6
11
 
7
12
  - Fix support for discriminator in response bodies if no mapping is defined (https://github.com/ahx/openapi_first/issues/285)
@@ -22,5 +22,4 @@ begin
22
22
  end
23
23
  rescue LoadError
24
24
  require 'json'
25
- puts 'openapi_first uses the default json gem'
26
25
  end
@@ -40,7 +40,7 @@ module OpenapiFirst
40
40
  def initialize(value, context: value, dir: nil)
41
41
  @value = value
42
42
  @context = context
43
- @dir = dir
43
+ @dir = (dir && File.absolute_path(dir)) || Dir.pwd
44
44
  end
45
45
 
46
46
  # The value of this node
@@ -108,10 +108,11 @@ module OpenapiFirst
108
108
 
109
109
  def schema(options = {})
110
110
  ref_resolver = JSONSchemer::CachedResolver.new do |uri|
111
- FileLoader.load(File.join(dir, uri.path))
111
+ FileLoader.load(uri.path)
112
112
  end
113
- root = JSONSchemer::Schema.new(context, ref_resolver:, **options)
114
- JSONSchemer::Schema.new(value, nil, root, **options)
113
+ base_uri = URI::File.build({ path: "#{dir}/" })
114
+ root = JSONSchemer::Schema.new(context, base_uri:, ref_resolver:, **options)
115
+ JSONSchemer::Schema.new(value, nil, root, base_uri:, **options)
115
116
  end
116
117
  end
117
118
 
@@ -1,20 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'minitest_helpers'
4
+ require_relative 'plain_helpers'
5
+
3
6
  module OpenapiFirst
7
+ # Test integration
4
8
  module Test
5
9
  # Methods to use in integration tests
6
10
  module Methods
7
- def assert_api_conform(status: nil, api: :default)
8
- api = OpenapiFirst::Test[api]
9
- request = respond_to?(:last_request) ? last_request : @request
10
- response = respond_to?(:last_response) ? last_response : @response
11
- if status && status != response.status
12
- raise OpenapiFirst::Error,
13
- "Expected status #{status}, but got #{response.status} " \
14
- "from #{request.request_method.upcase} #{request.path}."
11
+ def self.included(base)
12
+ if Test.minitest?(base)
13
+ base.include(OpenapiFirst::Test::MinitestHelpers)
14
+ else
15
+ base.include(OpenapiFirst::Test::PlainHelpers)
15
16
  end
16
- api.validate_request(request, raise_error: true)
17
- api.validate_response(request, response, raise_error: true)
18
17
  end
19
18
  end
20
19
  end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenapiFirst
4
+ module Test
5
+ # Assertion methods for Minitest
6
+ module MinitestHelpers
7
+ # :nocov:
8
+ def assert_api_conform(status: nil, api: :default)
9
+ api = OpenapiFirst::Test[api]
10
+ request = respond_to?(:last_request) ? last_request : @request
11
+ response = respond_to?(:last_response) ? last_response : @response
12
+
13
+ if status
14
+ assert_equal status, response.status,
15
+ "Expected status #{status}, but got #{response.status} " \
16
+ "from #{request.request_method.upcase} #{request.path}."
17
+ end
18
+
19
+ validated_request = api.validate_request(request, raise_error: false)
20
+ validated_response = api.validate_response(request, response, raise_error: false)
21
+
22
+ assert validated_request.valid?, validated_request.error&.exception_message
23
+ assert validated_response.valid?, validated_response.error&.exception_message
24
+ end
25
+ # :nocov:
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenapiFirst
4
+ module Test
5
+ # Assertion methods to use when no known test framework was found
6
+ # These methods just raise an exception if an error was found
7
+ module PlainHelpers
8
+ def assert_api_conform(status: nil, api: :default)
9
+ api = OpenapiFirst::Test[api]
10
+ # :nocov:
11
+ request = respond_to?(:last_request) ? last_request : @request
12
+ response = respond_to?(:last_response) ? last_response : @response
13
+ # :nocov:
14
+
15
+ if status && status != response.status
16
+ raise OpenapiFirst::Error,
17
+ "Expected status #{status}, but got #{response.status} " \
18
+ "from #{request.request_method.upcase} #{request.path}."
19
+ end
20
+
21
+ api.validate_request(request, raise_error: true)
22
+ api.validate_response(request, response, raise_error: true)
23
+ end
24
+ end
25
+ end
26
+ end
@@ -5,6 +5,12 @@ require_relative 'test/methods'
5
5
  module OpenapiFirst
6
6
  # Test integration
7
7
  module Test
8
+ def self.minitest?(base)
9
+ base.include?(::Minitest::Assertions)
10
+ rescue NameError
11
+ false
12
+ end
13
+
8
14
  class NotRegisteredError < StandardError; end
9
15
 
10
16
  DEFINITIONS = {} # rubocop:disable Style/MutableConstant
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.2.0'
4
+ VERSION = '2.2.1'
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-11 00:00:00.000000000 Z
10
+ date: 2025-01-16 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: hana
@@ -124,6 +124,8 @@ files:
124
124
  - lib/openapi_first/schema/validation_result.rb
125
125
  - lib/openapi_first/test.rb
126
126
  - lib/openapi_first/test/methods.rb
127
+ - lib/openapi_first/test/minitest_helpers.rb
128
+ - lib/openapi_first/test/plain_helpers.rb
127
129
  - lib/openapi_first/validated_request.rb
128
130
  - lib/openapi_first/validated_response.rb
129
131
  - lib/openapi_first/validators/request_body.rb