openapi_first 2.2.0 → 2.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/openapi_first/json.rb +0 -1
- data/lib/openapi_first/ref_resolver.rb +5 -4
- data/lib/openapi_first/test/methods.rb +9 -10
- data/lib/openapi_first/test/minitest_helpers.rb +28 -0
- data/lib/openapi_first/test/plain_helpers.rb +26 -0
- data/lib/openapi_first/test.rb +6 -0
- data/lib/openapi_first/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9458fb5b815dcc64722a1829dc2082f60a92b36ce7af9fa8529c041544b190d4
|
4
|
+
data.tar.gz: 5f5982e1e71f5f1a150860be23291863ff3c431b3bce332899b01150e2c9fc11
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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)
|
data/lib/openapi_first/json.rb
CHANGED
@@ -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(
|
111
|
+
FileLoader.load(uri.path)
|
112
112
|
end
|
113
|
-
|
114
|
-
JSONSchemer::Schema.new(
|
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
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
data/lib/openapi_first/test.rb
CHANGED
@@ -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
|
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.
|
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-
|
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
|