Exception: Udb::TopLevelDatabaseObject::SchemaValidationError
- Inherits:
-
StandardError
- Object
- StandardError
- Udb::TopLevelDatabaseObject::SchemaValidationError
- Defined in:
- lib/udb/obj/database_obj.rb
Overview
exception raised when an object does not validate against its schema
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
result from JsonSchemer.validate.
Instance Method Summary collapse
-
#initialize(path, result) ⇒ SchemaValidationError
constructor
create a new SchemaValidationError.
Constructor Details
#initialize(path, result) ⇒ SchemaValidationError
create a new SchemaValidationError
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 |
# File 'lib/udb/obj/database_obj.rb', line 328 def initialize(path, result) msg = "While validating #{path}:\n\n" nerrors = result.count msg << "#{nerrors} error(s) during validations\n\n" result.to_a.each do |r| msg << if r["type"] == "required" && !r.dig("details", "missing_keys").nil? " At '#{r['data_pointer']}': Missing required parameter(s) '#{r['details']['missing_keys']}'\n" elsif r["type"] == "schema" if r["schema_pointer"] == "/additionalProperties" " At #{r['data_pointer']}, there is an unallowed additional key\n" else " At #{r['data_pointer']}, endpoint is an invalid key\n" end elsif r["type"] == "enum" " At #{r['data_pointer']}, '#{r['data']}' is not a valid enum value (#{r['schema']['enum']})\n" elsif r["type"] == "maxProperties" " Maximum number of properties exceeded\n" elsif r["type"] == "object" " At #{r['data_pointer']}, Expecting object, got #{r['data']}\n" elsif r["type"] == "pattern" " At #{r['data_pointer']}, RegEx validation failed; '#{r['data']}' does not match '#{r['schema']['pattern']}'\n" elsif r["type"] == "integer" " At #{r['data_pointer']}, '#{r['data']}' is not a integer\n" elsif r["type"] == "array" " At #{r['data_pointer']}, '#{r['data']}' is not a array\n" elsif r["type"] == "oneOf" " At #{r['data_pointer']}, '#{r['data']}' matches more than one of #{r['schema']['oneOf']}\n" elsif r["type"] == "const" " At #{r['data_pointer']}, '#{r['data']}' does not match required value '#{r['schema']['const']}'\n" else " #{r}\n\n" end end msg << "\n" # msg << result.to_a.to_s super(msg) @result = result end |
Instance Attribute Details
#result ⇒ Object (readonly)
result from JsonSchemer.validate
323 324 325 |
# File 'lib/udb/obj/database_obj.rb', line 323 def result @result end |