Class: Committee::SchemaValidator::OpenAPI3::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/committee/schema_validator/open_api_3/router.rb

Instance Method Summary collapse

Constructor Details

#initialize(schema, validator_option) ⇒ Router

Returns a new instance of Router.

Parameters:



8
9
10
11
12
# File 'lib/committee/schema_validator/open_api_3/router.rb', line 8

def initialize(schema, validator_option)
  @schema = schema
  @prefix_regexp = ::Committee::SchemaValidator.build_prefix_regexp(validator_option.prefix)
  @validator_option = validator_option
end

Instance Method Details

#build_schema_validator(request) ⇒ Object



20
21
22
# File 'lib/committee/schema_validator/open_api_3/router.rb', line 20

def build_schema_validator(request)
  Committee::SchemaValidator::OpenAPI3.new(self, request, @validator_option)
end

#includes_request?(request) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/committee/schema_validator/open_api_3/router.rb', line 14

def includes_request?(request)
  return true unless @prefix_regexp

  prefix_request?(request)
end

#operation_object(request) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/committee/schema_validator/open_api_3/router.rb', line 24

def operation_object(request)
  return nil unless includes_request?(request)

  path = request.path
  path = path.gsub(@prefix_regexp, '') if @prefix_regexp

  request_method = request.request_method.downcase

  @schema.operation_object(path, request_method)
end