Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

## 2.7.1

- Speedup loading very large OADs by deferring creation of JSONSchemer::Schema instances.

## 2.7.0

- Allow to override path for schema matching with `config.path = ->(request) { '/prefix' + request.path } ` (https://github.com/ahx/openapi_first/issues/349)
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
openapi_first (2.7.0)
openapi_first (2.7.1)
hana (~> 1.3)
json_schemer (>= 2.1, < 3.0)
openapi_parameters (>= 0.3.3, < 2.0)
Expand Down Expand Up @@ -80,7 +80,7 @@ GEM
prism (1.4.0)
racc (1.8.1)
rack (3.1.13)
rack-session (2.1.0)
rack-session (2.1.1)
base64 (>= 0.1.0)
rack (>= 3.0.0)
rack-test (2.2.0)
Expand All @@ -106,11 +106,11 @@ GEM
rspec-expectations (3.13.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.3)
rspec-mocks (3.13.4)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.3)
rubocop (1.75.4)
rubocop (1.75.5)
json (~> 2.3)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.1.0)
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ..
specs:
openapi_first (2.7.0)
openapi_first (2.7.1)
hana (~> 1.3)
json_schemer (>= 2.1, < 3.0)
openapi_parameters (>= 0.3.3, < 2.0)
Expand Down Expand Up @@ -46,7 +46,7 @@ GEM
base64 (>= 0.1.0)
logger (>= 1.6.0)
rack (>= 3.0.0, < 4)
rack-session (2.1.0)
rack-session (2.1.1)
base64 (>= 0.1.0)
rack (>= 3.0.0)
regexp_parser (2.10.0)
Expand Down
2 changes: 1 addition & 1 deletion examples/rails_app/Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: ../..
specs:
openapi_first (2.7.0)
openapi_first (2.7.1)
hana (~> 1.3)
json_schemer (>= 2.1, < 3.0)
openapi_parameters (>= 0.3.3, < 2.0)
Expand Down
28 changes: 25 additions & 3 deletions lib/openapi_first/ref_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,31 @@ def each
# You have to pass configuration or ref_resolver
def schema(options)
base_uri = URI::File.build({ path: "#{dir}/" })
root = JSONSchemer::Schema.new(context, base_uri:, **options)
# binding.irb if value['maxItems'] == 4
JSONSchemer::Schema.new(value, nil, root, base_uri:, **options)
Schema.new(value:, context:, base_uri:, options:)
end
end

# @visibility private
# Defers initialization JSONSchemer::Schema, because that takes time.
class Schema
extend Forwardable

def initialize(value:, context:, base_uri:, options:)
@value = value
@context = context
@base_uri = base_uri
@options = options
end

attr_reader :value, :context, :base_uri, :options

def_delegators :schema, :validate, :valid?

def schema
@schema ||= begin
root_schema = JSONSchemer::Schema.new(context, base_uri:, **options)
JSONSchemer::Schema.new(value, nil, root_schema, base_uri:, **options)
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/openapi_first/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module OpenapiFirst
VERSION = '2.7.0'
VERSION = '2.7.1'
end
10,263 changes: 10,263 additions & 0 deletions spec/data/large.yaml

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions spec/openapi_first_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
expect(returned_definition).to be(original_definition)
end

require 'benchmark'
it 'works with a large document' do
time = Benchmark.realtime do
Timeout.timeout(2) do
OpenapiFirst.load('./spec/data/large.yaml')
end
end
expect(time).to be < 1
end

describe 'only option' do
specify 'with empty filter' do
definition = OpenapiFirst.load(spec_path, only: nil)
Expand Down
Loading