Class: OpenapiFirst::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_first/configuration.rb

Overview

Global configuration. Currently only used for the request validation middleware.

Direct Known Subclasses

ChildConfiguration

Constant Summary collapse

HOOKS =
%i[
  before_request_validation
  after_request_validation
  after_response_validation
  after_request_parameter_property_validation
  after_request_body_property_validation
  after_response_body_property_validation
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



15
16
17
18
19
20
21
# File 'lib/openapi_first/configuration.rb', line 15

def initialize
  @request_validation_error_response = OpenapiFirst.find_error_response(:default)
  @request_validation_raise_error = false
  @response_validation_raise_error = true
  @hooks = HOOKS.to_h { [_1, Set.new] }
  @path = nil
end

Instance Attribute Details

#hooksObject (readonly)

Returns the value of attribute hooks.



27
28
29
# File 'lib/openapi_first/configuration.rb', line 27

def hooks
  @hooks
end

#pathObject

Returns the value of attribute path.



28
29
30
# File 'lib/openapi_first/configuration.rb', line 28

def path
  @path
end

#request_validation_error_responseObject

Returns the value of attribute request_validation_error_response.



27
28
29
# File 'lib/openapi_first/configuration.rb', line 27

def request_validation_error_response
  @request_validation_error_response
end

#request_validation_raise_errorObject

Deprecated.


31
32
33
# File 'lib/openapi_first/configuration.rb', line 31

def request_validation_raise_error
  @request_validation_raise_error
end

#response_validation_raise_errorObject

Deprecated.


33
34
35
# File 'lib/openapi_first/configuration.rb', line 33

def response_validation_raise_error
  @response_validation_raise_error
end

Instance Method Details

#childObject

Return a child configuration that still receives updates of global hooks.



36
37
38
# File 'lib/openapi_first/configuration.rb', line 36

def child
  ChildConfiguration.new(parent: self)
end

#plugin(name) ⇒ Object



70
71
72
73
# File 'lib/openapi_first/configuration.rb', line 70

def plugin(name, **)
  require_relative 'plugins'
  Plugins.load(name).configure(self, **)
end

#register(path_or_definition, as: :default) ⇒ Object



23
24
25
# File 'lib/openapi_first/configuration.rb', line 23

def register(path_or_definition, as: :default)
  OpenapiFirst.register(path_or_definition, as:)
end