Module: Minitest::OpenAPI
- Defined in:
- lib/minitest/openapi.rb,
lib/minitest/openapi/dsl.rb,
lib/minitest/openapi/spec.rb,
lib/minitest/openapi/railtie.rb,
lib/minitest/openapi/version.rb,
lib/minitest/openapi/document.rb,
lib/minitest/openapi/recorder.rb,
lib/minitest/openapi/validator.rb,
lib/minitest/openapi/configuration.rb
Overview
Generates an OpenAPI 3.0 document from minitest API tests. Tests declare each operation and its response schema; the live response is validated against that schema as the suite runs; ‘openapi:generate` writes the doc.
Defined Under Namespace
Modules: DSL, Recorder, Spec Classes: Configuration, Document, Error, Railtie, Validator
Constant Summary collapse
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.components ⇒ Object
Component schemas available for $ref resolution during validation.
- .configuration ⇒ Object
- .configure {|configuration| ... } ⇒ Object
-
.document ⇒ Object
The document being assembled this run.
-
.generate!(path = nil) ⇒ Object
Writes the assembled document.
-
.reset! ⇒ Object
Drops the accumulated document (used between isolated test runs).
-
.resolve_path(path) ⇒ Object
Resolves a path relative to Rails.root when available, else the cwd.
Class Method Details
.components ⇒ Object
Component schemas available for $ref resolution during validation.
41 42 43 |
# File 'lib/minitest/openapi.rb', line 41 def components document.components end |
.configuration ⇒ Object
27 28 29 |
# File 'lib/minitest/openapi.rb', line 27 def configuration @configuration ||= Configuration.new end |
.configure {|configuration| ... } ⇒ Object
31 32 33 |
# File 'lib/minitest/openapi.rb', line 31 def configure yield configuration end |
.document ⇒ Object
The document being assembled this run.
36 37 38 |
# File 'lib/minitest/openapi.rb', line 36 def document @document ||= Document.new(configuration.base_document) end |
.generate!(path = nil) ⇒ Object
Writes the assembled document. Returns the absolute path written.
51 52 53 54 55 56 |
# File 'lib/minitest/openapi.rb', line 51 def generate!(path = nil) target = resolve_path(path || configuration.output_path) FileUtils.mkdir_p(File.dirname(target)) File.write(target, "#{JSON.pretty_generate(document.to_h)}\n") target end |
.reset! ⇒ Object
Drops the accumulated document (used between isolated test runs).
46 47 48 |
# File 'lib/minitest/openapi.rb', line 46 def reset! @document = nil end |
.resolve_path(path) ⇒ Object
Resolves a path relative to Rails.root when available, else the cwd.
59 60 61 62 63 64 |
# File 'lib/minitest/openapi.rb', line 59 def resolve_path(path) return path.to_s if Pathname.new(path).absolute? root = defined?(Rails) && Rails.respond_to?(:root) && Rails.root File.join((root || Dir.pwd).to_s, path) end |