Class: Verquest::Configuration
- Inherits:
-
Object
- Object
- Verquest::Configuration
- Includes:
- Base::HelperClassMethods
- Defined in:
- lib/verquest/configuration.rb
Overview
Configuration for the Verquest gem
This class manages configuration settings for the Verquest gem, including validation behavior, JSON Schema version, and version resolution strategy. It’s used to customize the behavior of versioned API requests.
Constant Summary collapse
- SCHEMAS =
Mapping of supported JSON Schema versions to their implementation classes
This constant maps the symbolic names of JSON Schema versions to their corresponding JSONSchemer implementation classes. These are used for schema validation and generation based on the configured schema version.
{ draft4: JSONSchemer::Draft4, draft6: JSONSchemer::Draft6, draft7: JSONSchemer::Draft7, draft2019_09: JSONSchemer::Draft201909, draft2020_12: JSONSchemer::Draft202012, openapi30: JSONSchemer::OpenAPI30, openapi31: JSONSchemer::OpenAPI31 }.freeze
Instance Attribute Summary collapse
-
#current_version ⇒ #call
A callable object that returns the current API version to use when not explicitly specified.
-
#custom_field_types ⇒ Object
Returns the value of attribute custom_field_types.
-
#default_additional_properties ⇒ Boolean
Controls the default behavior for handling properties not defined in the schema.
-
#insert_property_defaults ⇒ Boolean
Controls whether default values defined in property schemas should be inserted when not provided during validation.
-
#json_schema_version ⇒ Symbol
The JSON Schema draft version to use for validation and schema generation (see Configuration::SCHEMAS).
-
#remove_extra_root_keys ⇒ Boolean
Controls if extra root keys not defined in the schema should be removed from the parameters.
-
#validate_params ⇒ Boolean
Controls whether parameters are automatically validated against the schema.
-
#validation_error_handling ⇒ Symbol
Controls how errors during parameter processing are handled.
-
#version_resolver ⇒ #call
The resolver used to map version strings/identifiers to version objects.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
Initialize a new Configuration with default values.
-
#json_schema ⇒ Class
Gets the JSON Schema class based on the configured version.
-
#json_schema_uri ⇒ String
Gets the JSON Schema URI for the configured schema version.
Methods included from Base::HelperClassMethods
Constructor Details
#initialize ⇒ Configuration
Initialize a new Configuration with default values
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/verquest/configuration.rb', line 78 def initialize @validate_params = true @json_schema_version = :draft2020_12 @validation_error_handling = :raise @remove_extra_root_keys = true @version_resolver = VersionResolver @insert_property_defaults = true @custom_field_types = {} @default_additional_properties = false end |
Instance Attribute Details
#current_version ⇒ #call
A callable object that returns the current API version to use when not explicitly specified
73 74 75 |
# File 'lib/verquest/configuration.rb', line 73 def current_version @current_version end |
#custom_field_types ⇒ Object
Returns the value of attribute custom_field_types.
73 |
# File 'lib/verquest/configuration.rb', line 73 attr_reader :current_version, :version_resolver, :custom_field_types |
#default_additional_properties ⇒ Boolean
Controls the default behavior for handling properties not defined in the schema
59 60 |
# File 'lib/verquest/configuration.rb', line 59 attr_accessor :validate_params, :json_schema_version, :validation_error_handling, :remove_extra_root_keys, :insert_property_defaults, :default_additional_properties |
#insert_property_defaults ⇒ Boolean
Controls whether default values defined in property schemas should be inserted when not provided during validation
59 60 |
# File 'lib/verquest/configuration.rb', line 59 attr_accessor :validate_params, :json_schema_version, :validation_error_handling, :remove_extra_root_keys, :insert_property_defaults, :default_additional_properties |
#json_schema_version ⇒ Symbol
The JSON Schema draft version to use for validation and schema generation (see Configuration::SCHEMAS)
59 60 |
# File 'lib/verquest/configuration.rb', line 59 attr_accessor :validate_params, :json_schema_version, :validation_error_handling, :remove_extra_root_keys, :insert_property_defaults, :default_additional_properties |
#remove_extra_root_keys ⇒ Boolean
Controls if extra root keys not defined in the schema should be removed from the parameters
59 60 |
# File 'lib/verquest/configuration.rb', line 59 attr_accessor :validate_params, :json_schema_version, :validation_error_handling, :remove_extra_root_keys, :insert_property_defaults, :default_additional_properties |
#validate_params ⇒ Boolean
Controls whether parameters are automatically validated against the schema
59 60 61 |
# File 'lib/verquest/configuration.rb', line 59 def validate_params @validate_params end |
#validation_error_handling ⇒ Symbol
Controls how errors during parameter processing are handled
59 60 |
# File 'lib/verquest/configuration.rb', line 59 attr_accessor :validate_params, :json_schema_version, :validation_error_handling, :remove_extra_root_keys, :insert_property_defaults, :default_additional_properties |
#version_resolver ⇒ #call
The resolver used to map version strings/identifiers to version objects
73 |
# File 'lib/verquest/configuration.rb', line 73 attr_reader :current_version, :version_resolver, :custom_field_types |
Instance Method Details
#json_schema ⇒ Class
Gets the JSON Schema class based on the configured version
148 149 150 |
# File 'lib/verquest/configuration.rb', line 148 def json_schema SCHEMAS[json_schema_version] || raise(ArgumentError, "Unsupported JSON Schema version: #{json_schema_version}") end |
#json_schema_uri ⇒ String
Gets the JSON Schema URI for the configured schema version
155 156 157 |
# File 'lib/verquest/configuration.rb', line 155 def json_schema_uri json_schema::BASE_URI.to_s end |