Skip to content

Commit d849736

Browse files
authored
remove lint from empty builders; clean up merge tests (#718)
1 parent d2e1757 commit d849736

24 files changed

+192
-64
lines changed

.github/workflows/rust.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Configuration for GitHub-based CI, based on the stock GitHub Rust config.
2+
# Configuration for GitHub-based CI
33
#
44
name: Build
55

@@ -29,6 +29,6 @@ jobs:
2929
steps:
3030
- uses: actions/checkout@v2
3131
- name: Build
32-
run: cargo build --tests --verbose
32+
run: cargo build --locked --tests --verbose
3333
- name: Run tests
34-
run: cargo test --verbose
34+
run: cargo test --locked --verbose

typify-impl/src/type_entry.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,14 @@ impl TypeEntry {
11481148
},
11491149
);
11501150

1151+
// If there are no properties, all of this is kind of pointless,
1152+
// but at least this lets us avoid the lint warning.
1153+
let value_ident = if prop_name.is_empty() {
1154+
quote! { _value }
1155+
} else {
1156+
quote! { value }
1157+
};
1158+
11511159
output.add_item(
11521160
OutputSpaceMod::Builder,
11531161
name,
@@ -1189,7 +1197,7 @@ impl TypeEntry {
11891197
{
11901198
type Error = super::error::ConversionError;
11911199

1192-
fn try_from(value: #type_name)
1200+
fn try_from(#value_ident: #type_name)
11931201
-> ::std::result::Result<Self, super::error::ConversionError>
11941202
{
11951203
Ok(Self {
@@ -1202,7 +1210,7 @@ impl TypeEntry {
12021210

12031211
// Construct a builder from the item.
12041212
impl From<super::#type_name> for #type_name {
1205-
fn from(value: super::#type_name) -> Self {
1213+
fn from(#value_ident: super::#type_name) -> Self {
12061214
Self {
12071215
#(
12081216
#prop_name: Ok(value.#prop_name),

typify/tests/schemas.rs

+2
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ fn validate_schema(
8787

8888
// Make a file with the generated code.
8989
let code = quote! {
90+
#![deny(warnings)]
91+
9092
#type_space
9193

9294
fn main() {}

typify/tests/schemas/arrays-and-tuples.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#[doc = r" Error types."]
23
pub mod error {
34
#[doc = r" Error from a TryFrom or FromStr implementation."]

typify/tests/schemas/deny-list.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#[doc = r" Error types."]
23
pub mod error {
34
#[doc = r" Error from a TryFrom or FromStr implementation."]

typify/tests/schemas/extraneous-enum.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#[doc = r" Error types."]
23
pub mod error {
34
#[doc = r" Error from a TryFrom or FromStr implementation."]

typify/tests/schemas/id-or-name.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#[doc = r" Error types."]
23
pub mod error {
34
#[doc = r" Error from a TryFrom or FromStr implementation."]

typify/tests/schemas/maps.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#[doc = r" Error types."]
23
pub mod error {
34
#[doc = r" Error from a TryFrom or FromStr implementation."]

typify/tests/schemas/maps_custom.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![deny(warnings)]
12
#[doc = r" Error types."]
23
pub mod error {
34
#[doc = r" Error from a TryFrom or FromStr implementation."]

typify/tests/schemas/merged-schemas.json

+44-1
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@
226226
]
227227
},
228228
"unsatisfiable-2": {
229+
"$comment": "can't be satisfied because required properties conflict in their enum values",
229230
"allOf": [
230231
{
231232
"type": "object",
@@ -237,6 +238,9 @@
237238
]
238239
}
239240
},
241+
"required": [
242+
"action"
243+
],
240244
"additionalProperties": false
241245
},
242246
{
@@ -254,6 +258,7 @@
254258
]
255259
},
256260
"unsatisfiable-3": {
261+
"$comment": "tests a complex merge that can't be satisfied; it's basically the same as unsatisfiable-2, but is broken into multiple pieces",
257262
"allOf": [
258263
{
259264
"$ref": "#/definitions/unsatisfiable-3-a"
@@ -264,7 +269,10 @@
264269
"action": {
265270
"$ref": "#/definitions/unsatisfiable-3-b"
266271
}
267-
}
272+
},
273+
"required": [
274+
"action"
275+
]
268276
}
269277
]
270278
},
@@ -447,6 +455,41 @@
447455
}
448456
}
449457
]
458+
},
459+
"merge-empty": {
460+
"$comment": "properties conflict but are not required so we end up with an empty object",
461+
"allOf": [
462+
{
463+
"type": "object",
464+
"properties": {
465+
"action": {
466+
"type": "string",
467+
"enum": [
468+
"foo"
469+
]
470+
},
471+
"token": {
472+
"type": "string"
473+
}
474+
},
475+
"additionalProperties": false
476+
},
477+
{
478+
"type": "object",
479+
"properties": {
480+
"action": {
481+
"type": "string",
482+
"enum": [
483+
"bar"
484+
]
485+
}
486+
},
487+
"token": {
488+
"type": "integer"
489+
},
490+
"additionalProperties": false
491+
}
492+
]
450493
}
451494
}
452495
}

0 commit comments

Comments
 (0)