openapi-ruby 4.0.2 → 4.0.3
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f4bf806084ec440728b07b1cb5105c2e2f8529852b143a087bb919111afd6498
|
|
4
|
+
data.tar.gz: d73357f612fa69222d354a2f122a496c63bf8d8259ddb15bdfb38c898c7fb335
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ea9f2ab82f0cdae01a6a578daa13f7274914a77b2476ba4ff7bbaf4cfd991ea685c608dcd71eac23bb2bc9ebf0ce35d0ac764b63a89bbb35add7e95c73a9d048
|
|
7
|
+
data.tar.gz: b940f94f696df915e90eccc593ae3901b1bc63229b4158391da62ffddb7fef1932a788358c1bffe771054f3e7d5f68faae36ff549ebb2c1166c078ed8ee58c66
|
data/README.md
CHANGED
|
@@ -473,9 +473,17 @@ Loading a test file normally *is* enough to run it: `rails/test_help` requires `
|
|
|
473
473
|
|
|
474
474
|
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.
|
|
475
475
|
|
|
476
|
+
### No database required
|
|
477
|
+
|
|
478
|
+
The document is built from your declarations, never from the database — but `rails/test_help` verifies the test schema at require time (`maintain_test_schema!`), and many hand-written helpers add `ActiveRecord::Migration.check_all_pending!`. Both open a connection, which would make a database a hard requirement for generating a document that doesn't need one.
|
|
479
|
+
|
|
480
|
+
Generation stubs both out, so `rake openapi_ruby:generate` runs with no database available. Nothing else about your helper changes, and the stubs exist only inside the generation subprocess — normal test runs still verify the schema as usual.
|
|
481
|
+
|
|
482
|
+
Only the schema *check* is skipped. A connection is still available if your declarations genuinely need one (an enum built from a query at load time, say); such a suite needs a database either way.
|
|
483
|
+
|
|
476
484
|
### Making generation cheaper (optional)
|
|
477
485
|
|
|
478
|
-
Generation only needs your `path` / `api_path` declarations to register.
|
|
486
|
+
Generation only needs your `path` / `api_path` declarations to register. Booting the full test framework and loading fixtures is dead weight, and on a large suite it dominates the runtime.
|
|
479
487
|
|
|
480
488
|
Guard that setup with `OpenapiRuby.schema_generating?`, which returns `true` only in the rake task's subprocess (it sets `OPENAPI_RUBY_GENERATING=true`):
|
|
481
489
|
|
|
@@ -489,7 +497,7 @@ require "rails/test_help"
|
|
|
489
497
|
# ...other test-time setup...
|
|
490
498
|
```
|
|
491
499
|
|
|
492
|
-
This is an optimization
|
|
500
|
+
This is purely an optimization — generation is already correct and database-free without it.
|
|
493
501
|
|
|
494
502
|
One caveat if you do guard: skipping `rails/test_help` also means `fixtures` is undefined, so any test file calling `fixtures :all` in its class body fails to *load*. Point `PATTERN` at just the files carrying `api_path` declarations:
|
|
495
503
|
|
|
@@ -42,12 +42,15 @@ module OpenapiRuby
|
|
|
42
42
|
end
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
# Prepended to every generated script
|
|
46
|
-
# must
|
|
45
|
+
# Prepended to every generated script, before any consumer file is
|
|
46
|
+
# required. Loading the consumer's test files must neither run them
|
|
47
|
+
# (AutorunSuppressor) nor drag in a database (TestSchemaSuppressor).
|
|
47
48
|
def suppress_autorun
|
|
48
49
|
<<~RUBY.chomp
|
|
49
50
|
require "openapi_ruby/generator/autorun_suppressor"
|
|
51
|
+
require "openapi_ruby/generator/test_schema_suppressor"
|
|
50
52
|
OpenapiRuby::Generator::AutorunSuppressor.install!
|
|
53
|
+
OpenapiRuby::Generator::TestSchemaSuppressor.install!
|
|
51
54
|
RUBY
|
|
52
55
|
end
|
|
53
56
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module OpenapiRuby
|
|
4
|
+
module Generator
|
|
5
|
+
# Schema generation never runs tests, so keeping the test database's schema
|
|
6
|
+
# current is wasted work — but `rails/test_help` does it unconditionally at
|
|
7
|
+
# require time (`rails/testing/maintain_test_schema` → `maintain_test_schema!`),
|
|
8
|
+
# which opens a database connection. That makes a database a hard
|
|
9
|
+
# requirement for generating a document that doesn't depend on one.
|
|
10
|
+
#
|
|
11
|
+
# `maintain_test_schema!` is a no-op when the setting is off, so turning it
|
|
12
|
+
# off for the generation subprocess drops the requirement.
|
|
13
|
+
#
|
|
14
|
+
# This only skips the schema *check*. A connection is still available if the
|
|
15
|
+
# consumer's declarations genuinely need one (say, an enum built from a
|
|
16
|
+
# query at load time) — such a suite needs a database either way.
|
|
17
|
+
module TestSchemaSuppressor
|
|
18
|
+
module_function
|
|
19
|
+
|
|
20
|
+
def install!
|
|
21
|
+
return unless defined?(::ActiveSupport) && ::ActiveSupport.respond_to?(:on_load)
|
|
22
|
+
|
|
23
|
+
# Registered as a load hook so it applies whenever the consumer's helper
|
|
24
|
+
# boots Rails, rather than depending on require order.
|
|
25
|
+
::ActiveSupport.on_load(:active_record) do
|
|
26
|
+
OpenapiRuby::Generator::TestSchemaSuppressor.disable!
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Neutralises the methods rather than clearing
|
|
31
|
+
# `ActiveRecord.maintain_test_schema`. The flag is reapplied from app
|
|
32
|
+
# config by the `active_record.set_configs` initializer, which runs after
|
|
33
|
+
# any load hook we can register from here — so setting it is silently
|
|
34
|
+
# undone before `rails/test_help` reads it.
|
|
35
|
+
def disable!
|
|
36
|
+
::ActiveRecord::Migration.singleton_class.prepend(MigrationSilencer)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
module MigrationSilencer
|
|
40
|
+
# Called by rails/test_help at require time.
|
|
41
|
+
def maintain_test_schema!
|
|
42
|
+
nil
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Not called by Rails during boot, but a common addition to a
|
|
46
|
+
# hand-written test_helper. Same intent as the above: assert the test
|
|
47
|
+
# database matches the migrations. Nothing is loaded from the database
|
|
48
|
+
# to build the document, so there is nothing to verify.
|
|
49
|
+
def check_all_pending!
|
|
50
|
+
nil
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
data/lib/openapi_ruby/version.rb
CHANGED
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: 4.0.
|
|
4
|
+
version: 4.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Morten Hartvig
|
|
@@ -108,6 +108,7 @@ files:
|
|
|
108
108
|
- lib/openapi_ruby/generator/autorun_suppressor.rb
|
|
109
109
|
- lib/openapi_ruby/generator/rake_task_support.rb
|
|
110
110
|
- lib/openapi_ruby/generator/schema_writer.rb
|
|
111
|
+
- lib/openapi_ruby/generator/test_schema_suppressor.rb
|
|
111
112
|
- lib/openapi_ruby/middleware/coercion.rb
|
|
112
113
|
- lib/openapi_ruby/middleware/error_handler.rb
|
|
113
114
|
- lib/openapi_ruby/middleware/path_matcher.rb
|