openapi-ruby 3.0.1 → 3.0.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: 6058ecc135b267a8e6ad7591b38df8c8e18c983fb961e0cad545e4169158ffb8
4
- data.tar.gz: f3b392baaf7681017db2e477ede7a14f1d0442882d7c97caba1da17c6fc841e2
3
+ metadata.gz: c80ade10ad457a2ce7b09f51f788c9bad884da32e462071349a3a3cac7627573
4
+ data.tar.gz: f26291466286fe326b0aa0e4223d50e6e6f4864c85d0cfec10e0f53cde8689a9
5
5
  SHA512:
6
- metadata.gz: d28688dc74dc40701c1a1ad8a557b467c7c8b0f6537b6c2ae471123d056b5196128be20c13482f6d702db1685f32a76ac9e0b6bca569f5e664b036bfd3e683bf
7
- data.tar.gz: c3ed7228acf6b39feec3c29946cdae5012d236429a877b42a066891a887461ee3bfd07dc6b5edd48409836e1acb573a271571d0db1d582f04d88a9d8ec9bd70a
6
+ metadata.gz: d2fe17e3e72da93b6b50fef93dd2641f2814d1aaf964364d9cf324f1b9562336956b1706d264baf6515f1d9d8ceee07abf830f83c83117594adb5f2806313981
7
+ data.tar.gz: 61780c593073693c446d64f5088d495b0083c246989d5799f97b780945351a8f07aeee3e55d5cf1b87bc5c018e21bb4625029d108aed50a1172db9a54be09f5b
data/README.md CHANGED
@@ -379,9 +379,9 @@ Generate OpenAPI spec files without running tests:
379
379
  rake openapi_ruby:generate
380
380
  ```
381
381
 
382
- This uses RSpec `--dry-run` (or loads Minitest files) to collect API definitions and write schemas. It auto-detects the test framework, or you can set `FRAMEWORK=rspec` or `FRAMEWORK=minitest`. Custom patterns: `PATTERN="packs/*/spec/**/*_spec.rb"`.
382
+ This loads spec/test files to collect API definitions and writes schemas without running any tests. It auto-detects the test framework, or you can set `FRAMEWORK=rspec` or `FRAMEWORK=minitest`. Custom patterns: `PATTERN="packs/*/spec/**/*_spec.rb"`.
383
383
 
384
- Schemas are also generated automatically after running the full test suite via `after(:suite)` / `Minitest.after_run` hooks.
384
+ Schemas are **only** written by the rake task — running tests (`bundle exec rspec`, `rails test`) does not generate or overwrite schema files. This prevents partial schema overwrites when running a subset of specs.
385
385
 
386
386
  ## Runtime Middleware
387
387
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiRuby
4
- VERSION = "3.0.1"
4
+ VERSION = "3.0.2"
5
5
  end
@@ -2,17 +2,18 @@
2
2
 
3
3
  namespace :openapi_ruby do
4
4
  desc "Generate OpenAPI schema files from spec definitions and components"
5
- task generate: :environment do
5
+ task :generate do
6
6
  framework = ENV.fetch("FRAMEWORK", detect_test_framework).to_s
7
+ pattern = ENV.fetch("PATTERN", default_pattern_for(framework))
7
8
 
8
- case framework
9
- when "rspec"
10
- generate_with_rspec
11
- when "minitest"
12
- generate_with_minitest
13
- else
14
- abort "Unknown test framework '#{framework}'. Set FRAMEWORK=rspec or FRAMEWORK=minitest."
15
- end
9
+ # Spawn a subprocess so RAILS_ENV defaults to "test" cleanly,
10
+ # just like rswag did with RSpec::Core::RakeTask.
11
+ env = {"RAILS_ENV" => ENV.fetch("RAILS_ENV", "test")}
12
+ script = generate_script(framework, pattern)
13
+ command = "bundle exec ruby -e #{Shellwords.escape(script)}"
14
+
15
+ puts "Generating OpenAPI schemas (#{framework})..."
16
+ system(env, command) || abort("Schema generation failed")
16
17
  end
17
18
  end
18
19
 
@@ -26,43 +27,29 @@ def detect_test_framework
26
27
  end
27
28
  end
28
29
 
29
- def generate_with_rspec
30
- pattern = ENV.fetch("PATTERN", "spec/**/*_spec.rb")
31
- puts "Generating OpenAPI schemas (RSpec)..."
32
-
33
- # Load rspec-core first — normally RSpec's runner does this before spec_helper,
34
- # but since we're loading specs via require we need it explicitly.
35
- require "rspec/core"
36
-
37
- # Add spec/ to the load path so require "openapi_helper" / "rails_helper" works,
38
- # matching what RSpec does when it runs.
39
- $LOAD_PATH.unshift(File.expand_path("spec")) unless $LOAD_PATH.include?(File.expand_path("spec"))
40
-
41
- # Load all spec files to trigger DSL context registrations.
42
- # RSpec's describe/context blocks are evaluated at load time,
43
- # so requiring the files registers paths and operations without
44
- # running any tests. Spec files pull in RSpec and the openapi_ruby
45
- # adapter via their own require chains (e.g. require "openapi_helper").
46
- pattern.split(",").each do |p|
47
- Dir.glob(p.strip).sort.each { |f| require File.expand_path(f) }
30
+ def default_pattern_for(framework)
31
+ case framework
32
+ when "rspec" then "spec/**/*_spec.rb"
33
+ when "minitest" then "test/**/*_test.rb"
48
34
  end
49
-
50
- # Generate schemas from the registered contexts
51
- OpenapiRuby::Generator::SchemaWriter.generate_all!
52
35
  end
53
36
 
54
- def generate_with_minitest
55
- pattern = ENV.fetch("PATTERN", "test/**/*_test.rb")
56
- puts "Generating OpenAPI schemas (Minitest)..."
57
-
58
- # Load Rails environment and minitest adapter
59
- require "openapi_ruby/minitest"
60
-
61
- # Load all test files to trigger api_path registrations.
62
- # Minitest's api_path registers DSL contexts at class load time,
63
- # so simply requiring the files is enough.
64
- Dir.glob(pattern).sort.each { |f| require File.expand_path(f) }
65
-
66
- # Generate schemas from the registered contexts
67
- OpenapiRuby::Generator::SchemaWriter.generate_all!
37
+ def generate_script(framework, pattern)
38
+ case framework
39
+ when "rspec"
40
+ <<~RUBY
41
+ require "rspec/core"
42
+ $LOAD_PATH.unshift(File.expand_path("spec")) unless $LOAD_PATH.include?(File.expand_path("spec"))
43
+ #{pattern.split(",").map { |p| %[Dir.glob(#{p.strip.inspect}).sort.each { |f| require File.expand_path(f) }] }.join("\n")}
44
+ OpenapiRuby::Generator::SchemaWriter.generate_all!
45
+ RUBY
46
+ when "minitest"
47
+ <<~RUBY
48
+ require "openapi_ruby/minitest"
49
+ #{pattern.split(",").map { |p| %[Dir.glob(#{p.strip.inspect}).sort.each { |f| require File.expand_path(f) }] }.join("\n")}
50
+ OpenapiRuby::Generator::SchemaWriter.generate_all!
51
+ RUBY
52
+ else
53
+ abort "Unknown test framework '#{framework}'."
54
+ end
68
55
  end
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.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten Hartvig