Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove lint from empty builders; clean up merge tests #718

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading