mirror of
https://github.com/neondatabase/neon.git
synced 2026-01-05 20:42:54 +00:00
## Problem `pg_jsonschema` and `pg_session_jwt` are not yet covered by tests ## Summary of changes Added the tests for these extensions.
88 lines
2.6 KiB
Plaintext
88 lines
2.6 KiB
Plaintext
-- Schema with enums, nulls, extra properties disallowed
|
|
SELECT jsonschema_is_valid('{
|
|
"type": "object",
|
|
"properties": {
|
|
"status": { "type": "string", "enum": ["active", "inactive", "pending"] },
|
|
"email": { "type": ["string", "null"], "format": "email" }
|
|
},
|
|
"required": ["status"],
|
|
"additionalProperties": false
|
|
}'::json);
|
|
jsonschema_is_valid
|
|
---------------------
|
|
t
|
|
(1 row)
|
|
|
|
-- Valid enum and null email
|
|
SELECT jsonschema_validation_errors(
|
|
'{
|
|
"type": "object",
|
|
"properties": {
|
|
"status": { "type": "string", "enum": ["active", "inactive", "pending"] },
|
|
"email": { "type": ["string", "null"], "format": "email" }
|
|
},
|
|
"required": ["status"],
|
|
"additionalProperties": false
|
|
}'::json,
|
|
'{"status": "active", "email": null}'::json
|
|
);
|
|
jsonschema_validation_errors
|
|
------------------------------
|
|
{}
|
|
(1 row)
|
|
|
|
-- Invalid enum value
|
|
SELECT jsonschema_validation_errors(
|
|
'{
|
|
"type": "object",
|
|
"properties": {
|
|
"status": { "type": "string", "enum": ["active", "inactive", "pending"] },
|
|
"email": { "type": ["string", "null"], "format": "email" }
|
|
},
|
|
"required": ["status"],
|
|
"additionalProperties": false
|
|
}'::json,
|
|
'{"status": "disabled", "email": null}'::json
|
|
);
|
|
jsonschema_validation_errors
|
|
----------------------------------------------------------------------
|
|
{"\"disabled\" is not one of [\"active\",\"inactive\",\"pending\"]"}
|
|
(1 row)
|
|
|
|
-- Invalid email format (assuming format is validated)
|
|
SELECT jsonschema_validation_errors(
|
|
'{
|
|
"type": "object",
|
|
"properties": {
|
|
"status": { "type": "string", "enum": ["active", "inactive", "pending"] },
|
|
"email": { "type": ["string", "null"], "format": "email" }
|
|
},
|
|
"required": ["status"],
|
|
"additionalProperties": false
|
|
}'::json,
|
|
'{"status": "active", "email": "not-an-email"}'::json
|
|
);
|
|
jsonschema_validation_errors
|
|
-----------------------------------------
|
|
{"\"not-an-email\" is not a \"email\""}
|
|
(1 row)
|
|
|
|
-- Extra property not allowed
|
|
SELECT jsonschema_validation_errors(
|
|
'{
|
|
"type": "object",
|
|
"properties": {
|
|
"status": { "type": "string", "enum": ["active", "inactive", "pending"] },
|
|
"email": { "type": ["string", "null"], "format": "email" }
|
|
},
|
|
"required": ["status"],
|
|
"additionalProperties": false
|
|
}'::json,
|
|
'{"status": "active", "extra": "should not be here"}'::json
|
|
);
|
|
jsonschema_validation_errors
|
|
--------------------------------------------------------------------
|
|
{"Additional properties are not allowed ('extra' was unexpected)"}
|
|
(1 row)
|
|
|