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
540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 |
# File 'lib/coradoc/validation.rb', line 540 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
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
# File 'lib/coradoc/validation.rb', line 563 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 |