chore: checkpoint before Python removal

This commit is contained in:
2026-03-26 22:33:59 +00:00
parent 683cec9307
commit e568ddf82a
29972 changed files with 11269302 additions and 2 deletions

222
vendor/json-patch/tests/basic.rs vendored Normal file
View File

@@ -0,0 +1,222 @@
use json_patch::{
AddOperation, CopyOperation, MoveOperation, Patch, PatchOperation, RemoveOperation,
ReplaceOperation, TestOperation,
};
use serde_json::{from_str, from_value, json, Value};
#[test]
fn parse_from_value() {
let json = json!([{"op": "add", "path": "/a/b", "value": 1}, {"op": "remove", "path": "/c"}]);
let patch: Patch = from_value(json).unwrap();
assert_eq!(
patch,
Patch(vec![
PatchOperation::Add(AddOperation {
path: "/a/b".parse().unwrap(),
value: Value::from(1),
}),
PatchOperation::Remove(RemoveOperation {
path: "/c".parse().unwrap(),
}),
])
);
let _patch: Patch =
from_str(r#"[{"op": "add", "path": "/a/b", "value": 1}, {"op": "remove", "path": "/c"}]"#)
.unwrap();
}
#[test]
fn parse_from_string() {
let patch: Patch =
from_str(r#"[{"op": "add", "path": "/a/b", "value": 1}, {"op": "remove", "path": "/c"}]"#)
.unwrap();
assert_eq!(
patch,
Patch(vec![
PatchOperation::Add(AddOperation {
path: "/a/b".parse().unwrap(),
value: Value::from(1),
}),
PatchOperation::Remove(RemoveOperation {
path: "/c".parse().unwrap(),
}),
])
);
}
#[test]
fn serialize_patch() {
let s = r#"[{"op":"add","path":"/a/b","value":1},{"op":"remove","path":"/c"}]"#;
let patch: Patch = from_str(s).unwrap();
let serialized = serde_json::to_string(&patch).unwrap();
assert_eq!(serialized, s);
}
#[test]
fn display_add_operation() {
let op = PatchOperation::Add(AddOperation {
path: "/a/b/c".parse().unwrap(),
value: json!(["hello", "bye"]),
});
assert_eq!(
op.to_string(),
r#"{"op":"add","path":"/a/b/c","value":["hello","bye"]}"#
);
assert_eq!(
format!("{:#}", op),
r#"{
"op": "add",
"path": "/a/b/c",
"value": [
"hello",
"bye"
]
}"#
);
}
#[test]
fn display_remove_operation() {
let op = PatchOperation::Remove(RemoveOperation {
path: "/a/b/c".parse().unwrap(),
});
assert_eq!(op.to_string(), r#"{"op":"remove","path":"/a/b/c"}"#);
assert_eq!(
format!("{:#}", op),
r#"{
"op": "remove",
"path": "/a/b/c"
}"#
);
}
#[test]
fn display_replace_operation() {
let op = PatchOperation::Replace(ReplaceOperation {
path: "/a/b/c".parse().unwrap(),
value: json!(42),
});
assert_eq!(
op.to_string(),
r#"{"op":"replace","path":"/a/b/c","value":42}"#
);
assert_eq!(
format!("{:#}", op),
r#"{
"op": "replace",
"path": "/a/b/c",
"value": 42
}"#
);
}
#[test]
fn display_move_operation() {
let op = PatchOperation::Move(MoveOperation {
from: "/a/b/c".parse().unwrap(),
path: "/a/b/d".parse().unwrap(),
});
assert_eq!(
op.to_string(),
r#"{"op":"move","from":"/a/b/c","path":"/a/b/d"}"#
);
assert_eq!(
format!("{:#}", op),
r#"{
"op": "move",
"from": "/a/b/c",
"path": "/a/b/d"
}"#
);
}
#[test]
fn display_copy_operation() {
let op = PatchOperation::Copy(CopyOperation {
from: "/a/b/d".parse().unwrap(),
path: "/a/b/e".parse().unwrap(),
});
assert_eq!(
op.to_string(),
r#"{"op":"copy","from":"/a/b/d","path":"/a/b/e"}"#
);
assert_eq!(
format!("{:#}", op),
r#"{
"op": "copy",
"from": "/a/b/d",
"path": "/a/b/e"
}"#
);
}
#[test]
fn display_test_operation() {
let op = PatchOperation::Test(TestOperation {
path: "/a/b/c".parse().unwrap(),
value: json!("hello"),
});
assert_eq!(
op.to_string(),
r#"{"op":"test","path":"/a/b/c","value":"hello"}"#
);
assert_eq!(
format!("{:#}", op),
r#"{
"op": "test",
"path": "/a/b/c",
"value": "hello"
}"#
);
}
#[test]
fn display_patch() {
let patch = Patch(vec![
PatchOperation::Add(AddOperation {
path: "/a/b/c".parse().unwrap(),
value: json!(["hello", "bye"]),
}),
PatchOperation::Remove(RemoveOperation {
path: "/a/b/c".parse().unwrap(),
}),
]);
assert_eq!(
patch.to_string(),
r#"[{"op":"add","path":"/a/b/c","value":["hello","bye"]},{"op":"remove","path":"/a/b/c"}]"#
);
assert_eq!(
format!("{:#}", patch),
r#"[
{
"op": "add",
"path": "/a/b/c",
"value": [
"hello",
"bye"
]
},
{
"op": "remove",
"path": "/a/b/c"
}
]"#
);
}
#[test]
fn display_patch_default() {
let patch = Patch::default();
assert_eq!(patch.to_string(), r#"[]"#);
}
#[test]
fn display_patch_operation_default() {
let op = PatchOperation::default();
assert_eq!(op.to_string(), r#"{"op":"test","path":"","value":null}"#);
}

126
vendor/json-patch/tests/errors.yaml vendored Normal file
View File

@@ -0,0 +1,126 @@
- doc: &1
first: "Hello"
second: "Bye"
third:
- "first"
- "second"
patch:
- op: add
path: "/first"
value: "Hello!!!"
- op: add
path: "/third/00"
value: "value"
error: "operation '/1' failed at path '/third/00': path is invalid"
- doc: *1
patch:
- op: add
path: "/third/01"
value: "value"
error: "operation '/0' failed at path '/third/01': path is invalid"
- doc: *1
patch:
- op: add
path: "/third/1~1"
value: "value"
error: "operation '/0' failed at path '/third/1~1': path is invalid"
- doc: *1
patch:
- op: add
path: "/third/1.0"
value: "value"
error: "operation '/0' failed at path '/third/1.0': path is invalid"
- doc: *1
patch:
- op: add
path: "/third/1e2"
value: "value"
error: "operation '/0' failed at path '/third/1e2': path is invalid"
- doc: *1
patch:
- op: add
path: "/third/+1"
value: "value"
error: "operation '/0' failed at path '/third/+1': path is invalid"
- doc: *1
patch:
- op: copy
from: "/third/1~1"
path: "/fourth"
error: 'operation ''/0'' failed at path ''/fourth'': "from" path is invalid'
- doc: *1
patch:
- op: move
from: "/third/1~1"
path: "/fourth"
error: 'operation ''/0'' failed at path ''/fourth'': "from" path is invalid'
- doc: *1
patch:
- op: move
from: "/third"
path: "/third/0"
error: "operation '/0' failed at path '/third/0': cannot move the value inside itself"
- doc: *1
patch:
- op: add
path: "/invalid/add/path"
value: true
error: "operation '/0' failed at path '/invalid/add/path': path is invalid"
- doc: *1
patch:
- op: remove
path: "/invalid/remove/path"
value: true
error: "operation '/0' failed at path '/invalid/remove/path': path is invalid"
- doc: *1
patch:
- op: replace
path: "/invalid/replace/path"
value: true
error: "operation '/0' failed at path '/invalid/replace/path': path is invalid"
- doc: *1
patch:
- op: test
path: "/invalid/test/path"
value: true
error: "operation '/0' failed at path '/invalid/test/path': path is invalid"
- doc: *1
patch:
- op: add
path: "first"
value: true
error: "json pointer failed to parse; does not start with a slash ('/') and is not empty"
- doc: *1
patch:
- op: replace
path: "first"
value: true
error: "json pointer failed to parse; does not start with a slash ('/') and is not empty"
- doc: *1
patch:
- op: remove
path: "first"
value: true
error: "json pointer failed to parse; does not start with a slash ('/') and is not empty"
- doc: *1
patch:
- op: add
path: "/first/add_to_primitive"
value: true
error: "operation '/0' failed at path '/first/add_to_primitive': path is invalid"
- doc: *1
patch:
- op: remove
path: "/remove_non_existent"
error: "operation '/0' failed at path '/remove_non_existent': path is invalid"
- doc: *1
patch:
- op: remove
path: "/first/remove_from_primitive"
error: "operation '/0' failed at path '/first/remove_from_primitive': path is invalid"
- doc: *1
patch:
- op: test
path: "/first"
value: "Other"
error: "operation '/0' failed at path '/first': value did not match"

149
vendor/json-patch/tests/schemars.json vendored Normal file
View File

@@ -0,0 +1,149 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "PatchOperation",
"description": "JSON Patch single patch operation",
"oneOf": [
{
"description": "'add' operation",
"type": "object",
"required": [
"op",
"path",
"value"
],
"properties": {
"op": {
"type": "string",
"enum": [
"add"
]
},
"path": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location within the target document where the operation is performed.",
"type": "string"
},
"value": {
"description": "Value to add to the target location."
}
}
},
{
"description": "'remove' operation",
"type": "object",
"required": [
"op",
"path"
],
"properties": {
"op": {
"type": "string",
"enum": [
"remove"
]
},
"path": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location within the target document where the operation is performed.",
"type": "string"
}
}
},
{
"description": "'replace' operation",
"type": "object",
"required": [
"op",
"path",
"value"
],
"properties": {
"op": {
"type": "string",
"enum": [
"replace"
]
},
"path": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location within the target document where the operation is performed.",
"type": "string"
},
"value": {
"description": "Value to replace with."
}
}
},
{
"description": "'move' operation",
"type": "object",
"required": [
"from",
"op",
"path"
],
"properties": {
"from": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location to move value from.",
"type": "string"
},
"op": {
"type": "string",
"enum": [
"move"
]
},
"path": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location within the target document where the operation is performed.",
"type": "string"
}
}
},
{
"description": "'copy' operation",
"type": "object",
"required": [
"from",
"op",
"path"
],
"properties": {
"from": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location to copy value from.",
"type": "string"
},
"op": {
"type": "string",
"enum": [
"copy"
]
},
"path": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location within the target document where the operation is performed.",
"type": "string"
}
}
},
{
"description": "'test' operation",
"type": "object",
"required": [
"op",
"path",
"value"
],
"properties": {
"op": {
"type": "string",
"enum": [
"test"
]
},
"path": {
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location within the target document where the operation is performed.",
"type": "string"
},
"value": {
"description": "Value to test against."
}
}
}
]
}

