Repository: oxidecomputer/typify
Pull request #718 (2024-12-20 21:48:58)

remove lint from empty builders; clean up merge tests


Patch:
diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml
index 864d5d8..f5c6904 100644
--- a/.github/workflows/rust.yml
+++ b/.github/workflows/rust.yml
@@ -1,5 +1,5 @@
 #
-# Configuration for GitHub-based CI, based on the stock GitHub Rust config.
+# Configuration for GitHub-based CI
 #
 name: Build
 
@@ -29,6 +29,6 @@ jobs:
     steps:
     - uses: actions/checkout@v2
     - name: Build
-      run: cargo build --tests --verbose
+      run: cargo build --locked --tests --verbose
     - name: Run tests
-      run: cargo test --verbose
+      run: cargo test --locked --verbose
diff --git a/typify-impl/src/type_entry.rs b/typify-impl/src/type_entry.rs
index 97a4d47..b4f53a3 100644
--- a/typify-impl/src/type_entry.rs
+++ b/typify-impl/src/type_entry.rs
@@ -1148,6 +1148,14 @@ impl TypeEntry {
                 },
             );
 
+            // If there are no properties, all of this is kind of pointless,
+            // but at least this lets us avoid the lint warning.
+            let value_ident = if prop_name.is_empty() {
+                quote! { _value }
+            } else {
+                quote! { value }
+            };
+
             output.add_item(
                 OutputSpaceMod::Builder,
                 name,
@@ -1189,7 +1197,7 @@ impl TypeEntry {
                     {
                         type Error = super::error::ConversionError;
 
-                        fn try_from(value: #type_name)
+                        fn try_from(#value_ident: #type_name)
                             -> ::std::result::Result<Self, super::error::ConversionError>
                         {
                             Ok(Self {
@@ -1202,7 +1210,7 @@ impl TypeEntry {
 
                     // Construct a builder from the item.
                     impl From<super::#type_name> for #type_name {
-                        fn from(value: super::#type_name) -> Self {
+                        fn from(#value_ident: super::#type_name) -> Self {
                             Self {
                                 #(
                                     #prop_name: Ok(value.#prop_name),


Test patch:
diff --git a/typify/tests/schemas.rs b/typify/tests/schemas.rs
index 78dfc8f..041fce2 100644
--- a/typify/tests/schemas.rs
+++ b/typify/tests/schemas.rs
@@ -87,6 +87,8 @@ fn validate_schema(
 
     // Make a file with the generated code.
     let code = quote! {
+        #![deny(warnings)]
+
         #type_space
 
         fn main() {}
diff --git a/typify/tests/schemas/arrays-and-tuples.rs b/typify/tests/schemas/arrays-and-tuples.rs
index a1bf64a..4bbd53d 100644
--- a/typify/tests/schemas/arrays-and-tuples.rs
+++ b/typify/tests/schemas/arrays-and-tuples.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/deny-list.rs b/typify/tests/schemas/deny-list.rs
index 3e5e636..a474d16 100644
--- a/typify/tests/schemas/deny-list.rs
+++ b/typify/tests/schemas/deny-list.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/extraneous-enum.rs b/typify/tests/schemas/extraneous-enum.rs
index 6295761..6ee90be 100644
--- a/typify/tests/schemas/extraneous-enum.rs
+++ b/typify/tests/schemas/extraneous-enum.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/id-or-name.rs b/typify/tests/schemas/id-or-name.rs
index 6493f35..60bbda0 100644
--- a/typify/tests/schemas/id-or-name.rs
+++ b/typify/tests/schemas/id-or-name.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/maps.rs b/typify/tests/schemas/maps.rs
index e908db4..58b1179 100644
--- a/typify/tests/schemas/maps.rs
+++ b/typify/tests/schemas/maps.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/maps_custom.rs b/typify/tests/schemas/maps_custom.rs
index 5094dae..6903409 100644
--- a/typify/tests/schemas/maps_custom.rs
+++ b/typify/tests/schemas/maps_custom.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/merged-schemas.json b/typify/tests/schemas/merged-schemas.json
index a98e937..22724ac 100644
--- a/typify/tests/schemas/merged-schemas.json
+++ b/typify/tests/schemas/merged-schemas.json
@@ -226,6 +226,7 @@
       ]
     },
     "unsatisfiable-2": {
+      "$comment": "can't be satisfied because required properties conflict in their enum values",
       "allOf": [
         {
           "type": "object",
@@ -237,6 +238,9 @@
               ]
             }
           },
+          "required": [
+            "action"
+          ],
           "additionalProperties": false
         },
         {
@@ -254,6 +258,7 @@
       ]
     },
     "unsatisfiable-3": {
+      "$comment": "tests a complex merge that can't be satisfied; it's basically the same as unsatisfiable-2, but is broken into multiple pieces",
       "allOf": [
         {
           "$ref": "#/definitions/unsatisfiable-3-a"
@@ -264,7 +269,10 @@
             "action": {
               "$ref": "#/definitions/unsatisfiable-3-b"
             }
-          }
+          },
+          "required": [
+            "action"
+          ]
         }
       ]
     },
@@ -447,6 +455,41 @@
           }
         }
       ]
+    },
+    "merge-empty": {
+      "$comment": "properties conflict but are not required so we end up with an empty object",
+      "allOf": [
+        {
+          "type": "object",
+          "properties": {
+            "action": {
+              "type": "string",
+              "enum": [
+                "foo"
+              ]
+            },
+            "token": {
+              "type": "string"
+            }
+          },
+          "additionalProperties": false
+        },
+        {
+          "type": "object",
+          "properties": {
+            "action": {
+              "type": "string",
+              "enum": [
+                "bar"
+              ]
+            }
+          },
+          "token": {
+            "type": "integer"
+          },
+          "additionalProperties": false
+        }
+      ]
     }
   }
 }
diff --git a/typify/tests/schemas/merged-schemas.rs b/typify/tests/schemas/merged-schemas.rs
index f7e7308..1bacde4 100644
--- a/typify/tests/schemas/merged-schemas.rs
+++ b/typify/tests/schemas/merged-schemas.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
@@ -441,6 +442,61 @@ impl std::convert::TryFrom<::std::string::String> for JsonSuccessResult {
         value.parse()
     }
 }
+#[doc = "MergeEmpty"]
+#[doc = r""]
+#[doc = r" <details><summary>JSON schema</summary>"]
+#[doc = r""]
+#[doc = r" ```json"]
+#[doc = "{"]
+#[doc = "  \"allOf\": ["]
+#[doc = "    {"]
+#[doc = "      \"type\": \"object\","]
+#[doc = "      \"properties\": {"]
+#[doc = "        \"action\": {"]
+#[doc = "          \"type\": \"string\","]
+#[doc = "          \"enum\": ["]
+#[doc = "            \"foo\""]
+#[doc = "          ]"]
+#[doc = "        },"]
+#[doc = "        \"token\": {"]
+#[doc = "          \"type\": \"string\""]
+#[doc = "        }"]
+#[doc = "      },"]
+#[doc = "      \"additionalProperties\": false"]
+#[doc = "    },"]
+#[doc = "    {"]
+#[doc = "      \"type\": \"object\","]
+#[doc = "      \"properties\": {"]
+#[doc = "        \"action\": {"]
+#[doc = "          \"type\": \"string\","]
+#[doc = "          \"enum\": ["]
+#[doc = "            \"bar\""]
+#[doc = "          ]"]
+#[doc = "        }"]
+#[doc = "      },"]
+#[doc = "      \"additionalProperties\": false,"]
+#[doc = "      \"token\": {"]
+#[doc = "        \"type\": \"integer\""]
+#[doc = "      }"]
+#[doc = "    }"]
+#[doc = "  ],"]
+#[doc = "  \"$comment\": \"properties conflict but are not required so we end up with an empty object\""]
+#[doc = "}"]
+#[doc = r" ```"]
+#[doc = r" </details>"]
+#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
+#[serde(deny_unknown_fields)]
+pub struct MergeEmpty {}
+impl From<&MergeEmpty> for MergeEmpty {
+    fn from(value: &MergeEmpty) -> Self {
+        value.clone()
+    }
+}
+impl MergeEmpty {
+    pub fn builder() -> builder::MergeEmpty {
+        Default::default()
+    }
+}
 #[doc = "NarrowNumber"]
 #[doc = r""]
 #[doc = r" <details><summary>JSON schema</summary>"]
@@ -870,6 +926,9 @@ impl From<&Unsatisfiable1> for Unsatisfiable1 {
 #[doc = "  \"allOf\": ["]
 #[doc = "    {"]
 #[doc = "      \"type\": \"object\","]
+#[doc = "      \"required\": ["]
+#[doc = "        \"action\""]
+#[doc = "      ],"]
 #[doc = "      \"properties\": {"]
 #[doc = "        \"action\": {"]
 #[doc = "          \"type\": \"string\","]
@@ -892,23 +951,30 @@ impl From<&Unsatisfiable1> for Unsatisfiable1 {
 #[doc = "      },"]
 #[doc = "      \"additionalProperties\": false"]
 #[doc = "    }"]
-#[doc = "  ]"]
+#[doc = "  ],"]
+#[doc = "  \"$comment\": \"can't be satisfied because required properties conflict in their enum values\""]
 #[doc = "}"]
 #[doc = r" ```"]
 #[doc = r" </details>"]
-#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
+#[derive(
+    :: serde :: Deserialize,
+    :: serde :: Serialize,
+    Clone,
+    Copy,
+    Debug,
+    Eq,
+    Hash,
+    Ord,
+    PartialEq,
+    PartialOrd,
+)]
 #[serde(deny_unknown_fields)]
-pub struct Unsatisfiable2 {}
+pub enum Unsatisfiable2 {}
 impl From<&Unsatisfiable2> for Unsatisfiable2 {
     fn from(value: &Unsatisfiable2) -> Self {
         value.clone()
     }
 }
-impl Unsatisfiable2 {
-    pub fn builder() -> builder::Unsatisfiable2 {
-        Default::default()
-    }
-}
 #[doc = "Unsatisfiable3"]
 #[doc = r""]
 #[doc = r" <details><summary>JSON schema</summary>"]
@@ -921,28 +987,39 @@ impl Unsatisfiable2 {
 #[doc = "    },"]
 #[doc = "    {"]
 #[doc = "      \"type\": \"object\","]
+#[doc = "      \"required\": ["]
+#[doc = "        \"action\""]
+#[doc = "      ],"]
 #[doc = "      \"properties\": {"]
 #[doc = "        \"action\": {"]
 #[doc = "          \"$ref\": \"#/definitions/unsatisfiable-3-b\""]
 #[doc = "        }"]
 #[doc = "      }"]
 #[doc = "    }"]
-#[doc = "  ]"]
+#[doc = "  ],"]
+#[doc = "  \"$comment\": \"tests a complex merge that can't be satisfied; it's basically the same as unsatisfiable-2, but is broken into multiple pieces\""]
 #[doc = "}"]
 #[doc = r" ```"]
 #[doc = r" </details>"]
-#[derive(:: serde :: Deserialize, :: serde :: Serialize, Clone, Debug)]
-pub struct Unsatisfiable3 {}
+#[derive(
+    :: serde :: Deserialize,
+    :: serde :: Serialize,
+    Clone,
+    Copy,
+    Debug,
+    Eq,
+    Hash,
+    Ord,
+    PartialEq,
+    PartialOrd,
+)]
+#[serde(deny_unknown_fields)]
+pub enum Unsatisfiable3 {}
 impl From<&Unsatisfiable3> for Unsatisfiable3 {
     fn from(value: &Unsatisfiable3) -> Self {
         value.clone()
     }
 }
