Class: Coradoc::Validation::SchemaGenerator
- Inherits:
-
Object
- Object
- Coradoc::Validation::SchemaGenerator
- Defined in:
- lib/coradoc/validation.rb
Overview
Schema generator from CoreModel types
Automatically generates validation schemas from Lutaml::Model classes. This enables automatic validation based on model structure.
Class Method Summary collapse
-
.generate(model_class, required: [], ignored: [], custom_rules: {}) ⇒ Schema
Generate a validation schema from a CoreModel class.
-
.map_type(type) ⇒ Class+
Map Lutaml::Model type to Ruby class.
Class Method Details
.generate(model_class, required: [], ignored: [], custom_rules: {}) ⇒ Schema
Generate a validation schema from a CoreModel class
500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/coradoc/validation.rb', line 500 def generate(model_class, required: [], ignored: [], custom_rules: {}) return nil unless model_class.is_a?(Class) && model_class < CoreModel::Base # Pre-compute attribute definitions before the schema block attribute_defs = compute_attribute_definitions( model_class, required, ignored, custom_rules ) Schema.define do attribute_defs.each do |name, type, , is_required| if is_required required name, type: type, ** else optional name, type: type, ** end end end end |
.map_type(type) ⇒ Class+
Map Lutaml::Model type to Ruby class
523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 |
# File 'lib/coradoc/validation.rb', line 523 def map_type(type) # Handle Lutaml::Model type classes by name type_name = type.to_s case type_name when 'Lutaml::Model::Type::String' String when 'Lutaml::Model::Type::Integer' Integer when 'Lutaml::Model::Type::Float' Float when 'Lutaml::Model::Type::Boolean' [TrueClass, FalseClass] when 'Lutaml::Model::Type::Date' Date when 'Lutaml::Model::Type::Time' Time when 'Lutaml::Model::Type::DateTime' Time when 'Lutaml::Model::Type::Hash' Hash when 'Lutaml::Model::Type::Array' Array else # For non-Lutaml types (like CoreModel::Base), return the type itself type.is_a?(Class) ? type : Object end end |