openapi_first 2.2.1 → 2.2.3

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: 9458fb5b815dcc64722a1829dc2082f60a92b36ce7af9fa8529c041544b190d4
4
- data.tar.gz: 5f5982e1e71f5f1a150860be23291863ff3c431b3bce332899b01150e2c9fc11
3
+ metadata.gz: 543c0103c059d292d91db5a177e4a2fec307473b0438b2b851d96f2818920a9c
4
+ data.tar.gz: b98142de184e58931bc544aa867cf4700605164fbfe2b426e074732dd37f293e
5
5
  SHA512:
6
- metadata.gz: c92c5cbda9bcd884299a265fcc713c0370e0766670e2b3199af9169dfe29855ed78ae5ad1a70fd98326a4f764403e0b9429132b97ee9f3b887d5d9af772acd69
7
- data.tar.gz: '05083e92a954621b54667d8f99c133b2489e70eaa2b7332885c867053c81667a0eba0779ad210c150c8402814dff6d144044349271e8fe06808bafe0e5ad94ca'
6
+ metadata.gz: 19cec612f7336c745bbccff2a518f65ce9785d9b4f4b237adb3b4bf6b5198eaa2e52c6eefce79eec748a627e99a6d58c41a648f95e66065b9bb9c01ed188fd58
7
+ data.tar.gz: 7350acd1b0a7e4b7ca34c9c0ad2e7e18096b344c2bec42af12c140271eb55765ea73d9fbd39808d919c6a6d061b4759a0323c647bd5b7a42f104efa72d0638f8
data/CHANGELOG.md CHANGED
@@ -2,10 +2,18 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.2.3
6
+
7
+ - Respect global JSONSchemer configuration (https://github.com/ahx/openapi_first/pull/318)
8
+
9
+ ## 2.2.2
10
+
11
+ - Fix parsing parameters with referenced schemas (https://github.com/ahx/openapi_first/issues/316)
12
+
5
13
  ## 2.2.1
6
14
 
7
15
  - 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)
16
+ - Remove warning about missing assertions when using assert_api_conform ([https://github.com/ahx/openapi_first/issues/313](https://github.com/ahx/openapi_first/issues/312))
9
17
 
10
18
  ## 2.2.0
11
19
 
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'json_schemer'
4
- require_relative 'json_pointer'
5
4
  require_relative 'ref_resolver'
6
5
 
7
6
  module OpenapiFirst
@@ -18,10 +17,10 @@ module OpenapiFirst
18
17
  end
19
18
 
20
19
  def initialize(contents, filepath:, config:)
21
- @schemer_configuration = JSONSchemer::Configuration.new(
22
- meta_schema: detect_meta_schema(contents, filepath),
23
- insert_property_defaults: true
24
- )
20
+ @schemer_configuration = JSONSchemer.configuration.clone
21
+ @schemer_configuration.meta_schema = detect_meta_schema(contents, filepath)
22
+ @schemer_configuration.insert_property_defaults = true
23
+
25
24
  @config = config
26
25
  @contents = RefResolver.for(contents, dir: filepath && File.dirname(filepath))
27
26
  end
@@ -47,10 +46,11 @@ module OpenapiFirst
47
46
  def router # rubocop:disable Metrics/MethodLength
48
47
  router = OpenapiFirst::Router.new
49
48
  @contents.fetch('paths').each do |path, path_item_object|
49
+ path_parameters = resolve_parameters(path_item_object['parameters'])
50
50
  path_item_object.resolved.keys.intersection(REQUEST_METHODS).map do |request_method|
51
51
  operation_object = path_item_object[request_method]
52
- parameters = operation_object['parameters']&.resolved.to_a.chain(path_item_object['parameters']&.resolved.to_a)
53
- parameters = parse_parameters(parameters)
52
+ operation_parameters = resolve_parameters(operation_object['parameters'])
53
+ parameters = parse_parameters(operation_parameters.chain(path_parameters))
54
54
 
55
55
  build_requests(path:, request_method:, operation_object:,
56
56
  parameters:).each do |request|
@@ -89,6 +89,14 @@ module OpenapiFirst
89
89
  )
90
90
  end
91
91
 
92
+ def resolve_parameters(parameters)
93
+ parameters&.map do |parameter|
94
+ result = parameter.resolved
95
+ result['schema'] = parameter['schema'].resolved
96
+ result
97
+ end.to_a
98
+ end
99
+
92
100
  def build_parameter_schema(parameters)
93
101
  schema = build_parameters_schema(parameters)
94
102
 
@@ -118,6 +118,7 @@ module OpenapiFirst
118
118
 
119
119
  # @visibility private
120
120
  class Array
121
+ include Enumerable
121
122
  include Resolvable
122
123
  include Diggable
123
124
 
@@ -128,6 +129,12 @@ module OpenapiFirst
128
129
  RefResolver.for(item, dir:, context:)
129
130
  end
130
131
 
132
+ def each
133
+ resolved.each do |item|
134
+ yield RefResolver.for(item, dir:, context:)
135
+ end
136
+ end
137
+
131
138
  def resolved
132
139
  value.map do |item|
133
140
  if item.respond_to?(:key?) && item.key?('$ref')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.2.1'
4
+ VERSION = '2.2.3'
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.1
4
+ version: 2.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-01-16 00:00:00.000000000 Z
10
+ date: 2025-01-22 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: hana
@@ -104,7 +104,6 @@ files:
104
104
  - lib/openapi_first/failure.rb
105
105
  - lib/openapi_first/file_loader.rb
106
106
  - lib/openapi_first/json.rb
107
- - lib/openapi_first/json_pointer.rb
108
107
  - lib/openapi_first/middlewares/request_validation.rb
109
108
  - lib/openapi_first/middlewares/response_validation.rb
110
109
  - lib/openapi_first/ref_resolver.rb
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module OpenapiFirst
4
- # Functions to handle JSON Pointers
5
- # @!visibility private
6
- module JsonPointer
7
- ESCAPE_CHARS = { '~' => '~0', '/' => '~1', '+' => '%2B' }.freeze
8
- ESCAPE_REGEX = Regexp.union(ESCAPE_CHARS.keys)
9
-
10
- module_function
11
-
12
- def append(root, *tokens)
13
- "#{root}/" + tokens.map do |token|
14
- escape_json_pointer_token(token)
15
- end.join('/')
16
- end
17
-
18
- def escape_json_pointer_token(token)
19
- token.to_s.gsub(ESCAPE_REGEX, ESCAPE_CHARS)
20
- end
21
- end
22
- end