Skip to content

Commit

Permalink
remove lint from empty builders; clean up merge tests (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahl authored Dec 20, 2024
1 parent d2e1757 commit d849736
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 64 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Configuration for GitHub-based CI, based on the stock GitHub Rust config.
# Configuration for GitHub-based CI
#
name: Build

Expand Down Expand Up @@ -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
12 changes: 10 additions & 2 deletions typify-impl/src/type_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand All @@ -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),
Expand Down
2 changes: 2 additions & 0 deletions typify/tests/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ fn validate_schema(

// Make a file with the generated code.
let code = quote! {
#![deny(warnings)]

#type_space

fn main() {}
Expand Down
1 change: 1 addition & 0 deletions typify/tests/schemas/arrays-and-tuples.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
Expand Down
1 change: 1 addition & 0 deletions typify/tests/schemas/deny-list.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
Expand Down
1 change: 1 addition & 0 deletions typify/tests/schemas/extraneous-enum.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
Expand Down
1 change: 1 addition & 0 deletions typify/tests/schemas/id-or-name.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
Expand Down
1 change: 1 addition & 0 deletions typify/tests/schemas/maps.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
Expand Down
1 change: 1 addition & 0 deletions typify/tests/schemas/maps_custom.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![deny(warnings)]
#[doc = r" Error types."]
pub mod error {
#[doc = r" Error from a TryFrom or FromStr implementation."]
Expand Down
45 changes: 44 additions & 1 deletion typify/tests/schemas/merged-schemas.json
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@
]
},
"unsatisfiable-2": {
"$comment": "can't be satisfied because required properties conflict in their enum values",
"allOf": [
{
"type": "object",
Expand All @@ -237,6 +238,9 @@
]
}
},
"required": [
"action"
],
"additionalProperties": false
},
{
Expand All @@ -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"
Expand All @@ -264,7 +269,10 @@
"action": {
"$ref": "#/definitions/unsatisfiable-3-b"
}
}
},
"required": [
"action"
]
}
]
},
Expand Down Expand Up @@ -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
}
]
}
}
}
Loading

0 comments on commit d849736

Please sign in to comment.