-impl Unsatisfiable3 {
-    pub fn builder() -> builder::Unsatisfiable3 {
-        Default::default()
-    }
-}
 #[doc = "Unsatisfiable3A"]
 #[doc = r""]
 #[doc = r" <details><summary>JSON schema</summary>"]
@@ -1552,6 +1629,27 @@ pub mod builder {
         }
     }
     #[derive(Clone, Debug)]
+    pub struct MergeEmpty {}
+    impl Default for MergeEmpty {
+        fn default() -> Self {
+            Self {}
+        }
+    }
+    impl MergeEmpty {}
+    impl ::std::convert::TryFrom<MergeEmpty> for super::MergeEmpty {
+        type Error = super::error::ConversionError;
+        fn try_from(
+            _value: MergeEmpty,
+        ) -> ::std::result::Result<Self, super::error::ConversionError> {
+            Ok(Self {})
+        }
+    }
+    impl From<super::MergeEmpty> for MergeEmpty {
+        fn from(_value: super::MergeEmpty) -> Self {
+            Self {}
+        }
+    }
+    #[derive(Clone, Debug)]
     pub struct OrderDependentMerge {
         bar: ::std::result::Result<
             ::std::option::Option<::serde_json::Value>,
@@ -1812,48 +1910,6 @@ pub mod builder {
         }
     }
     #[derive(Clone, Debug)]
