openapi_first 1.1.1 → 1.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: 4bb6d0ee4dbe98020ef124e79a99ced0d0111b1e2891cc8cb3ed8bb697973d2b
4
- data.tar.gz: 77ce896a68f885614f64fd680af0dde1860c07ae772ce7d5f7d1b75b5abb4528
3
+ metadata.gz: 5ee379d839bec13bd899f690b3275d761b7425461f2241da4ccb62de384f0c94
4
+ data.tar.gz: 6ea27d437c7cb443d5b5c84b8e6d0ef34782e4f5d8bb5ce7666acc78797ca523
5
5
  SHA512:
6
- metadata.gz: 841e32068646969d92ab26fff9c332e849056463c99805c8e0dbbb437918113a09750fb5ceffd3940716911ea50bc20685acbcd862aa6acc270e43fe43675c87
7
- data.tar.gz: d9a225b3e3119512fc3ed585f00f6f915e21f3199206f520d20733999441567e651fcb129588092c4e7ea9dcc4ce1e77c24365b04b8a8d9d232b8a1a5cd8e1da
6
+ metadata.gz: ab20a8bcd7d61961f4a1d654a36291f295ee0d69c50829cd8f1965998ca9a480a0636e2b0ca62d220a53c62b60d8bedb934fc8a57bed39a8e45683796a5cee8a
7
+ data.tar.gz: 43206c1bf540193863bd1f02c14f79d172fff662974c8efbfd90dfd6334f11f23c0dee62c9c70c4bd45bbf202e68a76c9750a00aa4a45f5dd8682b6837a1177b
data/CHANGELOG.md CHANGED
@@ -1,15 +1,20 @@
1
1
  # Changelog
2
2
 
3
- ## 1.1.1
3
+ ## 1.2.0
4
4
 
