phpunit-json-assertions icon indicating copy to clipboard operation
phpunit-json-assertions copied to clipboard

"const" keyword not working

Open SchMatthieu opened this issue 2 years ago • 2 comments

We use the test folder in the repository to test our jsonSchema. We have created a class based on the same structure as AssertTaitTest.php. But when we want to test our json the keyword const doesn't work despite the errors put in the schema on purpose. However, the keyword enum works and is well taken into account in the errors. You can find attached our test json and the associated schema. Thanks in advance!

Our jsonSchema: { "$schema": "http://json-schema.org/draft-07/schema#", "$id": "https://<ourwebsite.fr/Schemas/ApiComponent/OuvragePush", "title": "Api Component Schema: Ouvrage Push", "type": "object", "properties": { "type": { "type": "string", "const": "OuvragePush"}, "price": { "type": "string", "const": "United States of America" } }, "required": [ "type", "price" ] }

Our mock json data: '{ "type":"OuvragePushooo", "price": "14" }'

SchMatthieu avatar Feb 10 '23 16:02 SchMatthieu

I don't believe const is supported. This library uses https://github.com/justinrainbow/json-schema under the hood which claims to support draft-3 and draft-4. Const was added in draft-6.

J-T-McC avatar Feb 10 '23 21:02 J-T-McC

Thank you very much for the answer!

SchMatthieu avatar Feb 15 '23 14:02 SchMatthieu