use crate::*; use serde_json::{json, Value}; use pgrx::JsonB; // Helper to convert Value to JsonB fn jsonb(val: Value) -> JsonB { JsonB(val) } pub fn simple_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "simple", "public": false, "request": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } }, "required": ["name", "age"] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn invalid_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "invalid_punc", "public": false, "request": { "$id": "urn:invalid_schema", "type": ["invalid_type_value"] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn errors_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "detailed_errors_test", "public": false, "request": { "type": "object", "properties": { "address": { "type": "object", "properties": { "street": { "type": "string" }, "city": { "type": "string", "maxLength": 10 } }, "required": ["street", "city"] } }, "required": ["address"] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn oneof_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "oneof_test", "public": false, "request": { "oneOf": [ { "type": "object", "properties": { "string_prop": { "type": "string", "maxLength": 5 } }, "required": ["string_prop"] }, { "type": "object", "properties": { "number_prop": { "type": "number", "minimum": 10 } }, "required": ["number_prop"] } ] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn root_types_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([ { "name": "object_test", "public": false, "request": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } }, "required": ["name", "age"] } }, { "name": "array_test", "public": false, "request": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "format": "uuid" } } } } } ]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn strict_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([ { "name": "basic_strict_test", "public": true, "request": { "type": "object", "properties": { "name": { "type": "string" } } } }, { "name": "non_strict_test", "public": false, "request": { "type": "object", "properties": { "name": { "type": "string" } } } }, { "name": "nested_strict_test", "public": true, "request": { "type": "object", "properties": { "user": { "type": "object", "properties": { "name": { "type": "string" } } }, "items": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" } } } } } } }, { "name": "already_unevaluated_test", "public": true, "request": { "type": "object", "properties": { "name": { "type": "string" } }, "unevaluatedProperties": true } }, { "name": "already_additional_test", "public": true, "request": { "type": "object", "properties": { "name": { "type": "string" } }, "additionalProperties": false } }, { "name": "conditional_strict_test", "public": true, "request": { "type": "object", "properties": { "creating": { "type": "boolean" } }, "if": { "properties": { "creating": { "const": true } } }, "then": { "properties": { "name": { "type": "string" } }, "required": ["name"] } } } ]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn required_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "basic_validation_test", "public": false, "request": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "integer", "minimum": 0 } }, "required": ["name", "age"] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn dependencies_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "dependency_split_test", "public": false, "request": { "type": "object", "properties": { "creating": { "type": "boolean" }, "name": { "type": "string" }, "kind": { "type": "string" }, "description": { "type": "string" } }, "dependencies": { "creating": ["name", "kind"] } } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn nested_req_deps_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "nested_dep_test", "public": false, "request": { "type": "object", "properties": { "items": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string" }, "creating": { "type": "boolean" }, "name": { "type": "string" }, "kind": { "type": "string" } }, "required": ["id"], "dependencies": { "creating": ["name", "kind"] } } } }, "required": ["items"] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn additional_properties_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([ { "name": "additional_props_test", "public": false, "request": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "number" } }, "additionalProperties": false } }, { "name": "nested_additional_props_test", "public": false, "request": { "type": "object", "properties": { "user": { "type": "object", "properties": { "name": { "type": "string" } }, "additionalProperties": false } } } } ]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn unevaluated_properties_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([ { "name": "simple_unevaluated_test", "public": false, "request": { "type": "object", "properties": { "name": { "type": "string" }, "age": { "type": "number" } }, "patternProperties": { "^attr_": { "type": "string" } }, "unevaluatedProperties": false } }, { "name": "conditional_unevaluated_test", "public": false, "request": { "type": "object", "allOf": [ { "properties": { "firstName": { "type": "string" } } }, { "properties": { "lastName": { "type": "string" } } } ], "properties": { "age": { "type": "number" } }, "unevaluatedProperties": false } } ]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn format_schemas() -> JsonB { let enums = json!([]); let types = json!([]); let puncs = json!([{ "name": "format_test", "public": false, "request": { "type": "object", "properties": { "uuid": { "type": "string", "format": "uuid" }, "date_time": { "type": "string", "format": "date-time" }, "email": { "type": "string", "format": "email" } } } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn property_merging_schemas() -> JsonB { let enums = json!([]); let types = json!([ { "name": "entity", "schemas": [{ "$id": "entity", "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } }, "required": ["id"] }] }, { "name": "user", "schemas": [{ "$id": "user", "$ref": "entity", "properties": { "password": { "type": "string", "minLength": 8 } }, "required": ["password"] }] }, { "name": "person", "schemas": [{ "$id": "person", "$ref": "user", "properties": { "first_name": { "type": "string", "minLength": 1 }, "last_name": { "type": "string", "minLength": 1 } }, "required": ["first_name", "last_name"] }] } ]); let puncs = json!([]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn required_merging_schemas() -> JsonB { let enums = json!([]); let types = json!([ { "name": "entity", "schemas": [{ "$id": "entity", "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "type": { "type": "string" }, "created_by": { "type": "string", "format": "uuid" } }, "required": ["id", "type", "created_by"] }] }, { "name": "user", "schemas": [{ "$id": "user", "$ref": "entity", "properties": { "password": { "type": "string", "minLength": 8 } }, "if": { "properties": { "type": { "const": "user" } } }, "then": { "required": ["password"] } }] }, { "name": "person", "schemas": [{ "$id": "person", "$ref": "user", "properties": { "first_name": { "type": "string", "minLength": 1 }, "last_name": { "type": "string", "minLength": 1 } }, "if": { "properties": { "type": { "const": "person" } } }, "then": { "required": ["first_name", "last_name"] } }] } ]); let puncs = json!([]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn dependencies_merging_schemas() -> JsonB { let enums = json!([]); let types = json!([ { "name": "entity", "schemas": [{ "$id": "entity", "type": "object", "properties": { "id": { "type": "string", "format": "uuid" }, "type": { "type": "string" }, "created_by": { "type": "string", "format": "uuid" }, "creating": { "type": "boolean" }, "name": { "type": "string" } }, "required": ["id", "type", "created_by"], "dependencies": { "creating": ["name"] } }] }, { "name": "user", "schemas": [{ "$id": "user", "$ref": "entity", "properties": { "password": { "type": "string", "minLength": 8 } }, "dependencies": { "creating": ["name"] } }] }, { "name": "person", "schemas": [{ "$id": "person", "$ref": "user", "properties": { "first_name": { "type": "string", "minLength": 1 }, "last_name": { "type": "string", "minLength": 1 } }, "dependencies": { "creating": ["first_name", "last_name"] } }] } ]); let puncs = json!([]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn punc_with_refs_schemas() -> JsonB { let enums = json!([]); let types = json!([ { "name": "entity", "schemas": [{ "$id": "entity", "type": "object", "properties": { "id": { "type": "string" }, "name": { "type": "string" } }, "required": ["id"] }] }, { "name": "person", "schemas": [{ "$id": "person", "$ref": "entity", "properties": { "first_name": { "type": "string", "minLength": 1 }, "last_name": { "type": "string", "minLength": 1 }, "address": { "type": "object", "properties": { "street": { "type": "string" }, "city": { "type": "string" } }, "required": ["street", "city"] } } }] } ]); let puncs = json!([ { "name": "public_ref_test", "public": true, "request": { "$ref": "person" } }, { "name": "private_ref_test", "public": false, "request": { "$ref": "person" } } ]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn enum_schemas() -> JsonB { let enums = json!([ { "name": "task_priority", "values": ["low", "medium", "high", "urgent"], "schemas": [{ "$id": "task_priority", "type": "string", "enum": ["low", "medium", "high", "urgent"] }] } ]); let types = json!([]); let puncs = json!([{ "name": "enum_ref_test", "public": false, "request": { "type": "object", "properties": { "priority": { "$ref": "task_priority" } }, "required": ["priority"] } }]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn punc_local_refs_schemas() -> JsonB { let enums = json!([]); let types = json!([ { "name": "global_thing", "schemas": [{ "$id": "global_thing", "type": "object", "properties": { "id": { "type": "string", "format": "uuid" } }, "required": ["id"] }] } ]); let puncs = json!([ { "name": "punc_with_local_ref_test", "public": false, "schemas": [{ "$id": "local_address", "type": "object", "properties": { "street": { "type": "string" }, "city": { "type": "string" } }, "required": ["street", "city"] }], "request": { "$ref": "local_address" } }, { "name": "punc_with_local_ref_to_global_test", "public": false, "schemas": [{ "$id": "local_user_with_thing", "type": "object", "properties": { "user_name": { "type": "string" }, "thing": { "$ref": "global_thing" } }, "required": ["user_name", "thing"] }], "request": { "$ref": "local_user_with_thing" } } ]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) } pub fn title_override_schemas() -> JsonB { let enums = json!([]); let types = json!([ { "name": "base_with_title", "schemas": [{ "$id": "base_with_title", "type": "object", "title": "Base Title", "properties": { "name": { "type": "string" } }, "required": ["name"] }] }, { "name": "override_with_title", "schemas": [{ "$id": "override_with_title", "$ref": "base_with_title", "title": "Override Title" }] } ]); let puncs = json!([]); cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs)) }