Repository: oxidecomputer/typify
Pull request #517 (2024-03-03 14:22:53)

Fix merging num/str validations that are equal
While trying to use [progenitor](https://github.com/oxidecomputer/progenitor) with the [DHL Express API](https://developer.dhl.com/sites/default/files/2023-10/dpdhl-express-api-2.10.0_swagger.yaml), I received the following unimplemented panic: `this is fairly fussy and I don't want to do it`.

I tracked the panic down to `merge_so_number` in this repo.

The validation rules it tried to merge where the same, which is why I were able to fix the panic by adding another case that handles if both `a` and `b` are defined but simply the same.


Patch:
diff --git a/Cargo.lock b/Cargo.lock
index 24fda68..f02cf78 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -259,7 +259,7 @@ dependencies = [
  "heck",
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -387,7 +387,7 @@ dependencies = [
  "schemars",
  "serde",
  "serde_json",
- "syn 2.0.51",
+ "syn 2.0.52",
  "typify",
 ]
 
@@ -586,9 +586,9 @@ checksum = "c4cd1a83af159aa67994778be9070f0ae1bd732942279cabb14f86f986a21456"
 
 [[package]]
 name = "log"
-version = "0.4.20"
+version = "0.4.21"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f"
+checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
 
 [[package]]
 name = "memchr"
@@ -691,7 +691,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5"
 dependencies = [
  "proc-macro2",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -789,9 +789,9 @@ checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f"
 
 [[package]]
 name = "regress"
-version = "0.8.0"
+version = "0.9.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4f5f39ba4513916c1b2657b72af6ec671f091cd637992f58d0ede5cae4e5dea0"
+checksum = "d06f9a1f7cd8473611ba1a480cf35f9c5cffc2954336ba90a982fdb7e7d7f51e"
 dependencies = [
  "hashbrown",
  "memchr",
@@ -862,7 +862,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "schema-derive",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -874,7 +874,7 @@ dependencies = [
  "paste",
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -925,7 +925,7 @@ checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -968,7 +968,7 @@ dependencies = [
  "proc-macro2",
  "quote",
  "serde",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -1005,9 +1005,9 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "2.0.51"
+version = "2.0.52"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6ab617d94515e94ae53b8406c628598680aa0c9587474ecbe58188f7b345d66c"
+checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07"
 dependencies = [
  "proc-macro2",
  "quote",
@@ -1069,7 +1069,7 @@ checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
 
 [[package]]
@@ -1222,7 +1222,7 @@ dependencies = [
  "schemars",
  "serde",
  "serde_json",
- "syn 2.0.51",
+ "syn 2.0.52",
  "thiserror",
  "unicode-ident",
  "uuid",
@@ -1238,7 +1238,7 @@ dependencies = [
  "serde",
  "serde_json",
  "serde_tokenstream",
- "syn 2.0.51",
+ "syn 2.0.52",
  "typify-impl",
 ]
 
@@ -1252,7 +1252,7 @@ dependencies = [
  "schemars",
  "serde",
  "serde_json",
- "syn 2.0.51",
+ "syn 2.0.52",
  "typify",
 ]
 
@@ -1341,7 +1341,7 @@ dependencies = [
  "once_cell",
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
  "wasm-bindgen-shared",
 ]
 
@@ -1363,7 +1363,7 @@ checksum = "f0eb82fcb7930ae6219a7ecfd55b217f5f0893484b7a13022ebb2b2bf20b5283"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
  "wasm-bindgen-backend",
  "wasm-bindgen-shared",
 ]
@@ -1638,5 +1638,5 @@ checksum = "b3c129550b3e6de3fd0ba67ba5c81818f9805e58b8d7fee80a3a59d2c9fc601a"
 dependencies = [
  "proc-macro2",
  "quote",
- "syn 2.0.51",
+ "syn 2.0.52",
 ]
diff --git a/typify-impl/Cargo.toml b/typify-impl/Cargo.toml
index 4bcd8a9..708dcbb 100644
--- a/typify-impl/Cargo.toml
+++ b/typify-impl/Cargo.toml
@@ -9,13 +9,13 @@ readme = "../README.md"
 
 [dependencies]
 heck = "0.4.1"
-log = "0.4.20"
+log = "0.4.21"
 proc-macro2 = "1.0.78"
 quote = "1.0.35"
-regress = "0.8.0"
+regress = "0.9.0"
 schemars = "0.8.16"
 serde_json = "1.0.114"
-syn = { version = "2.0.51", features = ["full"] }
+syn = { version = "2.0.52", features = ["full"] }
 thiserror = "1.0.57"
 unicode-ident = "1.0.12"
 
@@ -28,5 +28,5 @@ rustfmt-wrapper = "0.2.1"
 schema = "0.1.0"
 schemars = { version = "0.8.16", features = ["uuid1"] }
 serde = "1.0.197"
-syn = { version = "2.0.51", features = ["full", "extra-traits"] }
+syn = { version = "2.0.52", features = ["full", "extra-traits"] }
 uuid = "1.7.0"
diff --git a/typify-impl/src/merge.rs b/typify-impl/src/merge.rs
index c14779b..3188d29 100644
--- a/typify-impl/src/merge.rs
+++ b/typify-impl/src/merge.rs
@@ -686,6 +686,7 @@ fn merge_so_number(
 ) -> Result<Option<Box<NumberValidation>>, ()> {
     match (a, b) {
         (None, other) | (other, None) => Ok(other.cloned().map(Box::new)),
+        (Some(a), Some(b)) if a == b => Ok(Some(Box::new(a.clone()))),
         (Some(_), Some(_)) => {
             unimplemented!("this is fairly fussy and I don't want to do it")
         }
@@ -698,6 +699,7 @@ fn merge_so_string(
 ) -> Result<Option<Box<StringValidation>>, ()> {
     match (a, b) {
         (None, other) | (other, None) => Ok(other.cloned().map(Box::new)),
+        (Some(a), Some(b)) if a == b => Ok(Some(Box::new(a.clone()))),
         (Some(_), Some(_)) => {
             unimplemented!("this is fairly fussy and I don't want to do it")
         }
diff --git a/typify/Cargo.toml b/typify/Cargo.toml
index e6f2514..3403b61 100644
--- a/typify/Cargo.toml
+++ b/typify/Cargo.toml
@@ -23,7 +23,7 @@ env_logger = "0.10.2"
 expectorate = "1.1.0"
 glob = "0.3.1"
 quote = "1.0.34"
-regress = "0.8.0"
+regress = "0.9.0"
 rustfmt-wrapper = "0.2.1"
 schemars = "0.8.16"
 serde = "1.0.197"


Test patch:
diff --git a/typify-test/Cargo.toml b/typify-test/Cargo.toml
index 2092247..216970c 100644
--- a/typify-test/Cargo.toml
+++ b/typify-test/Cargo.toml
@@ -4,7 +4,7 @@ version = "0.0.0"
 edition = "2021"
 
 [dependencies]
-regress = "0.8.0"
+regress = "0.9.0"
 serde = "1.0.197"
 serde_json = "1.0.114"
 
@@ -13,5 +13,5 @@ ipnetwork = { version = "0.20.0", features = ["schemars"] }
 prettyplease = "0.2.16"
 schemars = "0.8.16"
 serde = "1.0.197"
-syn = "2.0.51"
+syn = "2.0.52"
 typify = { path = "../typify" }