jhthorsen / json-validator

:cop: Validate data against a JSON schema
https://metacpan.org/release/JSON-Validator
56 stars 58 forks source link

How handle string OR null value ? #136

Closed pamasse closed 5 years ago

pamasse commented 5 years ago

Hi,

I'm trying to accept string value validate with a regex and also, null (undef) value. For example: "nameservers": [{ "ns": "ns1.nic.fr", "ip": null }] And "nameservers": [{ "ns": "ns1.nic.fr", "ip": "1.1.1.1" }] must be accepted.

I don't see any solution with the actual version of joi. Have you any idea to achieve this ?

Thx

jhthorsen commented 5 years ago

I haven’t tried this myself, but have you tried setting type([“null”,”string”]) ?

jhthorsen commented 5 years ago

Thanks for the issue 👍

This should be fixed in the upcoming version.