Class: OpenapiRuby::Configuration

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/openapi_ruby/configuration.rb', line 51

def initialize
  @schemas = {}
  @component_paths = ["app/api_components"]
  @component_scope_paths = {}
  @camelize_keys = true
  @request_validation = :disabled
  @response_validation = :disabled
  @coerce_params = true
  @test_request_validation = true
  @single_api_path_per_class = false
  @schema_output_dir = "openapi"
  @schema_output_format = :yaml
  @ui_enabled = false
  @ui_config = {}
  @strict_reference_validation = :warn_only
  @auto_validation_error_response = true
  @validation_error_schema = nil
end

Instance Attribute Details

#auto_validation_error_responseObject

Returns the value of attribute auto_validation_error_response.



15
16
17
# File 'lib/openapi_ruby/configuration.rb', line 15

def auto_validation_error_response
  @auto_validation_error_response
end

#camelize_keysObject

Output / formatting



14
15
16
# File 'lib/openapi_ruby/configuration.rb', line 14

def camelize_keys
  @camelize_keys
end

#coerce_paramsObject

Middleware (runtime validation)



19
20
21
# File 'lib/openapi_ruby/configuration.rb', line 19

def coerce_params
  @coerce_params
end

#component_pathsObject

Components



10
11
12
# File 'lib/openapi_ruby/configuration.rb', line 10

def component_paths
  @component_paths
end

#component_scope_pathsObject

Returns the value of attribute component_scope_paths.



11
12
13
# File 'lib/openapi_ruby/configuration.rb', line 11

def component_scope_paths
  @component_scope_paths
end

#request_validationObject

Middleware (runtime validation)



19
20
21
# File 'lib/openapi_ruby/configuration.rb', line 19

def request_validation
  @request_validation
end

#response_validationObject

Middleware (runtime validation)



19
20
21
# File 'lib/openapi_ruby/configuration.rb', line 19

def response_validation
  @response_validation
end

#schema_output_dirObject

Output / formatting



14
15
16
# File 'lib/openapi_ruby/configuration.rb', line 14

def schema_output_dir
  @schema_output_dir
end

#schema_output_formatObject

Output / formatting



14
15
16
# File 'lib/openapi_ruby/configuration.rb', line 14

def schema_output_format
  @schema_output_format
end

#schemasObject

Schema definitions — supports multiple schemas (e.g. public_api, admin_api) Each key maps to a hash with :info, :servers, :component_scope, :strict_mode, etc.



7
8
9
# File 'lib/openapi_ruby/configuration.rb', line 7

def schemas
  @schemas
end

#single_api_path_per_classObject

Style 2 only: require each test class to declare a single api_path. Off by default — resolution handles more than one path per class, so this is for suites that want the convention enforced anyway. See Adapters::ContextResolution for how a request is matched.



25
26
27
# File 'lib/openapi_ruby/configuration.rb', line 25

def single_api_path_per_class
  @single_api_path_per_class
end

#strict_reference_validationObject

OpenAPI meta-schema validation of generated specs and middleware-loaded documents. One of :disabled, :enabled (raise on errors), :warn_only (default, log warnings). Boolean values are accepted for backwards compatibility: true → :warn_only, false → :disabled.



35
36
37
# File 'lib/openapi_ruby/configuration.rb', line 35

def strict_reference_validation
  @strict_reference_validation
end

#test_request_validationObject

Test DSL: validate that requests match the declared operation before sending. Enabled by default; set to false to disable.



29
30
31
# File 'lib/openapi_ruby/configuration.rb', line 29

def test_request_validation
  @test_request_validation
end

#ui_configObject

UI (optional)



49
50
51
# File 'lib/openapi_ruby/configuration.rb', line 49

def ui_config
  @ui_config
end

#ui_enabledObject

UI (optional)



49
50
51
# File 'lib/openapi_ruby/configuration.rb', line 49

def ui_enabled
  @ui_enabled
end

#validation_error_schemaObject

Returns the value of attribute validation_error_schema.



16
17
18
# File 'lib/openapi_ruby/configuration.rb', line 16

def validation_error_schema
  @validation_error_schema
end

Instance Method Details

#validate!Object

Raises:



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/openapi_ruby/configuration.rb', line 70

def validate!
  unless %i[disabled enabled warn_only].include?(@request_validation)
    raise ConfigurationError, "request_validation must be :disabled, :enabled, or :warn_only"
  end

  unless %i[disabled enabled warn_only].include?(@response_validation)
    raise ConfigurationError, "response_validation must be :disabled, :enabled, or :warn_only"
  end

  return if %i[yaml json].include?(@schema_output_format)

  raise ConfigurationError, "schema_output_format must be :yaml or :json"
end