Compare commits
30 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 710598752f | |||
| 5fbf64bac5 | |||
| 2dd17f0b37 | |||
| cbda45e610 | |||
| 1085964c17 | |||
| 65971d9b93 | |||
| d938058d34 | |||
| 69ab6165bb | |||
| 03beada825 | |||
| efdd7528cc | |||
| 59395a33ac | |||
| 92c0a6fc0b | |||
| 7f66a4a35a | |||
| d37aadb0dd | |||
| d0ccc47d97 | |||
| 2d19bf100e | |||
| fb333c6cbb | |||
| d8a9a7b76b | |||
| c9022aefb9 | |||
| ccf0465e45 | |||
| dce50d9dc3 | |||
| 8ec6a5b58a | |||
| 6ef7e0c55e | |||
| 1cb5fb0ecf | |||
| d66aae8ae2 | |||
| 3b18901bda | |||
| b8c0e08068 | |||
| c734983a59 | |||
| 9b11f661bc | |||
| f3a733626e |
13
.env
13
.env
@ -1,13 +0,0 @@
|
||||
ENVIRONMENT=local
|
||||
DATABASE_PASSWORD=tIr4TJ0qUwGVM0rlQSe3W7Tgpi33zPbk
|
||||
DATABASE_ROLE=agreego_admin
|
||||
DATABASE_HOST=127.1.27.4
|
||||
DATABASE_PORT=5432
|
||||
POSTGRES_PASSWORD=xzIq5JT0xY3F+2m1GtnrKDdK29sNSXVVYZHPKJVh8pI=
|
||||
DATABASE_NAME=agreego
|
||||
DEV_DATABASE_NAME=agreego_dev
|
||||
GITEA_TOKEN=3d70c23673517330623a5122998fb304e3c73f0a
|
||||
MOOV_ACCOUNT_ID=69a0d2f6-77a2-4e26-934f-d869134f87d3
|
||||
MOOV_PUBLIC_KEY=9OMhK5qGnh7Tmk2Z
|
||||
MOOV_SECRET_KEY=DrRox7B-YWfO9IheiUUX7lGP8-7VY-Ni
|
||||
MOOV_DOMAIN=http://localhost
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
/target
|
||||
/package
|
||||
.env
|
||||
542
Cargo.lock
generated
542
Cargo.lock
generated
@ -26,7 +26,6 @@ dependencies = [
|
||||
"cfg-if",
|
||||
"getrandom 0.2.15",
|
||||
"once_cell",
|
||||
"serde",
|
||||
"version_check",
|
||||
"zerocopy 0.7.35",
|
||||
]
|
||||
@ -113,7 +112,7 @@ dependencies = [
|
||||
"miniz_oxide",
|
||||
"object",
|
||||
"rustc-demangle",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -215,12 +214,6 @@ version = "3.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
||||
|
||||
[[package]]
|
||||
name = "bytecount"
|
||||
version = "0.6.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
version = "1.5.0"
|
||||
@ -425,15 +418,6 @@ version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "email_address"
|
||||
version = "0.2.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e079f19b08ca6239f47f8ba8509c11cf3ea30095831f7fed61441475edd8c449"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "enum-map"
|
||||
version = "2.7.3"
|
||||
@ -486,17 +470,6 @@ version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7"
|
||||
|
||||
[[package]]
|
||||
name = "fancy-regex"
|
||||
version = "0.14.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e24cb5a94bcae1e5408b0effca5cd7172ea3c5755049c5f3af4cd283a165298"
|
||||
dependencies = [
|
||||
"bit-set",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fastrand"
|
||||
version = "2.3.0"
|
||||
@ -517,7 +490,6 @@ checksum = "1918b65d96df47d3591bed19c5cca17e3fa5d0707318e4b5ef2eae01764df7e5"
|
||||
dependencies = [
|
||||
"borrow-or-share",
|
||||
"ref-cast",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -541,16 +513,6 @@ dependencies = [
|
||||
"percent-encoding",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fraction"
|
||||
version = "0.15.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f158e3ff0a1b334408dc9fb811cd99b446986f4d8b741bb08f9df1604085ae7"
|
||||
dependencies = [
|
||||
"lazy_static",
|
||||
"num",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "funty"
|
||||
version = "2.0.0"
|
||||
@ -573,12 +535,6 @@ version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "05f29059c0c2090612e8d742178b0580d2dc940c837851ad723096f87af6663e"
|
||||
|
||||
[[package]]
|
||||
name = "futures-io"
|
||||
version = "0.3.31"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
||||
|
||||
[[package]]
|
||||
name = "futures-macro"
|
||||
version = "0.3.31"
|
||||
@ -609,11 +565,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9fa08315bb612088cc391249efdc3bc77536f16c91f6cf495e6fbe85b20a4a81"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-io",
|
||||
"futures-macro",
|
||||
"futures-sink",
|
||||
"futures-task",
|
||||
"memchr",
|
||||
"pin-project-lite",
|
||||
"pin-utils",
|
||||
"slab",
|
||||
@ -730,85 +684,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http"
|
||||
version = "1.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4a85d31aea989eead29a3aaf9e1115a180df8282431156e533de47660892565"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"fnv",
|
||||
"itoa",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http-body"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"http",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "http-body-util"
|
||||
version = "0.1.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b021d93e26becf5dc7e1b75b1bed1fd93124b374ceb73f43d4d4eafec896a64a"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-core",
|
||||
"http",
|
||||
"http-body",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "httparse"
|
||||
version = "1.10.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87"
|
||||
|
||||
[[package]]
|
||||
name = "hyper"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cc2b571658e38e0c01b1fdca3bbbe93c00d3d71693ff2770043f8c29bc7d6f80"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"httparse",
|
||||
"itoa",
|
||||
"pin-project-lite",
|
||||
"smallvec",
|
||||
"tokio",
|
||||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-util"
|
||||
version = "0.1.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "497bbc33a26fdd4af9ed9c70d63f61cf56a938375fbb32df34db9b1cd6d643f2"
|
||||
dependencies = [
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"hyper",
|
||||
"libc",
|
||||
"pin-project-lite",
|
||||
"socket2",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "icu_collections"
|
||||
version = "1.5.0"
|
||||
@ -964,12 +839,6 @@ dependencies = [
|
||||
"hashbrown",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.11.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "469fb0b9cefa57e3ef31275ee7cacb78f2fdca44e4765491884a2b119d4eb130"
|
||||
|
||||
[[package]]
|
||||
name = "is-terminal"
|
||||
version = "0.4.16"
|
||||
@ -1012,37 +881,11 @@ dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jsonschema"
|
||||
version = "0.29.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "161c33c3ec738cfea3288c5c53dfcdb32fd4fc2954de86ea06f71b5a1a40bfcd"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"base64",
|
||||
"bytecount",
|
||||
"email_address",
|
||||
"fancy-regex",
|
||||
"fraction",
|
||||
"idna",
|
||||
"itoa",
|
||||
"num-cmp",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"referencing",
|
||||
"regex-syntax",
|
||||
"reqwest",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"uuid-simd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jspg"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"boon",
|
||||
"jsonschema",
|
||||
"lazy_static",
|
||||
"pgrx",
|
||||
"pgrx-tests",
|
||||
@ -1069,7 +912,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1116,12 +959,6 @@ version = "2.7.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3"
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a"
|
||||
|
||||
[[package]]
|
||||
name = "minimal-lexical"
|
||||
version = "0.2.1"
|
||||
@ -1167,76 +1004,6 @@ dependencies = [
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num"
|
||||
version = "0.4.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"num-complex",
|
||||
"num-integer",
|
||||
"num-iter",
|
||||
"num-rational",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-bigint"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a5e44f723f1133c9deac646763579fdb3ac745e418f2a7af9cd0c431da1f20b9"
|
||||
dependencies = [
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-cmp"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63335b2e2c34fae2fb0aa2cecfd9f0832a1e24b3b32ecec612c3426d46dc8aaa"
|
||||
|
||||
[[package]]
|
||||
name = "num-complex"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-integer"
|
||||
version = "0.1.46"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-iter"
|
||||
version = "0.1.45"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-rational"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824"
|
||||
dependencies = [
|
||||
"num-bigint",
|
||||
"num-integer",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
@ -1270,12 +1037,6 @@ version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "outref"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1a80800c0488c3a21695ea981a54918fbb37abf04f4d0720c453632255e2ff0e"
|
||||
|
||||
[[package]]
|
||||
name = "owo-colors"
|
||||
version = "4.2.0"
|
||||
@ -1306,7 +1067,7 @@ dependencies = [
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1710,20 +1471,6 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "referencing"
|
||||
version = "0.29.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40a64b3a635fad9000648b4d8a59c8710c523ab61a23d392a7d91d47683f5adc"
|
||||
dependencies = [
|
||||
"ahash",
|
||||
"fluent-uri",
|
||||
"once_cell",
|
||||
"parking_lot",
|
||||
"percent-encoding",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.11.1"
|
||||
@ -1753,43 +1500,6 @@ version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
|
||||
|
||||
[[package]]
|
||||
name = "reqwest"
|
||||
version = "0.12.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d19c46a6fdd48bc4dab94b6103fccc55d34c67cc0ad04653aad4ea2a07cd7bbb"
|
||||
dependencies = [
|
||||
"base64",
|
||||
"bytes",
|
||||
"futures-channel",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"http",
|
||||
"http-body",
|
||||
"http-body-util",
|
||||
"hyper",
|
||||
"hyper-util",
|
||||
"ipnet",
|
||||
"js-sys",
|
||||
"log",
|
||||
"mime",
|
||||
"once_cell",
|
||||
"percent-encoding",
|
||||
"pin-project-lite",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"serde_urlencoded",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tower",
|
||||
"tower-service",
|
||||
"url",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"windows-registry",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.24"
|
||||
@ -1824,12 +1534,6 @@ dependencies = [
|
||||
"windows-sys 0.59.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "rusty-fork"
|
||||
version = "0.3.0"
|
||||
@ -1929,18 +1633,6 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_urlencoded"
|
||||
version = "0.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd"
|
||||
dependencies = [
|
||||
"form_urlencoded",
|
||||
"itoa",
|
||||
"ryu",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sha2"
|
||||
version = "0.10.8"
|
||||
@ -2048,15 +1740,6 @@ dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "sync_wrapper"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "synstructure"
|
||||
version = "0.13.1"
|
||||
@ -2253,58 +1936,6 @@ dependencies = [
|
||||
"winnow",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d039ad9159c98b70ecfd540b2573b97f7f52c3e8d9f8ad57a24b916a536975f9"
|
||||
dependencies = [
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"pin-project-lite",
|
||||
"sync_wrapper",
|
||||
"tokio",
|
||||
"tower-layer",
|
||||
"tower-service",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tower-layer"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e"
|
||||
|
||||
[[package]]
|
||||
name = "tower-service"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3"
|
||||
|
||||
[[package]]
|
||||
name = "tracing"
|
||||
version = "0.1.41"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0"
|
||||
dependencies = [
|
||||
"pin-project-lite",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
|
||||
dependencies = [
|
||||
"once_cell",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b"
|
||||
|
||||
[[package]]
|
||||
name = "typenum"
|
||||
version = "1.18.0"
|
||||
@ -2394,29 +2025,12 @@ dependencies = [
|
||||
"getrandom 0.3.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "uuid-simd"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b082222b4f6619906941c17eb2297fff4c2fb96cb60164170522942a200bd8"
|
||||
dependencies = [
|
||||
"outref",
|
||||
"uuid",
|
||||
"vsimd",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "version_check"
|
||||
version = "0.9.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
|
||||
|
||||
[[package]]
|
||||
name = "vsimd"
|
||||
version = "0.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.1"
|
||||
@ -2436,15 +2050,6 @@ dependencies = [
|
||||
"winapi-util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "want"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e"
|
||||
dependencies = [
|
||||
"try-lock",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasi"
|
||||
version = "0.11.0+wasi-snapshot-preview1"
|
||||
@ -2474,7 +2079,6 @@ checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
]
|
||||
|
||||
@ -2492,19 +2096,6 @@ dependencies = [
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-futures"
|
||||
version = "0.4.50"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "555d470ec0bc3bb57890405e5d4322cc9ea83cebb085523ced7be4144dac1e61"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"js-sys",
|
||||
"once_cell",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.100"
|
||||
@ -2596,7 +2187,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12342cb4d8e3b046f3d80effd474a7a02447231330ef77d71daa6fbc40681143"
|
||||
dependencies = [
|
||||
"windows-core",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2607,8 +2198,8 @@ checksum = "d2ed2439a290666cd67ecce2b0ffaad89c2a56b976b736e6ece670297897832d"
|
||||
dependencies = [
|
||||
"windows-implement",
|
||||
"windows-interface",
|
||||
"windows-result 0.1.2",
|
||||
"windows-targets 0.52.6",
|
||||
"windows-result",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2633,48 +2224,13 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
|
||||
|
||||
[[package]]
|
||||
name = "windows-registry"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3"
|
||||
dependencies = [
|
||||
"windows-result 0.3.2",
|
||||
"windows-strings",
|
||||
"windows-targets 0.53.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e383302e8ec8515204254685643de10811af0ed97ea37210dc26fb0032647f8"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-result"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-strings"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2683,7 +2239,7 @@ version = "0.52.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2692,7 +2248,7 @@ version = "0.59.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
|
||||
dependencies = [
|
||||
"windows-targets 0.52.6",
|
||||
"windows-targets",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2701,30 +2257,14 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.52.6",
|
||||
"windows_aarch64_msvc 0.52.6",
|
||||
"windows_i686_gnu 0.52.6",
|
||||
"windows_i686_gnullvm 0.52.6",
|
||||
"windows_i686_msvc 0.52.6",
|
||||
"windows_x86_64_gnu 0.52.6",
|
||||
"windows_x86_64_gnullvm 0.52.6",
|
||||
"windows_x86_64_msvc 0.52.6",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-targets"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b1e4c7e8ceaaf9cb7d7507c974735728ab453b67ef8f18febdd7c11fe59dca8b"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm 0.53.0",
|
||||
"windows_aarch64_msvc 0.53.0",
|
||||
"windows_i686_gnu 0.53.0",
|
||||
"windows_i686_gnullvm 0.53.0",
|
||||
"windows_i686_msvc 0.53.0",
|
||||
"windows_x86_64_gnu 0.53.0",
|
||||
"windows_x86_64_gnullvm 0.53.0",
|
||||
"windows_x86_64_msvc 0.53.0",
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_gnullvm",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -2733,96 +2273,48 @@ version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.52.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.53.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486"
|
||||
|
||||
[[package]]
|
||||
name = "winnow"
|
||||
version = "0.7.6"
|
||||
|
||||
@ -7,7 +7,6 @@ edition = "2021"
|
||||
pgrx = "0.14.0"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
jsonschema = "0.29.1"
|
||||
lazy_static = "1.5.0"
|
||||
boon = "0.6.1"
|
||||
|
||||
|
||||
22
flow
22
flow
@ -3,6 +3,7 @@
|
||||
# Flows
|
||||
source ./flows/base
|
||||
source ./flows/git
|
||||
source ./flows/kube
|
||||
source ./flows/packaging
|
||||
source ./flows/rust
|
||||
|
||||
@ -14,21 +15,6 @@ CARGO_DEPENDENCIES=(cargo-pgrx==0.14.0)
|
||||
GITEA_ORGANIZATION="cellular"
|
||||
GITEA_REPOSITORY="jspg"
|
||||
|
||||
env() {
|
||||
# Check if GITEA_TOKEN is set
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
# If not set, try to get it from kubectl
|
||||
GITEA_TOKEN=$(kubectl get secret -n cellular gitea-git -o jsonpath='{.data.token}' | base64 --decode)
|
||||
if [ -z "$GITEA_TOKEN" ]; then
|
||||
error "GITEA_TOKEN is not set and couldn't be retrieved from kubectl" >&2
|
||||
return 2
|
||||
fi
|
||||
export GITEA_TOKEN
|
||||
fi
|
||||
|
||||
success "Environment variables set"
|
||||
}
|
||||
|
||||
pgrx-prepare() {
|
||||
info "Initializing pgrx..."
|
||||
# Explicitly point to the postgresql@${POSTGRES_VERSION} pg_config, don't rely on 'which'
|
||||
@ -131,8 +117,7 @@ jspg-usage() {
|
||||
|
||||
jspg-flow() {
|
||||
case "$1" in
|
||||
env) env; return $?;;
|
||||
prepare) base-flow prepare && cargo-prepare && pgrx-prepare; return $?;;
|
||||
prepare) prepare && cargo-prepare && pgrx-prepare; return $?;;
|
||||
build) build; return $?;;
|
||||
install) install; return $?;;
|
||||
reinstall) clean && install; return $?;;
|
||||
@ -142,5 +127,6 @@ jspg-flow() {
|
||||
esac
|
||||
}
|
||||
|
||||
register-flow "jspg-flow" "jspg-usage"
|
||||
register-flow "jspg-usage" "jspg-flow"
|
||||
|
||||
dispatch "$@"
|
||||
2
flows
2
flows
Submodule flows updated: 3e3954fb79...e154758056
1
rustfmt.toml
Normal file
1
rustfmt.toml
Normal file
@ -0,0 +1 @@
|
||||
tab_spaces = 2
|
||||
745
src/lib.rs
745
src/lib.rs
@ -2,16 +2,27 @@ use pgrx::*;
|
||||
|
||||
pg_module_magic!();
|
||||
|
||||
use serde_json::{json, Value};
|
||||
use std::{collections::HashMap, sync::RwLock};
|
||||
use boon::{Compiler, Schemas, ValidationError, SchemaIndex, CompileError};
|
||||
use boon::{CompileError, Compiler, ErrorKind, SchemaIndex, Schemas, ValidationError, Type, Types};
|
||||
use lazy_static::lazy_static;
|
||||
use serde_json::{json, Value, Number};
|
||||
use std::borrow::Cow;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::{collections::HashMap, sync::RwLock};
|
||||
|
||||
struct BoonCache {
|
||||
schemas: Schemas,
|
||||
id_to_index: HashMap<String, SchemaIndex>,
|
||||
}
|
||||
|
||||
// Structure to hold error information without lifetimes
|
||||
#[derive(Debug)]
|
||||
struct Error {
|
||||
path: String,
|
||||
code: String,
|
||||
message: String,
|
||||
cause: Value, // Changed from String to Value to store JSON
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref SCHEMA_CACHE: RwLock<BoonCache> = RwLock::new(BoonCache {
|
||||
schemas: Schemas::new(),
|
||||
@ -20,22 +31,31 @@ lazy_static! {
|
||||
}
|
||||
|
||||
#[pg_extern(strict)]
|
||||
fn cache_json_schema(schema_id: &str, schema: JsonB) -> JsonB {
|
||||
fn cache_json_schema(schema_id: &str, schema: JsonB, strict: bool) -> JsonB {
|
||||
let mut cache = SCHEMA_CACHE.write().unwrap();
|
||||
let schema_value: Value = schema.0;
|
||||
let mut schema_value: Value = schema.0;
|
||||
let schema_path = format!("urn:{}", schema_id);
|
||||
|
||||
// Apply strict validation to all objects in the schema if requested
|
||||
if strict {
|
||||
apply_strict_validation(&mut schema_value);
|
||||
}
|
||||
|
||||
// Create the boon compiler and enable format assertions
|
||||
let mut compiler = Compiler::new();
|
||||
compiler.enable_format_assertions();
|
||||
|
||||
// Use schema_path when adding the resource
|
||||
if let Err(e) = compiler.add_resource(&schema_path, schema_value.clone()) {
|
||||
return JsonB(json!({
|
||||
"success": false,
|
||||
"error": {
|
||||
"message": format!("Failed to add schema resource '{}': {}", schema_id, e),
|
||||
"schema_path": schema_path
|
||||
"errors": [{
|
||||
"code": "SCHEMA_RESOURCE_ADD_FAILED",
|
||||
"message": format!("Failed to add schema resource '{}'", schema_id),
|
||||
"details": {
|
||||
"schema": schema_id,
|
||||
"cause": format!("{}", e)
|
||||
}
|
||||
}]
|
||||
}));
|
||||
}
|
||||
|
||||
@ -44,117 +64,690 @@ fn cache_json_schema(schema_id: &str, schema: JsonB) -> JsonB {
|
||||
Ok(sch_index) => {
|
||||
// Store the index using the original schema_id as the key
|
||||
cache.id_to_index.insert(schema_id.to_string(), sch_index);
|
||||
JsonB(json!({ "success": true }))
|
||||
JsonB(json!({ "response": "success" }))
|
||||
}
|
||||
Err(e) => {
|
||||
let error = match &e {
|
||||
let errors = match &e {
|
||||
CompileError::ValidationError { url: _url, src } => {
|
||||
// Collect leaf errors from the meta-schema validation failure
|
||||
let mut error_list = Vec::new();
|
||||
collect_leaf_errors(src, &mut error_list);
|
||||
// Return the flat list directly
|
||||
json!(error_list)
|
||||
collect_errors(src, &mut error_list);
|
||||
// Filter and format errors properly - no instance for schema compilation
|
||||
format_errors(error_list, &schema_value, schema_id)
|
||||
}
|
||||
_ => {
|
||||
// Keep existing handling for other compilation errors
|
||||
let _error_type = format!("{:?}", e).split('(').next().unwrap_or("Unknown").to_string();
|
||||
json!({
|
||||
"message": format!("Schema '{}' compilation failed: {}", schema_id, e),
|
||||
"schema_path": schema_path,
|
||||
"detail": format!("{:?}", e),
|
||||
})
|
||||
// Other compilation errors
|
||||
vec![json!({
|
||||
"code": "SCHEMA_COMPILATION_FAILED",
|
||||
"message": format!("Schema '{}' compilation failed", schema_id),
|
||||
"details": {
|
||||
"schema": schema_id,
|
||||
"cause": format!("{:?}", e)
|
||||
}
|
||||
})]
|
||||
}
|
||||
};
|
||||
// Ensure the outer structure remains { success: false, error: ... }
|
||||
JsonB(json!({
|
||||
"success": false,
|
||||
"error": error
|
||||
}))
|
||||
JsonB(json!({ "errors": errors }))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Helper function to apply strict validation to a schema
|
||||
//
|
||||
// This recursively adds unevaluatedProperties: false to object-type schemas,
|
||||
// but SKIPS schemas inside if/then/else to avoid breaking conditional validation.
|
||||
fn apply_strict_validation(schema: &mut Value) {
|
||||
apply_strict_validation_recursive(schema, false);
|
||||
}
|
||||
|
||||
fn apply_strict_validation_recursive(schema: &mut Value, inside_conditional: bool) {
|
||||
match schema {
|
||||
Value::Object(map) => {
|
||||
// Skip adding strict validation if we're inside a conditional
|
||||
if !inside_conditional {
|
||||
// Add strict validation to object schemas only at top level
|
||||
if let Some(Value::String(t)) = map.get("type") {
|
||||
if t == "object" && !map.contains_key("unevaluatedProperties") && !map.contains_key("additionalProperties") {
|
||||
// At top level, use unevaluatedProperties: false
|
||||
// This considers all evaluated properties from all schemas
|
||||
map.insert("unevaluatedProperties".to_string(), Value::Bool(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recurse into all properties
|
||||
for (key, value) in map.iter_mut() {
|
||||
// Mark when we're inside conditional branches
|
||||
let in_conditional = inside_conditional || matches!(key.as_str(), "if" | "then" | "else");
|
||||
apply_strict_validation_recursive(value, in_conditional);
|
||||
}
|
||||
}
|
||||
Value::Array(arr) => {
|
||||
// Recurse into array items
|
||||
for item in arr.iter_mut() {
|
||||
apply_strict_validation_recursive(item, inside_conditional);
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
#[pg_extern(strict, parallel_safe)]
|
||||
fn validate_json_schema(schema_id: &str, instance: JsonB) -> JsonB {
|
||||
let cache = SCHEMA_CACHE.read().unwrap();
|
||||
|
||||
// Lookup uses the original schema_id
|
||||
match cache.id_to_index.get(schema_id) {
|
||||
None => JsonB(json!({
|
||||
"success": false,
|
||||
"error": {
|
||||
"message": format!("Schema with id '{}' not found in cache", schema_id)
|
||||
"errors": [{
|
||||
"code": "SCHEMA_NOT_FOUND",
|
||||
"message": format!("Schema '{}' not found in cache", schema_id),
|
||||
"details": {
|
||||
"schema": schema_id,
|
||||
"cause": "Schema must be cached before validation"
|
||||
}
|
||||
}]
|
||||
})),
|
||||
Some(sch_index) => {
|
||||
let instance_value: Value = instance.0;
|
||||
match cache.schemas.validate(&instance_value, *sch_index) {
|
||||
Ok(_) => JsonB(json!({ "success": true })),
|
||||
Ok(_) => JsonB(json!({ "response": "success" })),
|
||||
Err(validation_error) => {
|
||||
// Collect all leaf errors first
|
||||
let mut raw_error_list = Vec::new();
|
||||
collect_leaf_errors(&validation_error, &mut raw_error_list);
|
||||
|
||||
// Filter the errors (e.g., deduplicate by instance_path)
|
||||
let filtered_error_list = filter_boon_errors(raw_error_list);
|
||||
|
||||
JsonB(json!({
|
||||
"success": false,
|
||||
"error": filtered_error_list // Return the filtered list
|
||||
}))
|
||||
let mut error_list = Vec::new();
|
||||
collect_errors(&validation_error, &mut error_list);
|
||||
let errors = format_errors(error_list, &instance_value, schema_id);
|
||||
// Filter out FALSE_SCHEMA errors if there are other validation errors
|
||||
let filtered_errors = filter_false_schema_errors(errors);
|
||||
JsonB(json!({ "errors": filtered_errors }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Recursively collects leaf errors into a flat list
|
||||
fn collect_leaf_errors(error: &ValidationError, errors_list: &mut Vec<Value>) {
|
||||
if error.causes.is_empty() {
|
||||
let default_message = format!("{}", error);
|
||||
let message = if let Some(start_index) = default_message.find("': ") {
|
||||
default_message[start_index + 3..].to_string()
|
||||
} else {
|
||||
default_message
|
||||
// Recursively collects validation errors
|
||||
fn collect_errors(error: &ValidationError, errors_list: &mut Vec<Error>) {
|
||||
// Check if this is a structural error that we should skip
|
||||
let is_structural = matches!(
|
||||
&error.kind,
|
||||
ErrorKind::Group | ErrorKind::AllOf | ErrorKind::AnyOf | ErrorKind::Not | ErrorKind::OneOf(_)
|
||||
);
|
||||
|
||||
// Special handling for FalseSchema - if it has causes, use those instead
|
||||
if matches!(&error.kind, ErrorKind::FalseSchema) {
|
||||
if !error.causes.is_empty() {
|
||||
// FalseSchema often wraps more specific errors in if/then conditionals
|
||||
for cause in &error.causes {
|
||||
collect_errors(cause, errors_list);
|
||||
}
|
||||
return;
|
||||
}
|
||||
// If FalseSchema has no causes, it's likely from unevaluatedProperties
|
||||
// We'll handle it as a leaf error below
|
||||
}
|
||||
|
||||
if error.causes.is_empty() && !is_structural {
|
||||
let base_path = error.instance_location.to_string();
|
||||
|
||||
// Match on error kind and handle each type
|
||||
let errors_to_add = match &error.kind {
|
||||
ErrorKind::Type { got, want } => handle_type_error(&base_path, got, want),
|
||||
ErrorKind::Required { want } => handle_required_error(&base_path, want),
|
||||
ErrorKind::Dependency { prop, missing } => handle_dependency_error(&base_path, prop, missing, false),
|
||||
ErrorKind::DependentRequired { prop, missing } => handle_dependency_error(&base_path, prop, missing, true),
|
||||
ErrorKind::AdditionalProperties { got } => handle_additional_properties_error(&base_path, got),
|
||||
ErrorKind::Enum { want } => handle_enum_error(&base_path, want),
|
||||
ErrorKind::Const { want } => handle_const_error(&base_path, want),
|
||||
ErrorKind::MinLength { got, want } => handle_min_length_error(&base_path, *got, *want),
|
||||
ErrorKind::MaxLength { got, want } => handle_max_length_error(&base_path, *got, *want),
|
||||
ErrorKind::Pattern { got, want } => handle_pattern_error(&base_path, got, want),
|
||||
ErrorKind::Minimum { got, want } => handle_minimum_error(&base_path, got, want),
|
||||
ErrorKind::Maximum { got, want } => handle_maximum_error(&base_path, got, want),
|
||||
ErrorKind::ExclusiveMinimum { got, want } => handle_exclusive_minimum_error(&base_path, got, want),
|
||||
ErrorKind::ExclusiveMaximum { got, want } => handle_exclusive_maximum_error(&base_path, got, want),
|
||||
ErrorKind::MultipleOf { got, want } => handle_multiple_of_error(&base_path, got, want),
|
||||
ErrorKind::MinItems { got, want } => handle_min_items_error(&base_path, *got, *want),
|
||||
ErrorKind::MaxItems { got, want } => handle_max_items_error(&base_path, *got, *want),
|
||||
ErrorKind::UniqueItems { got } => handle_unique_items_error(&base_path, got),
|
||||
ErrorKind::MinProperties { got, want } => handle_min_properties_error(&base_path, *got, *want),
|
||||
ErrorKind::MaxProperties { got, want } => handle_max_properties_error(&base_path, *got, *want),
|
||||
ErrorKind::AdditionalItems { got } => handle_additional_items_error(&base_path, *got),
|
||||
ErrorKind::Format { want, got, err } => handle_format_error(&base_path, want, got, err),
|
||||
ErrorKind::PropertyName { prop } => handle_property_name_error(&base_path, prop),
|
||||
ErrorKind::Contains => handle_contains_error(&base_path),
|
||||
ErrorKind::MinContains { got, want } => handle_min_contains_error(&base_path, got, *want),
|
||||
ErrorKind::MaxContains { got, want } => handle_max_contains_error(&base_path, got, *want),
|
||||
ErrorKind::ContentEncoding { want, err } => handle_content_encoding_error(&base_path, want, err),
|
||||
ErrorKind::ContentMediaType { want, err, .. } => handle_content_media_type_error(&base_path, want, err),
|
||||
ErrorKind::FalseSchema => handle_false_schema_error(&base_path),
|
||||
ErrorKind::Not => handle_not_error(&base_path),
|
||||
ErrorKind::RefCycle { url, kw_loc1, kw_loc2 } => handle_ref_cycle_error(&base_path, url, kw_loc1, kw_loc2),
|
||||
ErrorKind::Reference { kw, url } => handle_reference_error(&base_path, kw, url),
|
||||
ErrorKind::Schema { url } => handle_schema_error(&base_path, url),
|
||||
ErrorKind::ContentSchema => handle_content_schema_error(&base_path),
|
||||
ErrorKind::Group => handle_group_error(&base_path),
|
||||
ErrorKind::AllOf => handle_all_of_error(&base_path),
|
||||
ErrorKind::AnyOf => handle_any_of_error(&base_path),
|
||||
ErrorKind::OneOf(matched) => handle_one_of_error(&base_path, matched),
|
||||
};
|
||||
|
||||
errors_list.push(json!({
|
||||
"message": message,
|
||||
"schema_path": error.schema_url.to_string(),
|
||||
"instance_path": error.instance_location.to_string(),
|
||||
}));
|
||||
// Add all generated errors
|
||||
for error in errors_to_add {
|
||||
errors_list.push(error);
|
||||
}
|
||||
} else {
|
||||
// Recurse into causes
|
||||
for cause in &error.causes {
|
||||
collect_leaf_errors(cause, errors_list);
|
||||
collect_errors(cause, errors_list);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Filters collected errors, e.g., deduplicating by instance_path
|
||||
fn filter_boon_errors(raw_errors: Vec<Value>) -> Vec<Value> {
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map::Entry;
|
||||
// Handler functions for each error kind
|
||||
fn handle_type_error(base_path: &str, got: &Type, want: &Types) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "TYPE_MISMATCH".to_string(),
|
||||
message: format!("Expected {} but got {}",
|
||||
want.iter().map(|t| t.to_string()).collect::<Vec<_>>().join(" or "),
|
||||
got
|
||||
),
|
||||
cause: json!({
|
||||
"got": got.to_string(),
|
||||
"want": want.iter().map(|t| t.to_string()).collect::<Vec<_>>()
|
||||
}),
|
||||
}]
|
||||
}
|
||||
|
||||
// Use a HashMap to keep only the first error for each instance_path
|
||||
fn handle_required_error(base_path: &str, want: &[&str]) -> Vec<Error> {
|
||||
// Create a separate error for each missing required field
|
||||
want.iter().map(|missing_field| {
|
||||
let field_path = if base_path.is_empty() {
|
||||
format!("/{}", missing_field)
|
||||
} else {
|
||||
format!("{}/{}", base_path, missing_field)
|
||||
};
|
||||
|
||||
Error {
|
||||
path: field_path,
|
||||
code: "REQUIRED_FIELD_MISSING".to_string(),
|
||||
message: format!("Required field '{}' is missing", missing_field),
|
||||
cause: json!({ "want": [missing_field] }),
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn handle_dependency_error(base_path: &str, prop: &str, missing: &[&str], is_dependent_required: bool) -> Vec<Error> {
|
||||
// Create a separate error for each missing field
|
||||
missing.iter().map(|missing_field| {
|
||||
let field_path = if base_path.is_empty() {
|
||||
format!("/{}", missing_field)
|
||||
} else {
|
||||
format!("{}/{}", base_path, missing_field)
|
||||
};
|
||||
|
||||
let (code, message) = if is_dependent_required {
|
||||
(
|
||||
"DEPENDENT_REQUIRED_MISSING".to_string(),
|
||||
format!("Field '{}' is required when '{}' is present", missing_field, prop),
|
||||
)
|
||||
} else {
|
||||
(
|
||||
"DEPENDENCY_FAILED".to_string(),
|
||||
format!("Field '{}' is required when '{}' is present", missing_field, prop),
|
||||
)
|
||||
};
|
||||
|
||||
Error {
|
||||
path: field_path,
|
||||
code,
|
||||
message,
|
||||
cause: json!({ "prop": prop, "missing": [missing_field] }),
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn handle_additional_properties_error(base_path: &str, got: &[Cow<str>]) -> Vec<Error> {
|
||||
// Create a separate error for each additional property that's not allowed
|
||||
got.iter().map(|extra_prop| {
|
||||
let field_path = if base_path.is_empty() {
|
||||
format!("/{}", extra_prop)
|
||||
} else {
|
||||
format!("{}/{}", base_path, extra_prop)
|
||||
};
|
||||
|
||||
Error {
|
||||
path: field_path,
|
||||
code: "ADDITIONAL_PROPERTIES_NOT_ALLOWED".to_string(),
|
||||
message: format!("Property '{}' is not allowed", extra_prop),
|
||||
cause: json!({ "got": [extra_prop.to_string()] }),
|
||||
}
|
||||
}).collect()
|
||||
}
|
||||
|
||||
fn handle_enum_error(base_path: &str, want: &[Value]) -> Vec<Error> {
|
||||
let message = if want.len() == 1 {
|
||||
format!("Value must be {}", serde_json::to_string(&want[0]).unwrap_or_else(|_| "unknown".to_string()))
|
||||
} else {
|
||||
format!("Value must be one of: {}",
|
||||
want.iter()
|
||||
.map(|v| serde_json::to_string(v).unwrap_or_else(|_| "unknown".to_string()))
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ")
|
||||
)
|
||||
};
|
||||
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "ENUM_VIOLATED".to_string(),
|
||||
message,
|
||||
cause: json!({ "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_const_error(base_path: &str, want: &Value) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "CONST_VIOLATED".to_string(),
|
||||
message: format!("Value must be exactly {}", serde_json::to_string(want).unwrap_or_else(|_| "unknown".to_string())),
|
||||
cause: json!({ "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_min_length_error(base_path: &str, got: usize, want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MIN_LENGTH_VIOLATED".to_string(),
|
||||
message: format!("String length must be at least {} characters, but got {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_max_length_error(base_path: &str, got: usize, want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MAX_LENGTH_VIOLATED".to_string(),
|
||||
message: format!("String length must be at most {} characters, but got {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_pattern_error(base_path: &str, got: &Cow<str>, want: &str) -> Vec<Error> {
|
||||
let display_value = if got.len() > 50 {
|
||||
format!("{}...", &got[..50])
|
||||
} else {
|
||||
got.to_string()
|
||||
};
|
||||
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "PATTERN_VIOLATED".to_string(),
|
||||
message: format!("Value '{}' does not match pattern '{}'", display_value, want),
|
||||
cause: json!({ "got": got.to_string(), "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_minimum_error(base_path: &str, got: &Cow<Number>, want: &Number) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MINIMUM_VIOLATED".to_string(),
|
||||
message: format!("Value must be at least {}, but got {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_maximum_error(base_path: &str, got: &Cow<Number>, want: &Number) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MAXIMUM_VIOLATED".to_string(),
|
||||
message: format!("Value must be at most {}, but got {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_exclusive_minimum_error(base_path: &str, got: &Cow<Number>, want: &Number) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "EXCLUSIVE_MINIMUM_VIOLATED".to_string(),
|
||||
message: format!("Value must be greater than {}, but got {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_exclusive_maximum_error(base_path: &str, got: &Cow<Number>, want: &Number) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "EXCLUSIVE_MAXIMUM_VIOLATED".to_string(),
|
||||
message: format!("Value must be less than {}, but got {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_multiple_of_error(base_path: &str, got: &Cow<Number>, want: &Number) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MULTIPLE_OF_VIOLATED".to_string(),
|
||||
message: format!("{} is not a multiple of {}", got, want),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_min_items_error(base_path: &str, got: usize, want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MIN_ITEMS_VIOLATED".to_string(),
|
||||
message: format!("Array must have at least {} items, but has {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_max_items_error(base_path: &str, got: usize, want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MAX_ITEMS_VIOLATED".to_string(),
|
||||
message: format!("Array must have at most {} items, but has {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_unique_items_error(base_path: &str, got: &[usize; 2]) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "UNIQUE_ITEMS_VIOLATED".to_string(),
|
||||
message: format!("Array items at positions {} and {} are duplicates", got[0], got[1]),
|
||||
cause: json!({ "got": got }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_min_properties_error(base_path: &str, got: usize, want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MIN_PROPERTIES_VIOLATED".to_string(),
|
||||
message: format!("Object must have at least {} properties, but has {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_max_properties_error(base_path: &str, got: usize, want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MAX_PROPERTIES_VIOLATED".to_string(),
|
||||
message: format!("Object must have at most {} properties, but has {}", want, got),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_additional_items_error(base_path: &str, got: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "ADDITIONAL_ITEMS_NOT_ALLOWED".to_string(),
|
||||
message: format!("Last {} array items are not allowed", got),
|
||||
cause: json!({ "got": got }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_format_error(base_path: &str, want: &str, got: &Cow<Value>, err: &Box<dyn std::error::Error>) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "FORMAT_INVALID".to_string(),
|
||||
message: format!("Value {} is not a valid {} format",
|
||||
serde_json::to_string(got.as_ref()).unwrap_or_else(|_| "unknown".to_string()),
|
||||
want
|
||||
),
|
||||
cause: json!({ "got": got, "want": want, "err": err.to_string() }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_property_name_error(base_path: &str, prop: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "INVALID_PROPERTY_NAME".to_string(),
|
||||
message: format!("Property name '{}' is invalid", prop),
|
||||
cause: json!({ "prop": prop }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_contains_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "CONTAINS_FAILED".to_string(),
|
||||
message: "No array items match the required schema".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_min_contains_error(base_path: &str, got: &[usize], want: usize) -> Vec<Error> {
|
||||
let message = if got.is_empty() {
|
||||
format!("At least {} array items must match the schema, but none do", want)
|
||||
} else {
|
||||
format!("At least {} array items must match the schema, but only {} do (at positions {})",
|
||||
want,
|
||||
got.len(),
|
||||
got.iter().map(|i| i.to_string()).collect::<Vec<_>>().join(", ")
|
||||
)
|
||||
};
|
||||
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MIN_CONTAINS_VIOLATED".to_string(),
|
||||
message,
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_max_contains_error(base_path: &str, got: &[usize], want: usize) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "MAX_CONTAINS_VIOLATED".to_string(),
|
||||
message: format!("At most {} array items can match the schema, but {} do (at positions {})",
|
||||
want,
|
||||
got.len(),
|
||||
got.iter().map(|i| i.to_string()).collect::<Vec<_>>().join(", ")
|
||||
),
|
||||
cause: json!({ "got": got, "want": want }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_content_encoding_error(base_path: &str, want: &str, err: &Box<dyn std::error::Error>) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "CONTENT_ENCODING_INVALID".to_string(),
|
||||
message: format!("Content is not valid {} encoding: {}", want, err),
|
||||
cause: json!({ "want": want, "err": err.to_string() }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_content_media_type_error(base_path: &str, want: &str, err: &Box<dyn std::error::Error>) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "CONTENT_MEDIA_TYPE_INVALID".to_string(),
|
||||
message: format!("Content is not valid {} media type: {}", want, err),
|
||||
cause: json!({ "want": want, "err": err.to_string() }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_false_schema_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "FALSE_SCHEMA".to_string(),
|
||||
message: "This schema always fails validation".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_not_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "NOT_VIOLATED".to_string(),
|
||||
message: "Value matches a schema that it should not match".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_ref_cycle_error(base_path: &str, url: &str, kw_loc1: &str, kw_loc2: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "REFERENCE_CYCLE".to_string(),
|
||||
message: format!("Reference cycle detected: both '{}' and '{}' resolve to '{}'", kw_loc1, kw_loc2, url),
|
||||
cause: json!({ "url": url, "kw_loc1": kw_loc1, "kw_loc2": kw_loc2 }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_reference_error(base_path: &str, kw: &str, url: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "REFERENCE_FAILED".to_string(),
|
||||
message: format!("{} reference to '{}' failed validation", kw, url),
|
||||
cause: json!({ "kw": kw, "url": url }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_schema_error(base_path: &str, url: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "SCHEMA_FAILED".to_string(),
|
||||
message: format!("Schema '{}' validation failed", url),
|
||||
cause: json!({ "url": url }),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_content_schema_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "CONTENT_SCHEMA_FAILED".to_string(),
|
||||
message: "Content schema validation failed".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_group_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "VALIDATION_FAILED".to_string(),
|
||||
message: "Validation failed".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_all_of_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "ALL_OF_VIOLATED".to_string(),
|
||||
message: "Value does not match all required schemas".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_any_of_error(base_path: &str) -> Vec<Error> {
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "ANY_OF_VIOLATED".to_string(),
|
||||
message: "Value does not match any of the allowed schemas".to_string(),
|
||||
cause: json!({}),
|
||||
}]
|
||||
}
|
||||
|
||||
fn handle_one_of_error(base_path: &str, matched: &Option<(usize, usize)>) -> Vec<Error> {
|
||||
let (message, cause) = match matched {
|
||||
None => (
|
||||
"Value must match exactly one schema, but matches none".to_string(),
|
||||
json!({ "matched_indices": null })
|
||||
),
|
||||
Some((i, j)) => (
|
||||
format!("Value must match exactly one schema, but matches schemas at positions {} and {}", i, j),
|
||||
json!({ "matched_indices": [i, j] })
|
||||
),
|
||||
};
|
||||
|
||||
vec![Error {
|
||||
path: base_path.to_string(),
|
||||
code: "ONE_OF_VIOLATED".to_string(),
|
||||
message,
|
||||
cause,
|
||||
}]
|
||||
}
|
||||
|
||||
// Filter out FALSE_SCHEMA errors if there are other validation errors
|
||||
fn filter_false_schema_errors(errors: Vec<Value>) -> Vec<Value> {
|
||||
// Check if there are any non-FALSE_SCHEMA errors
|
||||
let has_non_false_schema = errors.iter().any(|e| {
|
||||
e.get("code")
|
||||
.and_then(|c| c.as_str())
|
||||
.map(|code| code != "FALSE_SCHEMA")
|
||||
.unwrap_or(false)
|
||||
});
|
||||
|
||||
if has_non_false_schema {
|
||||
// Filter out FALSE_SCHEMA errors
|
||||
errors.into_iter()
|
||||
.filter(|e| {
|
||||
e.get("code")
|
||||
.and_then(|c| c.as_str())
|
||||
.map(|code| code != "FALSE_SCHEMA")
|
||||
.unwrap_or(true)
|
||||
})
|
||||
.collect()
|
||||
} else {
|
||||
// Keep all errors (they're all FALSE_SCHEMA)
|
||||
errors
|
||||
}
|
||||
}
|
||||
|
||||
// Formats errors according to DropError structure
|
||||
fn format_errors(errors: Vec<Error>, instance: &Value, schema_id: &str) -> Vec<Value> {
|
||||
// Deduplicate by instance_path and format as DropError
|
||||
let mut unique_errors: HashMap<String, Value> = HashMap::new();
|
||||
|
||||
for error_value in raw_errors {
|
||||
if let Some(instance_path_value) = error_value.get("instance_path") {
|
||||
if let Some(instance_path_str) = instance_path_value.as_str() {
|
||||
// Use Entry API to insert only if the key is not present
|
||||
if let Entry::Vacant(entry) = unique_errors.entry(instance_path_str.to_string()) {
|
||||
entry.insert(error_value);
|
||||
for error in errors {
|
||||
if let Entry::Vacant(entry) = unique_errors.entry(error.path.clone()) {
|
||||
// Extract the failing value from the instance
|
||||
let failing_value = extract_value_at_path(instance, &error.path);
|
||||
entry.insert(json!({
|
||||
"code": error.code,
|
||||
"message": error.message,
|
||||
"details": {
|
||||
"path": error.path,
|
||||
"context": failing_value,
|
||||
"cause": error.cause,
|
||||
"schema": schema_id
|
||||
}
|
||||
}));
|
||||
}
|
||||
}
|
||||
// If error doesn't have instance_path or it's not a string, we might ignore it or handle differently.
|
||||
// For now, we implicitly ignore errors without a valid string instance_path for deduplication.
|
||||
}
|
||||
|
||||
// Collect the unique errors from the map values
|
||||
unique_errors.into_values().collect()
|
||||
}
|
||||
|
||||
// Helper function to extract value at a JSON pointer path
|
||||
fn extract_value_at_path(instance: &Value, path: &str) -> Value {
|
||||
let parts: Vec<&str> = path.split('/').filter(|s| !s.is_empty()).collect();
|
||||
let mut current = instance;
|
||||
|
||||
for part in parts {
|
||||
match current {
|
||||
Value::Object(map) => {
|
||||
if let Some(value) = map.get(part) {
|
||||
current = value;
|
||||
} else {
|
||||
return Value::Null;
|
||||
}
|
||||
}
|
||||
Value::Array(arr) => {
|
||||
if let Ok(index) = part.parse::<usize>() {
|
||||
if let Some(value) = arr.get(index) {
|
||||
current = value;
|
||||
} else {
|
||||
return Value::Null;
|
||||
}
|
||||
} else {
|
||||
return Value::Null;
|
||||
}
|
||||
}
|
||||
_ => return Value::Null,
|
||||
}
|
||||
}
|
||||
|
||||
current.clone()
|
||||
}
|
||||
|
||||
#[pg_extern(strict, parallel_safe)]
|
||||
fn json_schema_cached(schema_id: &str) -> bool {
|
||||
let cache = SCHEMA_CACHE.read().unwrap();
|
||||
@ -162,19 +755,20 @@ fn json_schema_cached(schema_id: &str) -> bool {
|
||||
}
|
||||
|
||||
#[pg_extern(strict)]
|
||||
fn clear_json_schemas() {
|
||||
fn clear_json_schemas() -> JsonB {
|
||||
let mut cache = SCHEMA_CACHE.write().unwrap();
|
||||
*cache = BoonCache {
|
||||
schemas: Schemas::new(),
|
||||
id_to_index: HashMap::new(),
|
||||
};
|
||||
JsonB(json!({ "response": "success" }))
|
||||
}
|
||||
|
||||
#[pg_extern(strict, parallel_safe)]
|
||||
fn show_json_schemas() -> Vec<String> {
|
||||
fn show_json_schemas() -> JsonB {
|
||||
let cache = SCHEMA_CACHE.read().unwrap();
|
||||
let ids: Vec<String> = cache.id_to_index.keys().cloned().collect();
|
||||
ids
|
||||
JsonB(json!({ "response": ids }))
|
||||
}
|
||||
|
||||
/// This module is required by `cargo pgrx test` invocations.
|
||||
@ -192,7 +786,6 @@ pub mod pg_test {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[cfg(any(test, feature = "pg_test"))]
|
||||
#[pg_schema]
|
||||
mod tests {
|
||||
|
||||
1136
src/tests.rs
1136
src/tests.rs
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user