Skip to content

Commit

Permalink
Use let-else
Browse files Browse the repository at this point in the history
  • Loading branch information
GREsau committed Aug 24, 2024
1 parent 5ca8b12 commit 2388014
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
5 changes: 2 additions & 3 deletions schemars/src/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,9 +458,8 @@ impl SchemaGenerator {
}

let pointer = self.definitions_path_stripped();
let target = match json_pointer_mut(schema_object, pointer, true) {
Some(d) => d,
None => return,
let Some(target) = json_pointer_mut(schema_object, pointer, true) else {
return;
};

target.append(&mut definitions);
Expand Down
32 changes: 14 additions & 18 deletions schemars/src/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,13 @@ impl Transform for RemoveRefSiblings {
fn transform(&mut self, schema: &mut Schema) {
transform_subschemas(self, schema);

if let Some(obj) = schema.as_object_mut() {
if obj.len() > 1 {
if let Some(ref_value) = obj.remove("$ref") {
if let Value::Array(all_of) =
obj.entry("allOf").or_insert(Value::Array(Vec::new()))
{
all_of.push(json!({
"$ref": ref_value
}));
}
if let Some(obj) = schema.as_object_mut().filter(|o| o.len() > 1) {
if let Some(ref_value) = obj.remove("$ref") {
if let Value::Array(all_of) = obj.entry("allOf").or_insert(Value::Array(Vec::new()))
{
all_of.push(json!({
"$ref": ref_value
}));
}
}
}
Expand Down Expand Up @@ -403,15 +400,14 @@ impl Transform for ReplaceUnevaluatedProperties {
fn transform(&mut self, schema: &mut Schema) {
transform_subschemas(self, schema);

if let Some(obj) = schema.as_object_mut() {
if let Some(up) = obj.remove("unevaluatedProperties") {
obj.insert("additionalProperties".to_owned(), up);
} else {
return;
}
} else {
let Some(obj) = schema.as_object_mut() else {
return;
}
};
let Some(up) = obj.remove("unevaluatedProperties") else {
return;
};

obj.insert("additionalProperties".to_owned(), up);

let mut gather_property_names = GatherPropertyNames::default();
gather_property_names.transform(schema);
Expand Down

0 comments on commit 2388014

Please sign in to comment.