-    pub struct Unsatisfiable2 {}
-    impl Default for Unsatisfiable2 {
-        fn default() -> Self {
-            Self {}
-        }
-    }
-    impl Unsatisfiable2 {}
-    impl ::std::convert::TryFrom<Unsatisfiable2> for super::Unsatisfiable2 {
-        type Error = super::error::ConversionError;
-        fn try_from(
-            value: Unsatisfiable2,
-        ) -> ::std::result::Result<Self, super::error::ConversionError> {
-            Ok(Self {})
-        }
-    }
-    impl From<super::Unsatisfiable2> for Unsatisfiable2 {
-        fn from(value: super::Unsatisfiable2) -> Self {
-            Self {}
-        }
-    }
-    #[derive(Clone, Debug)]
-    pub struct Unsatisfiable3 {}
-    impl Default for Unsatisfiable3 {
-        fn default() -> Self {
-            Self {}
-        }
-    }
-    impl Unsatisfiable3 {}
-    impl ::std::convert::TryFrom<Unsatisfiable3> for super::Unsatisfiable3 {
-        type Error = super::error::ConversionError;
-        fn try_from(
-            value: Unsatisfiable3,
-        ) -> ::std::result::Result<Self, super::error::ConversionError> {
-            Ok(Self {})
-        }
-    }
-    impl From<super::Unsatisfiable3> for Unsatisfiable3 {
-        fn from(value: super::Unsatisfiable3) -> Self {
-            Self {}
-        }
-    }
-    #[derive(Clone, Debug)]
     pub struct Unsatisfiable3A {
         action: ::std::result::Result<
             ::std::option::Option<super::Unsatisfiable3C>,
diff --git a/typify/tests/schemas/multiple-instance-types.rs b/typify/tests/schemas/multiple-instance-types.rs
index 2492fcb..99019b9 100644
--- a/typify/tests/schemas/multiple-instance-types.rs
+++ b/typify/tests/schemas/multiple-instance-types.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/noisy-types.rs b/typify/tests/schemas/noisy-types.rs
index c5756fc..8329f5e 100644
--- a/typify/tests/schemas/noisy-types.rs
+++ b/typify/tests/schemas/noisy-types.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/property-pattern.rs b/typify/tests/schemas/property-pattern.rs
index e04fc67..c600976 100644
--- a/typify/tests/schemas/property-pattern.rs
+++ b/typify/tests/schemas/property-pattern.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/reflexive.rs b/typify/tests/schemas/reflexive.rs
index a85d50d..6c22ee7 100644
--- a/typify/tests/schemas/reflexive.rs
+++ b/typify/tests/schemas/reflexive.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/rust-collisions.rs b/typify/tests/schemas/rust-collisions.rs
index 1c7faab..dc89734 100644
--- a/typify/tests/schemas/rust-collisions.rs
+++ b/typify/tests/schemas/rust-collisions.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/simple-types.rs b/typify/tests/schemas/simple-types.rs
index 7ffd55b..074f555 100644
--- a/typify/tests/schemas/simple-types.rs
+++ b/typify/tests/schemas/simple-types.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/string-enum-with-default.rs b/typify/tests/schemas/string-enum-with-default.rs
index 15d715d..bef69bb 100644
--- a/typify/tests/schemas/string-enum-with-default.rs
+++ b/typify/tests/schemas/string-enum-with-default.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/type-with-modified-generation.rs b/typify/tests/schemas/type-with-modified-generation.rs
index 7fbfc3e..1605ed4 100644
--- a/typify/tests/schemas/type-with-modified-generation.rs
+++ b/typify/tests/schemas/type-with-modified-generation.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/types-with-defaults.rs b/typify/tests/schemas/types-with-defaults.rs
index 82e558e..b58684a 100644
--- a/typify/tests/schemas/types-with-defaults.rs
+++ b/typify/tests/schemas/types-with-defaults.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/types-with-more-impls.rs b/typify/tests/schemas/types-with-more-impls.rs
index 98e9d1d..facb796 100644
--- a/typify/tests/schemas/types-with-more-impls.rs
+++ b/typify/tests/schemas/types-with-more-impls.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/untyped-enum-with-null.rs b/typify/tests/schemas/untyped-enum-with-null.rs
index 1cb8636..2463135 100644
--- a/typify/tests/schemas/untyped-enum-with-null.rs
+++ b/typify/tests/schemas/untyped-enum-with-null.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/various-enums.rs b/typify/tests/schemas/various-enums.rs
index 95ba9a1..eb646d5 100644
--- a/typify/tests/schemas/various-enums.rs
+++ b/typify/tests/schemas/various-enums.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]
diff --git a/typify/tests/schemas/x-rust-type.rs b/typify/tests/schemas/x-rust-type.rs
index 1642cc0..235ba11 100644
--- a/typify/tests/schemas/x-rust-type.rs
+++ b/typify/tests/schemas/x-rust-type.rs
@@ -1,3 +1,4 @@
+#![deny(warnings)]
 #[doc = r" Error types."]
 pub mod error {
     #[doc = r" Error from a TryFrom or FromStr implementation."]