Skip to content

No support for multiple error message formats per keyword #802

@anjnerajat

Description

@anjnerajat

Hi @stevehu
Looking for some suggestions around this use-case. Please redirect me to the threads if this has already been discussed.

Say there is a custom keyword defined in a custom meta schema whose validator does multiple kinds of validations and needs more than one message format to be used for showing error for those cases.
Ex: a custom keyword - "isRecordReference". Its validation logic does two things, check existence of the referenced record id and also checks whether referenced record allows being referenced or not (assume that the record can put some limitations on its access)
So now the error message for these two cases can't be same. For former scenario it should be "Record {0} not found" and for later "Record {0} can't be referenced here"

Sample Consuming Schema:

{
	"type": "string",
	"isContentReference": true
}

With the current one on one mapping between a keyword and a message format this cannot be achieved.

One way to achieve this could be to have one to many relationship b/w a keyword and its error codes and then have one message corresponding to each error code. The messages could be fetched based on error code the validator provides while constructing ValidationMessage instead of its keyword name.

Am I thinking in the wrong direction here? Can this library be modified to achieve such use-case? And does this go against any of JSON spec guidelines?
Please let me know your thoughts and thanks for all the help!

fyi @prashanth-chaitanya

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions