-
Notifications
You must be signed in to change notification settings - Fork 63
Description
I m using the gem to validation the jsonb field config in my model RegistrationForm :
class RegistrationForm < ApplicationRecord
CONFIG_JSON_SCHEMA = Rails.root.join('config', 'schemas', 'registration_forms', 'config.json')
validates :config, presence: true, json: { message: ->(errors) { errors }, schema: CONFIG_JSON_SCHEMA } # `schema: :dynamic_profile_schema` would also work
end
It works well. However as mentioned in the README, you should be able to render errors in a human-readable format array by specifying a proc as the value of the message key.
However this is what I am getting back running registration_form.errors.full_messages
on an invalid registration_form :
registration_form.errors.full_messages
["Config {\"data\"=>{\"name\"=>\"name\", \"label\"=>\"random label\"}, \"data_pointer\"=>\"/0\", \"schema\"=>{\"type\"=>\"object\", \"default\"=>{}, \"title\"=>\"Schema for item\", \"required\"=>[\"label\", \"kind\", \"name\"], \"properties\"=>{\"label\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The label Schema\", \"minLength\"=>1, \"examples\"=>[\"My label\"]}, \"kind\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The kind Schema\", \"enum\"=>[\"text\", \"number\", \"select\"], \"examples\"=>[\"text\"]}, \"name\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The name Schema\", \"minLength\"=>1, \"examples\"=>[\"My name\"]}, \"value\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The value Schema\", \"examples\"=>[\"My value\"]}, \"options\"=>{\"type\"=>\"object\", \"default\"=>{}, \"title\"=>\"The options Schema\", \"required\"=>[], \"properties\"=>{}, \"examples\"=>[{}]}}, \"examples\"=>[{\"label\"=>\"My label\", \"kind\"=>\"text\", \"name\"=>\"My name\", \"value\"=>\"My value\", \"options\"=>{}}]}, \"schema_pointer\"=>\"/items\", \"root_schema\"=>{\"type\"=>\"array\", \"default\"=>[], \"title\"=>\"Root Schema\", \"items\"=>{\"type\"=>\"object\", \"default\"=>{}, \"title\"=>\"Schema for item\", \"required\"=>[\"label\", \"kind\", \"name\"], \"properties\"=>{\"label\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The label Schema\", \"minLength\"=>1, \"examples\"=>[\"My label\"]}, \"kind\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The kind Schema\", \"enum\"=>[\"text\", \"number\", \"select\"], \"examples\"=>[\"text\"]}, \"name\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The name Schema\", \"minLength\"=>1, \"examples\"=>[\"My name\"]}, \"value\"=>{\"type\"=>\"string\", \"default\"=>\"\", \"title\"=>\"The value Schema\", \"examples\"=>[\"My value\"]}, \"options\"=>{\"type\"=>\"object\", \"default\"=>{}, \"title\"=>\"The options Schema\", \"required\"=>[], \"properties\"=>{}, \"examples\"=>[{}]}}, \"examples\"=>[{\"label\"=>\"My label\", \"kind\"=>\"text\", \"name\"=>\"My name\", \"value\"=>\"My value\", \"options\"=>{}}]}, \"examples\"=>[[{\"label\"=>\"My label\", \"kind\"=>\"text\", \"name\"=>\"My name\", \"value\"=>\"My value\", \"options\"=>{}}]], \"$id\"=>\"file:///Users/davidgeismar/code/360_ecommerce_solution/360-saas-multitenant/config/schemas/registration_forms/config.json\"}, \"type\"=>\"required\", \"details\"=>{\"missing_keys\"=>[\"kind\"]}}"]
This seems quite far from the human readable messages in the README.
What is going on here ?
My json schema (type array) :
{
"type": "array",
"default": [],
"title": "Root Schema",
"items": {
"type": "object",
"default": {},
"title": "Schema for item",
"required": [
"label",
"kind",
"name"
],
"properties": {
"label": {
"type": "string",
"default": "",
"title": "The label Schema",
"minLength": 1,
"examples": [
"My label"
]
},
"kind": {
"type": "string",
"default": "",
"title": "The kind Schema",
"enum": ["text", "number", "select"],
"examples": [
"text"
]
},
"name": {
"type": "string",
"default": "",
"title": "The name Schema",
"minLength": 1,
"examples": [
"My name"
]
},
"value": {
"type": "string",
"default": "",
"title": "The value Schema",
"examples": [
"My value"
]
},
"options": {
"type": "object",
"default": {},
"title": "The options Schema",
"required": [],
"properties": {},
"examples": [{}]
}
},
"examples": [{
"label": "My label",
"kind": "text",
"name": "My name",
"value": "My value",
"options": {}
}]
},
"examples": [
[{
"label": "My label",
"kind": "text",
"name": "My name",
"value": "My value",
"options": {}
}]
]
}