Module: OpenapiRuby::Adapters::RSpec
- Defined in:
- lib/openapi_ruby/adapters/rspec.rb
Defined Under Namespace
Modules: ExampleGroupHelpers, ExampleHelpers
Class Method Summary collapse
- .install! ⇒ Object
-
.validation_document_for(schema_name) ⇒ Object
Build the OpenAPI document hash for a given schema name and cache it.
Class Method Details
.install! ⇒ Object
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 |
# File 'lib/openapi_ruby/adapters/rspec.rb', line 309 def self.install! ::RSpec.configure do |config| config.extend ExampleGroupHelpers, type: :openapi config.include ExampleHelpers, type: :openapi if defined?(::RSpec::Rails) config.include ::RSpec::Rails::RequestExampleGroup, type: :openapi end # Schema writing is handled by the rake task (openapi_ruby:generate), # not by test runs. The rake task loads spec files to register DSL # contexts, then calls SchemaWriter.generate_all! directly. # This prevents partial schema overwrites when running a subset of specs. end end |
.validation_document_for(schema_name) ⇒ Object
Build the OpenAPI document hash for a given schema name and cache it. Used by response body validation so $ref schemas can be resolved.
288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/openapi_ruby/adapters/rspec.rb', line 288 def self.validation_document_for(schema_name) return nil unless schema_name key = schema_name.to_sym @validation_documents ||= {} @validation_documents[key] ||= begin config = OpenapiRuby.configuration schema_config = config.schemas[key] || config.schemas[schema_name.to_s] return nil unless schema_config builder = OpenapiRuby::Core::DocumentBuilder.new(schema_config) OpenapiRuby::DSL::MetadataStore.contexts_for(schema_name).each do |context| builder.add_path(context.path_template, context.to_openapi) end scope = schema_config[:component_scope] loader = OpenapiRuby::Components::Loader.new(scope: scope) builder.merge_components(loader.to_openapi_hash) builder.build.data end end |