[MDEV-30703] JSON_SCHEMA_VALID : Enum array must have at least one value Created: 2023-02-21  Updated: 2023-11-27  Resolved: 2023-04-21

Status: Closed
Project: MariaDB Server
Component/s: JSON
Affects Version/s: None
Fix Version/s: 11.1.1

Type: Bug Priority: Major
Reporter: Lena Startseva Assignee: Rucha Deodhar
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-27128 Implement JSON Schema Validation FUNC... Closed

 Description   

enum:

The value of this keyword MUST be an array. This array SHOULD have at least one element. Elements in the array SHOULD be unique.

https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.1.2

So it is expected that JSON_SCHEMA_VALID for this schema returns warning:

SET @schema = '{
                 "type":"array",
                  "enum": []
                }';

But actual result is:

SELECT JSON_SCHEMA_VALID(@schema, '2');
JSON_SCHEMA_VALID(@schema, '2')
0
SELECT JSON_SCHEMA_VALID(@schema, '[]');
JSON_SCHEMA_VALID(@schema, '[]')
0
SELECT JSON_SCHEMA_VALID(@schema, null);
JSON_SCHEMA_VALID(@schema, null)
1



 Comments   
Comment by Rucha Deodhar [ 2023-03-02 ]

Patch: https://github.com/MariaDB/server/tree/bb-MDEV-30703-json_schema

Comment by vaibhav sharma [ 2023-03-23 ]

You are correct that the JSON Schema specification states that the enum keyword should be an array with at least one element. In the example schema you provided, the enum keyword has an empty array as its value, which should trigger a warning according to the specification.

However, the actual behavior of the JSON_SCHEMA_VALID function you are using may differ from the specification. It appears that the function is not returning a warning for the empty array in the enum keyword.

It's possible that the function has different behavior for different versions or implementations of the JSON Schema specification. Alternatively, there may be a bug in the function that is causing it to incorrectly validate the schema.

Comment by Rucha Deodhar [ 2023-03-24 ]

vaibhav990 , yes, the patch fixes that.

Comment by Alexey Botchkov [ 2023-04-20 ]

ok to push.

Comment by Rucha Deodhar [ 2023-04-21 ]

Pushed to https://github.com/MariaDB/server/tree/bb-10.12-MDEV-27128

Generated at Thu Feb 08 10:18:16 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.