9
vendor/json-patch/tests/schemars.rs vendored Normal file
View File

@@ -0,0 +1,9 @@
#[cfg(feature = "schemars")]
#[test]
fn schema() {
use json_patch::*;
let schema = schemars::schema_for!(PatchOperation);
let json = serde_json::to_string_pretty(&schema).unwrap();
expectorate::assert_contents("tests/schemars.json", &json);
}

133
vendor/json-patch/tests/suite.rs vendored Normal file
View File

@@ -0,0 +1,133 @@
use json_patch::Patch;
use serde::Deserialize;
use serde_json::Value;
#[test]
fn errors() {
run_specs("tests/errors.yaml", Errors::ExactMatch, PatchKind::Patch);
}
#[test]
fn tests() {
run_specs("specs/tests.json", Errors::IgnoreContent, PatchKind::Patch);
}
#[test]
fn spec_tests() {
run_specs(
"specs/spec_tests.json",
Errors::IgnoreContent,
PatchKind::Patch,
);
}
#[test]
fn revert_tests() {
run_specs(
"specs/revert_tests.json",
Errors::IgnoreContent,
PatchKind::Patch,
);
}
#[test]
fn merge_tests() {
run_specs(
"specs/merge_tests.json",
Errors::IgnoreContent,
PatchKind::MergePatch,
);
}
#[derive(PartialEq, Eq, Clone, Copy)]
enum Errors {
ExactMatch,
IgnoreContent,
}
#[derive(PartialEq, Eq, Clone, Copy)]
enum PatchKind {
Patch,
MergePatch,
}
#[derive(Debug, Deserialize)]
struct PatchTestCase {
comment: Option<String>,
doc: Value,
patch: Value,
expected: Option<Value>,
error: Option<String>,
#[serde(default)]
disabled: bool,
}
fn run_patch_test_case(tc: &PatchTestCase, kind: PatchKind) -> Result<Value, String> {
let mut actual = tc.doc.clone();
if kind == PatchKind::MergePatch {
json_patch::merge(&mut actual, &tc.patch);
return Ok(actual);
}
// Patch and verify that in case of error document wasn't changed
let patch: Patch = serde_json::from_value(tc.patch.clone()).map_err(|err| err.to_string())?;
json_patch::patch(&mut actual, &patch)
.inspect_err(|_| {
assert_eq!(
tc.doc, actual,
"no changes should be made to the original document"
);
})
.map_err(|err| err.to_string())?;
Ok(actual)
}
fn run_specs(path: &str, errors: Errors, kind: PatchKind) {
let cases = std::fs::read_to_string(path).unwrap();
let is_yaml = path.ends_with(".yaml") || path.ends_with(".yml");
let cases: Vec<PatchTestCase> = if is_yaml {
serde_yaml::from_str(&cases).unwrap()
} else {
serde_json::from_str(&cases).unwrap()
};
for (idx, tc) in cases.into_iter().enumerate() {
if tc.disabled {
continue;
}
match run_patch_test_case(&tc, kind) {
Ok(actual) => {
if let Some(error) = tc.error {
panic!(
"expected to fail with an error: {}, got document {:?}",
error, actual
);
} else {
let comment = tc.comment.as_deref().unwrap_or("");
let expected = if let Some(ref expected) = tc.expected {
expected
} else {
&tc.doc
};
assert_eq!(
*expected, actual,
"\nActual does not match expected in test case {}: {}",
idx, comment
);
}
}
Err(actual_error) => {
if let Some(expected_error) = tc.error {
if errors == Errors::ExactMatch {
assert_eq!(actual_error, expected_error, "Expected test case {} to fail with an error:\n{}\n\nbut instead failed with an error:\n{}", idx, expected_error, actual_error);
}
} else {
panic!(
"Patch expected to succeed, but failed with an error:\n{}",
actual_error
);
}
}
}
}
}

