Module: EasyTalk::SchemaBase::ClassMethods
- Includes:
- EasyTalk::SchemaMethods
- Included in:
- Model::ClassMethods, EasyTalk::Schema::ClassMethods
- Defined in:
- lib/easy_talk/schema_base.rb
Overview
Class methods shared by Schema and Model.
Instance Method Summary collapse
- #additional_properties_allowed? ⇒ Boolean
- #define_schema ⇒ Object
-
#json_schema ⇒ Hash
included
from EasyTalk::SchemaMethods
Returns the JSON schema for the model.
- #properties ⇒ Object
-
#ref_template ⇒ String
included
from EasyTalk::SchemaMethods
Returns the reference template for the model.
- #schema ⇒ Object
- #schema_definition ⇒ Object
Instance Method Details
#additional_properties_allowed? ⇒ Boolean
160 161 162 163 |
# File 'lib/easy_talk/schema_base.rb', line 160 def additional_properties_allowed? ap = @schema_definition&.schema&.fetch(:additional_properties, false) ap == true || ap.is_a?(Class) || ap.is_a?(Hash) end |
#define_schema ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/easy_talk/schema_base.rb', line 141 def define_schema(&) raise ArgumentError, 'The class must have a name' unless name.present? clear_schema_state! @schema_definition = SchemaDefinition.new(name) @schema_definition.klass = self @schema_definition.instance_eval(&) defined_properties = (@schema_definition.schema[:properties] || {}).keys attr_accessor(*defined_properties) @schema_definition end |
#json_schema ⇒ Hash Originally defined in module EasyTalk::SchemaMethods
Returns the JSON schema for the model. This is the final output that includes the $schema keyword if configured.
#properties ⇒ Object
165 166 167 |
# File 'lib/easy_talk/schema_base.rb', line 165 def properties (@schema_definition&.schema&.dig(:properties) || {}).keys end |
#ref_template ⇒ String Originally defined in module EasyTalk::SchemaMethods
Returns the reference template for the model. When prefer_external_refs is enabled and the model has a schema ID, returns the external $id URI. Otherwise, returns the local $defs reference.
#schema ⇒ Object
133 134 135 136 137 138 139 |
# File 'lib/easy_talk/schema_base.rb', line 133 def schema @schema ||= if defined?(@schema_definition) && @schema_definition build_schema(@schema_definition) else {} end end |
#schema_definition ⇒ Object
156 157 158 |
# File 'lib/easy_talk/schema_base.rb', line 156 def schema_definition @schema_definition ||= {} end |