Skip to content

Misleading error message when minLength maxLength is set to same number in schema #247

@pinkjosh

Description

@pinkjosh

The validator below only checks when minLength and/or maxLength are provided and both are not equal:

https://github.com/santhosh-tekuri/jsonschema/blob/boon/validator.go#L432

If minLength and maxLength are equal and incoming value does not conform to this length then the existing error message would mislead the coder.

Example: if minLength is set as 10. no max length is set.
Incoming value: 9.
Error message: Expected atleast 10, got 9.

Example: if maxLength is set as 10. no min length is set.
Incoming value: 11.
Error message: Expected atmost 10, got 11.

Example: if minLength is set as 10. max length is also set as 10.
Incoming value: 9.
Error message: Expected atleast 10, got 9. (This error message is misleading because expectation is not atleast 10 but the length should exactly be 10.

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