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 +4 -4
- data/README.md +2 -2
- data/lib/openapi_ruby/version.rb +1 -1
- data/lib/tasks/openapi_ruby.rake +32 -45
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c80ade10ad457a2ce7b09f51f788c9bad884da32e462071349a3a3cac7627573
|
|
4
|
+
data.tar.gz: f26291466286fe326b0aa0e4223d50e6e6f4864c85d0cfec10e0f53cde8689a9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
|
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
|
|
data/lib/openapi_ruby/version.rb
CHANGED
data/lib/tasks/openapi_ruby.rake
CHANGED
|
@@ -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
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|