sagold / json-schema-library

Customizable and hackable json-validator and json-schema utilities for traversal, data generation and validation
MIT License
164 stars 19 forks source link

The purpose of minLengthOneError #49

Open vbilenko-te opened 8 months ago

vbilenko-te commented 8 months ago

Hi, First of all want to say thank you for developing such useful lib for JSON Schema. Have one question: what the purpose of minLengthOneError? According to official JSON Schema specification there is no such validator. Wouldn't say it cause a problem but still have to handle it separately.

sagold commented 8 months ago

Hi,

thank you for your feedback!

The minLengthOneError is thrown for validation errors of minLength: 1. This can be used to test for required input of string values, since there is no json-schema equivalent. The specific error simplifies custom error messages for this case. E.g. you can state that an input/value is expected, instead of telling that the input requires a minimum length of 1.

This behaviour can also be changed.

Are you having issues, because you checked for minError?

vbilenko-te commented 8 months ago

Thanks for the answer. Not a technical problem. Abstractly speaking there are two teams who using different libraries and it is hard to explain why it is only me who has a custom schema error which is not documented in official JSON Schema specification. For now I manage it as a regular minLength to follow official spec. So, just want to says it's would be nice to maintain compatibility with official public specifications to ensure consistency and compatibility across different systems. On my subjective opinion maybe it is better to throw both minLength and minLengthOne errors to keep compatible with spec and also provide additional custom error at the same time?