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
471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/openapi_ruby/adapters/rspec.rb', line 471 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.
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/openapi_ruby/adapters/rspec.rb', line 450 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 |