5
- - Fix reading response body for example when running Rails (`ActionDispatch::Response::RackBody`)
5
+ - Added `OpenapiFirst.parse(hash)` to load ("parse") a resolved/de-referenced Hash
6
+ - Added support for unescaped special characters in the path params (https://github.com/ahx/openapi_first/pull/217)
7
+ - Added `operation` to `RuntimeRequest` by [@MrBananaLord](https://github.com/ahx/openapi_first/pull/216)
6
8
 
7
- ## 1.1.0
9
+ ## 1.1.1
8
10
 
11
+ - Fix reading response body for example when running Rails (`ActionDispatch::Response::RackBody`)
9
12
  - Add `known?`, `status`, `body`, `headers`, `content_type` methods to inspect the parsed response (`RuntimeResponse`)
10
13
  - Add `OpenapiFirst::ParseError` which is raised by low-level interfaces like `request.body` if the body could not be parsed.
11
14
  - Add "code" field to errors in JSON:API error response
12
15
 
16
+ ## 1.1.0 (yanked)
17
+
13
18
  ## 1.0.0
14
19
 
15
20
  - Breaking: The default error uses application/problem+json content-type
data/Gemfile.lock CHANGED
@@ -1,20 +1,20 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openapi_first (1.1.1)
4
+ openapi_first (1.2.1)
5
5
  json_refs (~> 0.1, >= 0.1.7)
6
6
  json_schemer (~> 2.1.0)
7
7
  multi_json (~> 1.15)
8
- mustermann-contrib (~> 3.0.0)
8
+ mustermann (~> 3.0.0)
9
9
  openapi_parameters (>= 0.3.2, < 2.0)
10
10
  rack (>= 2.2, < 4.0)
11
11
 
12
12
  GEM
13
13
  remote: https://rubygems.org/
14
14
  specs:
15
- actionpack (7.1.2)
16
- actionview (= 7.1.2)
17
- activesupport (= 7.1.2)
15
+ actionpack (7.1.3)
16
+ actionview (= 7.1.3)
17
+ activesupport (= 7.1.3)
18
18
  nokogiri (>= 1.8.5)
19
19
  racc
20
20
  rack (>= 2.2.4)
@@ -22,13 +22,13 @@ GEM
22
22
  rack-test (>= 0.6.3)
23
23
  rails-dom-testing (~> 2.2)
24
24
  rails-html-sanitizer (~> 1.6)
25
- actionview (7.1.2)
26
- activesupport (= 7.1.2)
25
+ actionview (7.1.3)
26
+ activesupport (= 7.1.3)
27
27
  builder (~> 3.1)
28
28
  erubi (~> 1.11)
29
29
  rails-dom-testing (~> 2.2)
30
30
  rails-html-sanitizer (~> 1.6)
31
- activesupport (7.1.2)
31
+ activesupport (7.1.3)
32
32
  base64
33
33
  bigdecimal
34
34
  concurrent-ruby (~> 1.0, >= 1.0.2)
@@ -40,9 +40,9 @@ GEM
40
40
  tzinfo (~> 2.0)
41
41
  ast (2.4.2)
42
42
  base64 (0.2.0)
43
- bigdecimal (3.1.5)
43
+ bigdecimal (3.1.6)
44
44
  builder (3.2.4)
45
- concurrent-ruby (1.2.2)
45
+ concurrent-ruby (1.2.3)
46
46
  connection_pool (2.4.1)
47
47
  crass (1.0.6)
48
48
  diff-lcs (1.5.0)
@@ -51,7 +51,6 @@ GEM
51
51
  ruby2_keywords
52
52
  erubi (1.12.0)
53
53
  hana (1.3.7)
54
- hansi (0.2.1)
55
54
  i18n (1.14.1)
56
55
  concurrent-ruby (~> 1.0)
57
56
  json (2.7.1)
@@ -65,13 +64,10 @@ GEM
65
64
  loofah (2.22.0)
66
65
  crass (~> 1.0.2)
67
66
  nokogiri (>= 1.12.0)
68
- minitest (5.21.1)
67
+ minitest (5.21.2)
69
68
  multi_json (1.15.0)
70
69
  mustermann (3.0.0)
71
70
  ruby2_keywords (~> 0.0.1)
72
- mustermann-contrib (3.0.0)
73
- hansi (~> 0.2.0)
74
- mustermann (= 3.0.0)
75
71
  mutex_m (0.2.0)
76
72
  nokogiri (1.16.0-arm64-darwin)
77
73
  racc (~> 1.4)
@@ -81,7 +77,7 @@ GEM
81
77
  rack (>= 2.2)
82
78
  zeitwerk (~> 2.6)
83
79
  parallel (1.24.0)
84
- parser (3.3.0.3)
80
+ parser (3.3.0.5)
85
81
  ast (~> 2.4.1)
86
82
  racc
87
83
  racc (1.7.3)
@@ -117,11 +113,11 @@ GEM
117
113
  diff-lcs (>= 1.2.0, < 2.0)
118
114
  rspec-support (~> 3.12.0)
119
115
  rspec-support (3.12.1)
120
- rubocop (1.59.0)
116
+ rubocop (1.60.1)
121
117
  json (~> 2.3)
122
118
  language_server-protocol (>= 3.17.0)
123
119
  parallel (~> 1.10)
124
- parser (>= 3.2.2.4)
120
+ parser (>= 3.3.0.2)
125
121
  rainbow (>= 2.2.2, < 4.0)
126
122
  regexp_parser (>= 1.8, < 3.0)
127
123
  rexml (>= 3.2.5, < 4.0)
data/Gemfile.rack2.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- openapi_first (1.0.0.beta6)
4
+ openapi_first (1.1.1)
5
5
  json_refs (~> 0.1, >= 0.1.7)
6
6
  json_schemer (~> 2.1.0)
7
7
  multi_json (~> 1.15)
8
- mustermann-contrib (~> 3.0.0)
8
+ mustermann (~> 3.0.0)
9
9
  openapi_parameters (>= 0.3.2, < 2.0)
10
10
  rack (>= 2.2, < 4.0)
11
11
 
@@ -15,7 +15,6 @@ GEM
15
15
  ast (2.4.2)
16
16
  diff-lcs (1.5.0)
17
17
  hana (1.3.7)
18
- hansi (0.2.1)
19
18
  json (2.7.1)
20
19
  json_refs (0.1.8)
21
20
  hana
@@ -27,9 +26,6 @@ GEM
27
26
  multi_json (1.15.0)
28
27
  mustermann (3.0.0)
29
28
  ruby2_keywords (~> 0.0.1)
30
- mustermann-contrib (3.0.0)
31
- hansi (~> 0.2.0)
32
- mustermann (= 3.0.0)
33
29
  openapi_parameters (0.3.2)
34
30
  rack (>= 2.2)
35
31
  zeitwerk (~> 2.6)
@@ -6,7 +6,8 @@ module OpenapiFirst
6
6
  class BodyParser
7
7
  def self.const_missing(const_name)
8
8
  super unless const_name == :ParsingError
9
- warn 'DEPRECATION WARNING: OpenapiFirst::BodyParser::ParsingError is deprecated. Use OpenapiFirst::ParseError instead.' # rubocop:disable Layout/LineLength
9
+ warn 'DEPRECATION WARNING: OpenapiFirst::BodyParser::ParsingError is deprecated. ' \
10
+ 'Use OpenapiFirst::ParseError instead.'
10
11
  OpenapiFirst::ParseError
11
12
  end
12
13
 
@@ -11,8 +11,7 @@ module OpenapiFirst
11
11
  class Operation
12
12
  extend Forwardable
13
13
  def_delegators :operation_object,
14
- :[],
15
- :dig
14
+ :[]
16
15
 
17
16
  WRITE_METHODS = Set.new(%w[post put patch delete]).freeze
18
17
  private_constant :WRITE_METHODS
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mustermann/template'
3
+ require 'mustermann'
4
4
  require_relative 'definition/path_item'
5
5
  require_relative 'runtime_request'
6
6
 
@@ -9,7 +9,7 @@ module OpenapiFirst
9
9
  class Definition
10
10
  attr_reader :filepath, :paths, :openapi_version
11
11
 
12
- def initialize(resolved, filepath)
12
+ def initialize(resolved, filepath = nil)
13
13
  @filepath = filepath
14
14
  @paths = resolved['paths']
15
15
  @openapi_version = detect_version(resolved)
@@ -60,7 +60,7 @@ module OpenapiFirst
60
60
 
61
61
  def search_for_path_item(request_path)
62
62
  paths.find do |path, path_item_object|
63
- template = Mustermann::Template.new(path)
63
+ template = Mustermann.new(path)
64
64
  path_params = template.params(request_path)
65
65
  next unless path_params
66
66
  next unless path_params.size == template.names.size
@@ -47,9 +47,22 @@ module OpenapiFirst
47
47
 
48
48
  # Raise an exception that fits the failure.
49
49
  def raise!
50
- exception, message_prefix = TYPES.fetch(error_type)
50
+ exception, = TYPES.fetch(error_type)
51
+ raise exception, exception_message
52
+ end
53
+
54
+ def exception_message
55
+ _, message_prefix = TYPES.fetch(error_type)
56
+
57
+ "#{message_prefix} #{@message || generate_message}"
58
+ end
59
+
60
+ private
51
61
 
52
- raise exception, "#{message_prefix} #{@message || errors&.map(&:error)&.join('. ')}"
62
+ def generate_message
63
+ messages = errors&.take(4)&.map(&:error)
64
+ messages << "... (#{errors.size} errors total)" if errors && errors.size > 4
65
+ messages&.join('. ')
53
66
  end
54
67
  end
55
68
  end
@@ -22,7 +22,7 @@ module OpenapiFirst
22
22
  def_delegators :@operation, :operation_id, :request_method
23
23
  def_delegator :@path_item, :path, :path_definition
24
24
 
25
- attr_reader :path_item
25
+ attr_reader :path_item, :operation
26
26
 
27
27
  def known?
28
28
  known_path? && known_request_method?
@@ -90,6 +90,6 @@ module OpenapiFirst
90
90
 
91
91
  private
92
92
 
93
- attr_reader :request, :operation
93
+ attr_reader :request
94
94
  end
95
95
  end
@@ -20,13 +20,6 @@ module OpenapiFirst
20
20
  ValidationError.new(err)
21
21
  end
22
22
  end
23
-
24
- # Returns a message that is used in exception messages.
25
- def message
26
- return unless error?
27
-
28
- errors.map(&:error).join('. ')
29
- end
30
23
  end
31
24
  end
32
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '1.1.1'
4
+ VERSION = '1.2.1'
5
5
  end
data/lib/openapi_first.rb CHANGED
@@ -28,10 +28,20 @@ module OpenapiFirst
28
28
  # Key in rack to find instance of RuntimeRequest
29
29
  REQUEST = 'openapi.request'
30
30
 
31
- def self.load(spec_path, only: nil)
32
- resolved = Bundle.resolve(spec_path)
31
+ # Load and dereference an OpenAPI spec file
32
+ def self.load(filepath, only: nil)
33
+ resolved = bundle(filepath)
34
+ parse(resolved, only:, filepath:)
35
+ end
36
+
37
+ # Parse a dereferenced Hash
38
+ def self.parse(resolved, only: nil, filepath: nil)
33
39
  resolved['paths'].filter!(&->(key, _) { only.call(key) }) if only
34
- Definition.new(resolved, spec_path)
40
+ Definition.new(resolved, filepath)
41
+ end
42
+
43
+ def self.bundle(filepath)
44
+ Bundle.resolve(filepath)
35
45
  end
36
46
 
37
47
  module Bundle
@@ -41,7 +41,7 @@ Gem::Specification.new do |spec|
41
41
  spec.add_runtime_dependency 'json_refs', '~> 0.1', '>= 0.1.7'
42
42
  spec.add_runtime_dependency 'json_schemer', '~> 2.1.0'
43
43
  spec.add_runtime_dependency 'multi_json', '~> 1.15'
44
- spec.add_runtime_dependency 'mustermann-contrib', '~> 3.0.0'
44
+ spec.add_runtime_dependency 'mustermann', '~> 3.0.0'
45
45
  spec.add_runtime_dependency 'openapi_parameters', '>= 0.3.2', '< 2.0'
46
46
  spec.add_runtime_dependency 'rack', '>= 2.2', '< 4.0'
47
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_first
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-12 00:00:00.000000000 Z
11
+ date: 2024-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json_refs
@@ -59,7 +59,7 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.15'
61
61
  - !ruby/object:Gem::Dependency
62
- name: mustermann-contrib
62
+ name: mustermann
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
65
  - - "~>"