Skip to content

Validation error messge for dependentRequired #213

@ahx

Description

@ahx

Given I have a validation like this:

validation = JSONSchemer.schema({ 'dependentRequired' => { 'id' => ['type'] } }).validate({ 'id' => '2' }).to_a

This currently returns an error object like this:

[{"data" => {"id" => "2"},
  "data_pointer" => "/id",
  "schema" => {"dependentRequired" => {"id" => ["type"]}},
  "schema_pointer" => "",
  "root_schema" => {"dependentRequired" => {"id" => ["type"]}},
  "type" => "dependentRequired",
  "error" =>
   "object at `/id` is missing required `dependentRequired` properties"}]

One problem I see with this is the error message. "object at /id is missing required dependentRequired properties" is kind not correct, because the property is missing at root ('/') and no inside the id value.

Another thing I think would be great to have is added details about what keys are missing.
Maybe something like:

[{"data" => {"id" => "2"},
  "data_pointer" => "/id",
  "schema" => {"dependentRequired" => {"id" => ["type"]}},
  "schema_pointer" => "",
  "root_schema" => {"dependentRequired" => {"id" => ["type"]}},
  "type" => "dependentRequired",
  "details" => { "missing_keys": ["type"] },
  "error" =>
   "object at root is missing required properties: type"}]

If you think something like that would be feasible I can try to work on a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions