openapi-ruby 3.0.0 → 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: d33ec2601c1341f8afb455e3b2f0f1daa594aa96ddf3daebb8b6c6675a1f3723
4
- data.tar.gz: 44827b7a0f446ed51c1de676b8e777437ccfe8408b7166b731f1b55842b96fb2
3
+ metadata.gz: c80ade10ad457a2ce7b09f51f788c9bad884da32e462071349a3a3cac7627573
4
+ data.tar.gz: f26291466286fe326b0aa0e4223d50e6e6f4864c85d0cfec10e0f53cde8689a9
5
5
  SHA512:
6
- metadata.gz: 5d52dce6834c33e78cd9b8666291b35c289da0981eba2cadfad5c48b10d63a45c65a8d7e959dc09438ec64b9883e0a15ccea96af1c955892901096e0f1172075
7
- data.tar.gz: 6c99f505c721c19bc5be989f4d6d0b0e4a5f7dfe794d688286040b89fd5146dc3aa73ef1c2fbe65fc418785644686bf4d65bf23c98185ddc5814e244f8d1b7b0
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
 
@@ -63,7 +63,7 @@ module OpenapiRuby
63
63
  expanded = File.expand_path(path)
64
64
  next unless Dir.exist?(expanded)
65
65
 
66
- Dir.glob(File.join(expanded, "**/")).each do |dir_path|
66
+ Dir.glob(File.join(expanded, "**/")).sort.each do |dir_path|
67
67
  relative = dir_path.sub("#{expanded}/", "").chomp("/")
68
68
  next if relative.empty?
69
69
 
@@ -111,6 +111,9 @@ module OpenapiRuby
111
111
  end
112
112
  result.delete(type_key) if result[type_key].empty?
113
113
  end
114
+ # Sort component names alphabetically within each type for deterministic output
115
+ # regardless of file system ordering or load order.
116
+ result.each { |type_key, entries| result[type_key] = entries.sort_by { |k, _| k }.to_h }
114
117
  result
115
118
  end
116
119
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiRuby
4
- VERSION = "3.0.0"
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).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).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.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Morten Hartvig