Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6610b069db | |||
| bb84f9aa73 | |||
| 704770051c | |||
| 88c77deede | |||
| 0184c244d9 | |||
| e40de2eb12 | |||
| 5e55786e3e | |||
| 6520413069 | |||
| b97879ff61 | |||
| ea0b139f87 | |||
| dccaa0a46e | |||
| 441597e604 | |||
| 710598752f | |||
| 5fbf64bac5 | |||
| 2dd17f0b37 | |||
| cbda45e610 | |||
| 1085964c17 | |||
| 65971d9b93 | |||
| d938058d34 | |||
| 69ab6165bb | |||
| 03beada825 | |||
| efdd7528cc | |||
| 59395a33ac | |||
| 92c0a6fc0b | |||
| 7f66a4a35a | |||
| d37aadb0dd | |||
| d0ccc47d97 |
49
Cargo.lock
generated
49
Cargo.lock
generated
@ -362,6 +362,15 @@ version = "0.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6"
|
||||
|
||||
[[package]]
|
||||
name = "codepage"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48f68d061bc2828ae826206326e61251aca94c1e4a5305cf52d9138639c918b4"
|
||||
dependencies = [
|
||||
"encoding_rs",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "convert_case"
|
||||
version = "0.8.0"
|
||||
@ -418,6 +427,15 @@ version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "encoding_rs"
|
||||
version = "0.8.35"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "75030f3c4f45dafd7586dd6780965a8c7e8e285a5ecb86713e63a79c5b2766f3"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum-map"
|
||||
version = "2.7.3"
|
||||
@ -1106,9 +1124,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pgrx"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3e1b41219b12cfcaa5d58f946a7ff1e7ddf0a4f7f930a7cdab612916e8a12c64"
|
||||
checksum = "bab5bc1d60d3bc3c966d307a3c7313b1ebfb49a0ec183be3f1a057df0bcc9988"
|
||||
dependencies = [
|
||||
"atomic-traits",
|
||||
"bitflags",
|
||||
@ -1130,9 +1148,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pgrx-bindgen"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6afcef51e801bb18662716f1c524cedfb7943844593171734fe4d3a94c9afa12"
|
||||
checksum = "9804b74c211a9edd550cd974718f8cc407dec50d8e9cafb906e0b042ba434af0"
|
||||
dependencies = [
|
||||
"bindgen",
|
||||
"cc",
|
||||
@ -1149,9 +1167,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pgrx-macros"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "729af3e6954d2f76230d700efd8606121f13f71f800e5c76173add2c02097948"
|
||||
checksum = "f230769493bf567f137de23264d604d267dd72b8a77c596528e43cf423c6208e"
|
||||
dependencies = [
|
||||
"pgrx-sql-entity-graph",
|
||||
"proc-macro2",
|
||||
@ -1161,11 +1179,13 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pgrx-pg-config"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "116e33a329f3fac976b5f3150f14f2612735dfc56a15cb0a0800f25a3bd90aa7"
|
||||
checksum = "49b64c071c2a46a19ab4521120a25b02b598f4abf6e9b4b1769a7922edeee3de"
|
||||
dependencies = [
|
||||
"cargo_toml",
|
||||
"codepage",
|
||||
"encoding_rs",
|
||||
"eyre",
|
||||
"home",
|
||||
"owo-colors",
|
||||
@ -1175,13 +1195,14 @@ dependencies = [
|
||||
"thiserror 2.0.12",
|
||||
"toml",
|
||||
"url",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pgrx-pg-sys"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cd074044513f1f7fc63fd1ed0117ad0fbe690ef1b445f6d72b92e611b3846490"
|
||||
checksum = "fcbfa98ec7a90252d13a78ac666541173dbb01a2fc1ba20131db6490c0711125"
|
||||
dependencies = [
|
||||
"cee-scape",
|
||||
"libc",
|
||||
@ -1194,9 +1215,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pgrx-sql-entity-graph"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0eb73c4b916d4abb422fff66c2606c46bf4b99136209306836e89766a8d49cd"
|
||||
checksum = "e79bbf5a33cff6cfdc6dda3a976cd931c995eaa2c073a7c59b8f8fe8f6faa073"
|
||||
dependencies = [
|
||||
"convert_case",
|
||||
"eyre",
|
||||
@ -1210,9 +1231,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "pgrx-tests"
|
||||
version = "0.14.0"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "aba4e9a97fd148c9f65cf0c56d33a4cde4deb9941f5c0d914a39148e8148a7a6"
|
||||
checksum = "9791c709882f3af9545bcca71670fdd82768f67a428b416b6210eae3773dbd0d"
|
||||
dependencies = [
|
||||
"clap-cargo",
|
||||
"eyre",
|
||||
|
||||
@ -1,17 +1,17 @@
|
||||
[package]
|
||||
name = "jspg"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
pgrx = "0.14.0"
|
||||
pgrx = "0.15.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
lazy_static = "1.5.0"
|
||||
boon = "0.6.1"
|
||||
|
||||
[dev-dependencies]
|
||||
pgrx-tests = "0.14.0"
|
||||
pgrx-tests = "0.15.0"
|
||||
|
||||
[lib]
|
||||
crate-type = ["cdylib", "lib"]
|
||||
|
||||
4
flow
4
flow
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Flows
|
||||
source ./flows/base
|
||||
@ -11,7 +11,7 @@ source ./flows/rust
|
||||
POSTGRES_VERSION="17"
|
||||
POSTGRES_CONFIG_PATH="/opt/homebrew/opt/postgresql@${POSTGRES_VERSION}/bin/pg_config"
|
||||
DEPENDENCIES+=(icu4c pkg-config "postgresql@${POSTGRES_VERSION}")
|
||||
CARGO_DEPENDENCIES=(cargo-pgrx==0.14.0)
|
||||
CARGO_DEPENDENCIES=(cargo-pgrx==0.15.0)
|
||||
GITEA_ORGANIZATION="cellular"
|
||||
GITEA_REPOSITORY="jspg"
|
||||
|
||||
|
||||
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
@ -0,0 +1 @@
|
||||
tab_spaces = 2
|
||||
88
src/helpers.rs
Normal file
88
src/helpers.rs
Normal file
@ -0,0 +1,88 @@
|
||||
use serde_json::Value;
|
||||
use pgrx::JsonB;
|
||||
|
||||
// Simple test helpers for cleaner test code
|
||||
pub fn assert_success(result: &JsonB) {
|
||||
let json = &result.0;
|
||||
if !json.get("response").is_some() || json.get("errors").is_some() {
|
||||
let pretty = serde_json::to_string_pretty(json).unwrap_or_else(|_| format!("{:?}", json));
|
||||
panic!("Expected success but got:\n{}", pretty);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert_failure(result: &JsonB) {
|
||||
let json = &result.0;
|
||||
if json.get("response").is_some() || !json.get("errors").is_some() {
|
||||
let pretty = serde_json::to_string_pretty(json).unwrap_or_else(|_| format!("{:?}", json));
|
||||
panic!("Expected failure but got:\n{}", pretty);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn assert_error_count(result: &JsonB, expected_count: usize) {
|
||||
assert_failure(result);
|
||||
let errors = get_errors(result);
|
||||
if errors.len() != expected_count {
|
||||
let pretty = serde_json::to_string_pretty(&result.0).unwrap_or_else(|_| format!("{:?}", result.0));
|
||||
panic!("Expected {} errors, got {}:\n{}", expected_count, errors.len(), pretty);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_errors(result: &JsonB) -> &Vec<Value> {
|
||||
result.0["errors"].as_array().expect("errors should be an array")
|
||||
}
|
||||
|
||||
pub fn has_error_with_code(result: &JsonB, code: &str) -> bool {
|
||||
get_errors(result).iter().any(|e| e["code"] == code)
|
||||
}
|
||||
|
||||
|
||||
pub fn has_error_with_code_and_path(result: &JsonB, code: &str, path: &str) -> bool {
|
||||
get_errors(result).iter().any(|e| e["code"] == code && e["details"]["path"] == path)
|
||||
}
|
||||
|
||||
pub fn assert_has_error(result: &JsonB, code: &str, path: &str) {
|
||||
if !has_error_with_code_and_path(result, code, path) {
|
||||
let pretty = serde_json::to_string_pretty(&result.0).unwrap_or_else(|_| format!("{:?}", result.0));
|
||||
panic!("Expected error with code='{}' and path='{}' but not found:\n{}", code, path, pretty);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn find_error_with_code<'a>(result: &'a JsonB, code: &str) -> &'a Value {
|
||||
get_errors(result).iter().find(|e| e["code"] == code)
|
||||
.unwrap_or_else(|| panic!("No error found with code '{}'", code))
|
||||
}
|
||||
|
||||
|
||||
pub fn find_error_with_code_and_path<'a>(result: &'a JsonB, code: &str, path: &str) -> &'a Value {
|
||||
get_errors(result).iter().find(|e| e["code"] == code && e["details"]["path"] == path)
|
||||
.unwrap_or_else(|| panic!("No error found with code '{}' and path '{}'", code, path))
|
||||
}
|
||||
|
||||
pub fn assert_error_detail(error: &Value, detail_key: &str, expected_value: &str) {
|
||||
let actual = error["details"][detail_key].as_str()
|
||||
.unwrap_or_else(|| panic!("Error detail '{}' is not a string", detail_key));
|
||||
assert_eq!(actual, expected_value, "Error detail '{}' mismatch", detail_key);
|
||||
}
|
||||
|
||||
|
||||
// Additional convenience helpers for common patterns
|
||||
|
||||
pub fn assert_error_message_contains(error: &Value, substring: &str) {
|
||||
let message = error["message"].as_str().expect("error should have message");
|
||||
assert!(message.contains(substring), "Expected message to contain '{}', got '{}'", substring, message);
|
||||
}
|
||||
|
||||
pub fn assert_error_cause_json(error: &Value, expected_cause: &Value) {
|
||||
let cause = &error["details"]["cause"];
|
||||
assert!(cause.is_object(), "cause should be JSON object");
|
||||
assert_eq!(cause, expected_cause, "cause mismatch");
|
||||
}
|
||||
|
||||
pub fn assert_error_context(error: &Value, expected_context: &Value) {
|
||||
assert_eq!(&error["details"]["context"], expected_context, "context mismatch");
|
||||
}
|
||||
|
||||
|
||||
pub fn jsonb(val: Value) -> JsonB {
|
||||
JsonB(val)
|
||||
}
|
||||
1059
src/lib.rs
1059
src/lib.rs
File diff suppressed because it is too large
Load Diff
805
src/schemas.rs
Normal file
805
src/schemas.rs
Normal file
@ -0,0 +1,805 @@
|
||||
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,
|
||||
"schemas": [{
|
||||
"$id": "simple.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,
|
||||
"schemas": [{
|
||||
"$id": "invalid_punc.request",
|
||||
"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,
|
||||
"schemas": [{
|
||||
"$id": "detailed_errors_test.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,
|
||||
"schemas": [{
|
||||
"$id": "oneof_test.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,
|
||||
"schemas": [{
|
||||
"$id": "object_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"age": { "type": "integer", "minimum": 0 }
|
||||
},
|
||||
"required": ["name", "age"]
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "array_test",
|
||||
"public": false,
|
||||
"schemas": [{
|
||||
"$id": "array_test.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,
|
||||
"schemas": [{
|
||||
"$id": "basic_strict_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" }
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "non_strict_test",
|
||||
"public": false,
|
||||
"schemas": [{
|
||||
"$id": "non_strict_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" }
|
||||
}
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "nested_strict_test",
|
||||
"public": true,
|
||||
"schemas": [{
|
||||
"$id": "nested_strict_test.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,
|
||||
"schemas": [{
|
||||
"$id": "already_unevaluated_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" }
|
||||
},
|
||||
"unevaluatedProperties": true
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "already_additional_test",
|
||||
"public": true,
|
||||
"schemas": [{
|
||||
"$id": "already_additional_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "conditional_strict_test",
|
||||
"public": true,
|
||||
"schemas": [{
|
||||
"$id": "conditional_strict_test.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,
|
||||
"schemas": [{
|
||||
"$id": "basic_validation_test.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,
|
||||
"schemas": [{
|
||||
"$id": "dependency_split_test.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,
|
||||
"schemas": [{
|
||||
"$id": "nested_dep_test.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,
|
||||
"schemas": [{
|
||||
"$id": "additional_props_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"age": { "type": "number" }
|
||||
},
|
||||
"additionalProperties": false
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "nested_additional_props_test",
|
||||
"public": false,
|
||||
"schemas": [{
|
||||
"$id": "nested_additional_props_test.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,
|
||||
"schemas": [{
|
||||
"$id": "simple_unevaluated_test.request",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": { "type": "string" },
|
||||
"age": { "type": "number" }
|
||||
},
|
||||
"patternProperties": {
|
||||
"^attr_": { "type": "string" }
|
||||
},
|
||||
"unevaluatedProperties": false
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "conditional_unevaluated_test",
|
||||
"public": false,
|
||||
"schemas": [{
|
||||
"$id": "conditional_unevaluated_test.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,
|
||||
"schemas": [{
|
||||
"$id": "format_test.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,
|
||||
"schemas": [{
|
||||
"$id": "public_ref_test.request",
|
||||
"$ref": "person"
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "private_ref_test",
|
||||
"public": false,
|
||||
"schemas": [{
|
||||
"$id": "private_ref_test.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,
|
||||
"schemas": [{
|
||||
"$id": "enum_ref_test.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"]
|
||||
},
|
||||
{
|
||||
"$id": "punc_with_local_ref_test.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"]
|
||||
},
|
||||
{
|
||||
"$id": "punc_with_local_ref_to_global_test.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))
|
||||
}
|
||||
|
||||
pub fn type_matching_schemas() -> JsonB {
|
||||
let enums = json!([]);
|
||||
let types = json!([
|
||||
{
|
||||
"name": "entity",
|
||||
"schemas": [{
|
||||
"$id": "entity",
|
||||
"type": "object",
|
||||
"properties": { "type": { "type": "string" }, "name": { "type": "string" } },
|
||||
"required": ["type", "name"]
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "job",
|
||||
"schemas": [{
|
||||
"$id": "job",
|
||||
"$ref": "entity",
|
||||
"properties": { "job_id": { "type": "string" } },
|
||||
"required": ["job_id"]
|
||||
}]
|
||||
},
|
||||
{
|
||||
"name": "super_job",
|
||||
"schemas": [
|
||||
{
|
||||
"$id": "super_job",
|
||||
"$ref": "job",
|
||||
"properties": { "manager_id": { "type": "string" } },
|
||||
"required": ["manager_id"]
|
||||
},
|
||||
{
|
||||
"$id": "super_job.short",
|
||||
"$ref": "super_job",
|
||||
"properties": { "name": { "maxLength": 10 } }
|
||||
}
|
||||
]
|
||||
}
|
||||
]);
|
||||
let puncs = json!([]);
|
||||
cache_json_schemas(jsonb(enums), jsonb(types), jsonb(puncs))
|
||||
}
|
||||
1104
src/tests.rs
1104
src/tests.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user