Class: Ukiryu::SchemaValidator
- Inherits:
-
Object
- Object
- Ukiryu::SchemaValidator
- Defined in:
- lib/ukiryu/schema_validator.rb
Overview
Schema validator for YAML tool profiles
Validates tool profile YAML files against JSON Schema definitions.
Class Method Summary collapse
-
.default_schema_path ⇒ String?
Get the default schema path.
-
.load_schema(path = nil) ⇒ Hash
Load and parse the JSON schema.
-
.validate_profile(profile, options = {}) ⇒ Array<String>
Validate a tool profile against the schema.
Class Method Details
.default_schema_path ⇒ String?
Get the default schema path
77 78 79 80 |
# File 'lib/ukiryu/schema_validator.rb', line 77 def default_schema_path # Check environment variable for schema path ENV['UKIRYU_SCHEMA_PATH'] end |
.load_schema(path = nil) ⇒ Hash
Load and parse the JSON schema
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ukiryu/schema_validator.rb', line 62 def load_schema(path = nil) schema_path = path || default_schema_path return nil unless schema_path && File.exist?(schema_path) schema_content = File.read(schema_path) parsed = YAML.safe_load(schema_content) # Convert YAML schema to JSON schema format # YAML schema uses $schema, definitions, etc. convert_yaml_schema_to_json(parsed) end |
.validate_profile(profile, options = {}) ⇒ Array<String>
Validate a tool profile against the schema
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ukiryu/schema_validator.rb', line 27 def validate_profile(profile, = {}) # Check if json-schema gem is available return ["json-schema gem not installed. Add 'json-schema' to Gemfile for schema validation."] unless defined?(JSON::Validator) errors = [] # Load the schema schema = load_schema([:schema_path]) return ['Failed to load schema'] unless schema # Convert symbol keys to strings for JSON Schema validation # JSON Schema validators expect string keys, but YAML.safe_load produces symbol keys stringified_profile = stringify_keys(profile) # Validate against JSON schema begin # JSON Schema library expects the data to be a hash validation_errors = JSON::Validator.fully_validate(schema, stringified_profile, strict: [:strict] || false) # Convert errors to readable format validation_errors.each do |error| errors << format_schema_error(error) end rescue JSON::Schema::ValidationError => e errors << "Schema validation error: #{e.}" end errors end |