Module: EasyTalk::SchemaMethods
- Included in:
- Model::ClassMethods, EasyTalk::Schema::ClassMethods
- Defined in:
- lib/easy_talk/schema_methods.rb
Overview
Note:
Classes including this module must define:
name- The class name (used in ref_template)schema- The built schema hash (used in json_schema)@schema_definition- Instance variable with schema metadata
Shared methods for JSON Schema generation.
This module provides common functionality for building JSON schemas, including $schema and $id resolution. It is included in both EasyTalk::Model and EasyTalk::Schema to avoid code duplication.
Instance Method Summary collapse
-
#json_schema ⇒ Hash
Returns the JSON schema for the model.
-
#ref_template ⇒ String
Returns the reference template for the model.
Instance Method Details
#json_schema ⇒ Hash
Returns the JSON schema for the model. This is the final output that includes the $schema keyword if configured.
34 35 36 |
# File 'lib/easy_talk/schema_methods.rb', line 34 def json_schema @json_schema ||= build_json_schema end |
#ref_template ⇒ String
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.
22 23 24 25 26 27 28 |
# File 'lib/easy_talk/schema_methods.rb', line 22 def ref_template config = EasyTalk.configuration # Use external ref when configured and $id available, otherwise fall back to local $defs schema_id = resolve_schema_id if config.prefer_external_refs schema_id || "#/$defs/#{name}" end |