The post has been translated automatically. Original language: Russian
In a teaching catalogue every product needs a name for its printed label. The JSON Schema declares required: ["name"]. The print shop supplies three objects: {}, {"name":null} and {"name":""}. With required as the only constraint, only the first fails. The other two have the key.
Set the root type to object and give name the type string and minLength: 1. Now null has the wrong type and the empty string is too short. A fourth test, {"name":" "}, still passes even though the label looks blank.
In this example the catalogue owner chooses to trim ordinary spaces at both ends before checking length. Acceptance line: “Reject a missing field, null, an empty string and a single ordinary space. Print a two-word name with its internal space preserved.” Agree separately with the print shop on how to handle other whitespace characters.
В учебном каталоге каждый товар должен получить название для ценника. В JSON Schema разработчик указал required: ["name"]. Перед запуском типография прислала три пробных объекта: {}, {"name":null} и {"name":""}. При единственном ограничении required только первый объект провалит проверку: у остальных ключ присутствует.
Добавляем для name тип string и minLength: 1, а для корня тип object. Теперь null не подходит по типу, пустая строка слишком коротка. Четвёртый тест неожиданнее: {"name":" "} пройдёт, хотя на ценнике снова ничего не видно.
Решение владельца каталога в примере: обычные пробелы по краям удаляем перед проверкой длины. Строка приёмки: «Пропуск, null, пустая строка и один обычный пробел отклонены; название из двух слов печатается с внутренним пробелом». Для других пробельных символов отдельно согласуем нормализацию с типографией.
Comments 0
Newest Popular