openapi-ruby 3.4.0 → 3.5.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: b58ff6e6c8ccbf7c8c02d01f6a79ea02717cf3c709de9d1c8a8f870bb44a84fb
4
- data.tar.gz: e18b82cac3cd08bee2fcbee279d45e9b705b62ad0015feb8e3e5408cf4af63a5
3
+ metadata.gz: 420f08f5a6cc99f77fc5ecd23c7e280a52b1bc930996ca637c2f61828822cc54
4
+ data.tar.gz: 831c0a52dd27d6ed1c60986b82d0e71ca271290ea5c22b40653698fd969895ae
5
5
  SHA512:
6
- metadata.gz: d9248a97e6b5f513516f5d97d87ef81f68047ce4db54c62503667d20751bf15f99fb4644cde3369d017b388184e92e65f904aa171e546c189134d8d1dc742eea
7
- data.tar.gz: 4a627ed1b9bc867c24263627a27f01f22d5fc50bfde5ffe9d93e87484c50e68f61e739162c198c808b979d484c9c1a3b80921c14eedd32a9c7b076a702a90cb9
6
+ metadata.gz: 5e0c13aaa9b0d389f067224265cb11a358679228fafd7e864cefb4cb4a037b3b80b823b4d30050e7b667eb7849c509611490403e042e4f072b78a3af88526e60
7
+ data.tar.gz: d075ef796755e29033fee117fff4cb6a4177b30749afbd6a57993e9a47273d111cce9f7c672fb87c841af3107e150120dac59655c32652da19108ca60e017821
data/README.md CHANGED
@@ -481,7 +481,7 @@ Two things to set up on the consumer side so the two test frameworks don't both
481
481
 
482
482
  ```ruby
483
483
  # test/test_helper.rb
484
- unless ENV["OPENAPI_RUBY_GENERATING"]
484
+ unless OpenapiRuby.schema_generating?
485
485
  require "rails/test_help"
486
486
  # ...other test-time setup...
487
487
  end
@@ -489,13 +489,15 @@ end
489
489
 
490
490
  ```ruby
491
491
  # spec/rails_helper.rb
492
- unless ENV["OPENAPI_RUBY_GENERATING"]
492
+ unless OpenapiRuby.schema_generating?
493
493
  require "rspec/rails"
494
494
  # ...other spec-time setup...
495
495
  end
496
496
  ```
497
497
 
498
- The rake task sets `OPENAPI_RUBY_GENERATING=true` in the subprocess. With the guards in place, neither test framework boots its full Rails integration during generation — only the DSL needs to be live for `api_path` / `path` to register.
498
+ `OpenapiRuby.schema_generating?` returns `true` when the rake task launched the current process (it sets `OPENAPI_RUBY_GENERATING=true` in the subprocess). With the guards in place, neither test framework boots its full Rails integration during generation — only the DSL needs to be live for `api_path` / `path` to register.
499
+
500
+ The guards are only needed while both frameworks are live. Once the migration completes and only one test framework remains, the rake task auto-detects that framework and the guard becomes dead code that can be removed.
499
501
 
500
502
  ## Runtime Middleware
501
503
 
@@ -46,12 +46,12 @@ module OpenapiRuby
46
46
  end
47
47
 
48
48
  def to_json(*_args)
49
- JSON.pretty_generate(@data)
49
+ JSON.pretty_generate(to_h)
50
50
  end
51
51
 
52
52
  def to_yaml
53
53
  require "yaml"
54
- @data.to_yaml
54
+ to_h.to_yaml
55
55
  end
56
56
 
57
57
  def valid?
@@ -63,18 +63,44 @@ module OpenapiRuby
63
63
  # during a phased RSpec → Minitest migration where the suite
64
64
  # holds both DSL styles. Consumers should guard
65
65
  # `require "rails/test_help"` and `require "rspec/rails"` in
66
- # their test helpers with `unless ENV["OPENAPI_RUBY_GENERATING"]`
66
+ # their test helpers with `unless OpenapiRuby.schema_generating?`
67
67
  # so the two test frameworks don't both register Rails lazy
68
68
  # hooks in the same process — only the DSL needs to be live for
69
69
  # schema generation.
70
+ #
71
+ # Each glob runs with its own framework's directory at the head
72
+ # of $LOAD_PATH so the typical `require "openapi_helper"` /
73
+ # `require "rails_helper"` / `require "test_helper"` resolves
74
+ # to the right file. Without this, both spec/ and test/ getting
75
+ # unshifted in one block leads to whichever was unshifted last
76
+ # winning every lookup — and the wrong helper getting loaded
77
+ # for the other side's files.
70
78
  def hybrid_script(pattern)
79
+ globs = pattern.split(",").map(&:strip)
80
+ spec_globs = globs.grep(%r{\bspec/})
81
+ test_globs = globs.grep(%r{\btest/})
82
+ other_globs = globs - spec_globs - test_globs
83
+
71
84
  <<~RUBY
72
85
  require "rspec/core"
73
86
  require "openapi_ruby/rspec"
74
87
  require "openapi_ruby/minitest"
75
- $LOAD_PATH.unshift(File.expand_path("spec")) unless $LOAD_PATH.include?(File.expand_path("spec"))
76
- $LOAD_PATH.unshift(File.expand_path("test")) unless $LOAD_PATH.include?(File.expand_path("test"))
77
- #{glob_loads(pattern)}
88
+
89
+ load_with_path = lambda do |dir, glob|
90
+ path = File.expand_path(dir)
91
+ added = !$LOAD_PATH.include?(path)
92
+ $LOAD_PATH.unshift(path) if added
93
+ begin
94
+ Dir.glob(glob).sort.each { |f| require File.expand_path(f) }
95
+ ensure
96
+ $LOAD_PATH.delete(path) if added
97
+ end
98
+ end
99
+
100
+ #{spec_globs.map { |g| "load_with_path.call(\"spec\", #{g.inspect})" }.join("\n ")}
101
+ #{test_globs.map { |g| "load_with_path.call(\"test\", #{g.inspect})" }.join("\n ")}
102
+ #{other_globs.map { |g| %[Dir.glob(#{g.inspect}).sort.each { |f| require File.expand_path(f) }] }.join("\n ")}
103
+
78
104
  OpenapiRuby::Generator::SchemaWriter.generate_all!
79
105
  RUBY
80
106
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiRuby
4
- VERSION = "3.4.0"
4
+ VERSION = "3.5.1"
5
5
  end
data/lib/openapi_ruby.rb CHANGED
@@ -27,6 +27,22 @@ module OpenapiRuby
27
27
  def reset_configuration!
28
28
  @configuration = Configuration.new
29
29
  end
30
+
31
+ # True when the current process was started by `openapi_ruby:generate`
32
+ # (the rake task sets OPENAPI_RUBY_GENERATING=true in the subprocess).
33
+ #
34
+ # Useful in consumer test helpers to guard test-framework requires
35
+ # that conflict when both `rspec/rails` and `rails/test_help` load
36
+ # in the same process (the FRAMEWORK=hybrid case):
37
+ #
38
+ # # test/test_helper.rb
39
+ # unless OpenapiRuby.schema_generating?
40
+ # require "rails/test_help"
41
+ # # ...other test-time setup...
42
+ # end
43
+ def schema_generating?
44
+ ENV["OPENAPI_RUBY_GENERATING"] == "true"
45
+ end
30
46
  end
31
47
  end
32
48
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.0
4
+ version: 3.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten Hartvig