288
vendor/json-patch/tests/utoipa.json vendored Normal file
View File

@@ -0,0 +1,288 @@
{
"openapi": "3.0.3",
"info": {
"title": "json-patch",
"description": "RFC 6902, JavaScript Object Notation (JSON) Patch",
"contact": {
"name": "Ivan Dubrov",
"email": "dubrov.ivan@gmail.com"
},
"license": {
"name": "MIT/Apache-2.0"
},
"version": "0.0.0"
},
"paths": {
"foo": {
"get": {
"tags": [
"crate"
],
"operationId": "get_foo",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/Patch"
}
}
},
"required": true
},
"responses": {
"200": {
"description": "Patch completed"
},
"406": {
"description": "Not accepted"
}
}
}
}
},
"components": {
"schemas": {
"AddOperation": {
"type": "object",
"description": "JSON Patch 'add' operation representation",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
},
"value": {
"description": "Value to add to the target location."
}
}
},
"CopyOperation": {
"type": "object",
"description": "JSON Patch 'copy' operation representation",
"required": [
"from",
"path"
],
"properties": {
"from": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nto copy value from."
},
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
}
}
},
"MoveOperation": {
"type": "object",
"description": "JSON Patch 'move' operation representation",
"required": [
"from",
"path"
],
"properties": {
"from": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nto move value from."
},
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
}
}
},
"Patch": {
"type": "array",
"items": {
"$ref": "#/components/schemas/PatchOperation"
},
"description": "Representation of JSON Patch (list of patch operations)"
},
"PatchOperation": {
"oneOf": [
{
"allOf": [
{
"$ref": "#/components/schemas/AddOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"add"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/RemoveOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"remove"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/ReplaceOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"replace"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/MoveOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"move"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/CopyOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"copy"
]
}
}
}
]
},
{
"allOf": [
{
"$ref": "#/components/schemas/TestOperation"
},
{
"type": "object",
"required": [
"op"
],
"properties": {
"op": {
"type": "string",
"enum": [
"test"
]
}
}
}
]
}
],
"description": "JSON Patch single patch operation",
"discriminator": {
"propertyName": "op"
}
},
"RemoveOperation": {
"type": "object",
"description": "JSON Patch 'remove' operation representation",
"required": [
"path"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
}
}
},
"ReplaceOperation": {
"type": "object",
"description": "JSON Patch 'replace' operation representation",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
},
"value": {
"description": "Value to replace with."
}
}
},
"TestOperation": {
"type": "object",
"description": "JSON Patch 'test' operation representation",
"required": [
"path",
"value"
],
"properties": {
"path": {
"type": "string",
"description": "JSON-Pointer value [RFC6901](https://tools.ietf.org/html/rfc6901) that references a location\nwithin the target document where the operation is performed."
},
"value": {
"description": "Value to test against."
}
}
}
}
}
}

40
vendor/json-patch/tests/utoipa.rs vendored Normal file
View File

@@ -0,0 +1,40 @@
#[cfg(feature = "utoipa")]
#[test]
fn schema() {
use json_patch::*;
use utoipa::OpenApi;
#[utoipa::path(
get,
path = "foo",
request_body = Patch,
responses(
(status = 200, description = "Patch completed"),
(status = 406, description = "Not accepted"),
),
)]
#[allow(unused)]
fn get_foo(body: Patch) {}
#[derive(OpenApi, Default)]
#[openapi(
paths(get_foo),
components(schemas(
AddOperation,
CopyOperation,
MoveOperation,
PatchOperation,
RemoveOperation,
ReplaceOperation,
TestOperation,
Patch,
))
)]
struct ApiDoc;
let mut doc = ApiDoc::openapi();
doc.info.version = "0.0.0".to_string();
let json = doc.to_pretty_json().unwrap();
expectorate::assert_contents("tests/utoipa.json", &json);
}