From d849736d6271b418faaa337ff9cfc4bf56bbaede Mon Sep 17 00:00:00 2001 From: Adam Leventhal Date: Fri, 20 Dec 2024 13:56:32 -0800 Subject: [PATCH] remove lint from empty builders; clean up merge tests (#718) --- .github/workflows/rust.yml | 6 +- typify-impl/src/type_entry.rs | 12 +- typify/tests/schemas.rs | 2 + typify/tests/schemas/arrays-and-tuples.rs | 1 + typify/tests/schemas/deny-list.rs | 1 + typify/tests/schemas/extraneous-enum.rs | 1 + typify/tests/schemas/id-or-name.rs | 1 + typify/tests/schemas/maps.rs | 1 + typify/tests/schemas/maps_custom.rs | 1 + typify/tests/schemas/merged-schemas.json | 45 ++++- typify/tests/schemas/merged-schemas.rs | 172 ++++++++++++------ .../tests/schemas/multiple-instance-types.rs | 1 + typify/tests/schemas/noisy-types.rs | 1 + typify/tests/schemas/property-pattern.rs | 1 + typify/tests/schemas/reflexive.rs | 1 + typify/tests/schemas/rust-collisions.rs | 1 + typify/tests/schemas/simple-types.rs | 1 + .../tests/schemas/string-enum-with-default.rs | 1 + .../schemas/type-with-modified-generation.rs | 1 + typify/tests/schemas/types-with-defaults.rs | 1 + typify/tests/schemas/types-with-more-impls.rs | 1 + .../tests/schemas/untyped-enum-with-null.rs | 1 + typify/tests/schemas/various-enums.rs | 1 + typify/tests/schemas/x-rust-type.rs | 1 + 24 files changed, 192 insertions(+), 64 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 864d5d80..f5c69049 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 97a4d479..b4f53a34 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 { Ok(Self { @@ -1202,7 +1210,7 @@ impl TypeEntry { // Construct a builder from the item. impl From 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), diff --git a/typify/tests/schemas.rs b/typify/tests/schemas.rs index 78dfc8f2..041fce22 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 a1bf64a6..4bbd53d0 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 3e5e6369..a474d161 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 62957610..6ee90bed 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 6493f35c..60bbda07 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 e908db42..58b11795 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 5094dae0..69034092 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 a98e9379..22724ac7 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 f7e7308c..1bacde4f 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"
JSON schema"] +#[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"
"] +#[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"
JSON schema"] @@ -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"
"] -#[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"
JSON schema"] @@ -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"
"] -#[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"
JSON schema"] @@ -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 for super::MergeEmpty { + type Error = super::error::ConversionError; + fn try_from( + _value: MergeEmpty, + ) -> ::std::result::Result { + Ok(Self {}) + } + } + impl From 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 for super::Unsatisfiable2 { - type Error = super::error::ConversionError; - fn try_from( - value: Unsatisfiable2, - ) -> ::std::result::Result { - Ok(Self {}) - } - } - impl From 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 for super::Unsatisfiable3 { - type Error = super::error::ConversionError; - fn try_from( - value: Unsatisfiable3, - ) -> ::std::result::Result { - Ok(Self {}) - } - } - impl From for Unsatisfiable3 { - fn from(value: super::Unsatisfiable3) -> Self { - Self {} - } - } - #[derive(Clone, Debug)] pub struct Unsatisfiable3A { action: ::std::result::Result< ::std::option::Option, diff --git a/typify/tests/schemas/multiple-instance-types.rs b/typify/tests/schemas/multiple-instance-types.rs index 2492fcb1..99019b9e 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 c5756fc8..8329f5e1 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 e04fc672..c600976e 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 a85d50d1..6c22ee7a 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 1c7faab0..dc89734e 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 7ffd55ba..074f555f 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 15d715dd..bef69bb5 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 7fbfc3ea..1605ed45 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 82e558e6..b58684a1 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 98e9d1da..facb796c 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 1cb86369..24631353 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 95ba9a1b..eb646d5f 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 1642cc0a..235ba11c 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."]