openapi_first 2.7.0 → 2.7.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: 177998c88421283a6868e3aa9c5bbbe1eea702bc8b65abb22c28795cb2b7b6a2
4
- data.tar.gz: 603118b530e39957ea95086d98a95362e9eb9b9490a63adc7c2bc8e0f7ba7846
3
+ metadata.gz: 93e611196a63a7f9bf41d6ee90c25f22dbeaf49bc7c08ff00c26dd579c68a70d
4
+ data.tar.gz: dbe36e65d24186b0c3ac258508f4ae5ecbd7eea55a6679d6107c7b2d2dee6547
5
5
  SHA512:
6
- metadata.gz: 58aac32a5c8d7433414f4bf0f2cbf8142376c76d9ad918bf06531f40da0206e870a12e36718ca7763dd273ea18b664799f22acff84df143e36591a19284895fd
7
- data.tar.gz: cba873da9fa8b1bf957a47fe34dcd30c50af51185dc83ba78c3f78ad2d5630399555c7d81f89f6e7cb96d9c56771c55aa956900249c2a6700d88869233339f6d
6
+ metadata.gz: 2ef33d27a35ed67937026a735a35ee4934519b4463f09e95a4e0987f17c50c72d40990827a1f05f8bfad6b2e1ba4e79fea86d055d3b29d2e11b07810a7eba6fb
7
+ data.tar.gz: 5b7825b079722c7718f84b7ebb211a6201a03723077aac83947d654470b773ba389e95424a5038fab74370a521890c848cd0016381ef34104e1b4c2a3daa4fda
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.7.2
6
+
7
+ - Fix $ref-resolving for referenced arrays.
8
+ This fixes loading something like this:
9
+ ```yaml
10
+ parameters:
11
+ $ref: 'my-paramters.yaml'
12
+ ```
13
+
14
+ ## 2.7.1
15
+
16
+ - Speedup loading very large OADs by deferring creation of JSONSchemer::Schema instances.
17
+
5
18
  ## 2.7.0
6
19
 
7
20
  - Allow to override path for schema matching with `config.path = ->(request) { '/prefix' + request.path } ` (https://github.com/ahx/openapi_first/issues/349)
data/README.md CHANGED
@@ -332,8 +332,6 @@ Here is a [feature comparison between openapi_first and committee](https://gist.
332
332
 
333
333
  ### How can I adapt request paths that don't match my schema?
334
334
 
335
- If your API is deployed at a different path than what's defined in your OpenAPI schema, you can use `env[OpenapiFirst::PATH]` to override the path used for schema matching.
336
-
337
335
  Let's say you have `openapi.yaml` like this:
338
336
 
339
337
  ```yaml
@@ -14,7 +14,12 @@ module OpenapiFirst
14
14
  def self.for(value, filepath: nil, context: value)
15
15
  case value
16
16
  when ::Hash
17
- Hash.new(value, context:, filepath:)
17
+ resolver = Hash.new(value, context:, filepath:)
18
+ if value.key?('$ref')
19
+ probe = resolver.resolve_ref(value['$ref'])
20
+ return probe if probe.is_a?(Array)
21
+ end
22
+ resolver
18
23
  when ::Array
19
24
  Array.new(value, context:, filepath:)
20
25
  when ::NilClass
@@ -127,9 +132,31 @@ module OpenapiFirst
127
132
  # You have to pass configuration or ref_resolver
128
133
  def schema(options)
129
134
  base_uri = URI::File.build({ path: "#{dir}/" })
130
- root = JSONSchemer::Schema.new(context, base_uri:, **options)
131
- # binding.irb if value['maxItems'] == 4
132
- JSONSchemer::Schema.new(value, nil, root, base_uri:, **options)
135
+ Schema.new(value:, context:, base_uri:, options:)
136
+ end
137
+ end
138
+
139
+ # @visibility private
140
+ # Defers initialization JSONSchemer::Schema, because that takes time.
141
+ class Schema
142
+ extend Forwardable
143
+
144
+ def initialize(value:, context:, base_uri:, options:)
145
+ @value = value
146
+ @context = context
147
+ @base_uri = base_uri
148
+ @options = options
149
+ end
150
+
151
+ attr_reader :value, :context, :base_uri, :options
152
+
153
+ def_delegators :schema, :validate, :valid?
154
+
155
+ def schema
156
+ @schema ||= begin
157
+ root_schema = JSONSchemer::Schema.new(context, base_uri:, **options)
158
+ JSONSchemer::Schema.new(value, nil, root_schema, base_uri:, **options)
159
+ end
133
160
  end
134
161
  end
135
162
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiFirst
4
- VERSION = '2.7.0'
4
+ VERSION = '2.7.2'
5
5
  end
data/lib/openapi_first.rb CHANGED
@@ -16,9 +16,6 @@ module OpenapiFirst
16
16
  # Key in rack to find instance of Request
17
17
  REQUEST = 'openapi.request'
18
18
 
19
- # Key in rack to store the alternate path used for schema matching
20
- PATH = 'openapi.path'
21
-
22
19
  FAILURE = :openapi_first_validation_failure
23
20
 
24
21
  # @return [Configuration]
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.7.0
4
+ version: 2.7.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andreas Haller
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-05-04 00:00:00.000000000 Z
10
+ date: 2025-05-17 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: hana