Skip to content

Commit 4898153

Browse files
committed
chore: update changes
1 parent e24c385 commit 4898153

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

rust/catalyst-signed-doc-macro/src/rules/content_type.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ pub(crate) fn into_rule(
1212
content_types: &HashMap<ContentTypeTemplate, ContentTypeSpec>,
1313
field: &signed_doc_spec::content_type::ContentType,
1414
) -> anyhow::Result<TokenStream> {
15+
let is_field_empty =
16+
field.value.is_none() || field.value.as_ref().is_some_and(std::string::String::is_empty);
17+
1518
if matches!(field.required, IsRequired::Excluded) {
1619
anyhow::ensure!(
17-
field.value.is_empty(),
20+
is_field_empty,
1821
"'value' field must not exist when 'required' is 'excluded'"
1922
);
2023

@@ -24,18 +27,24 @@ pub(crate) fn into_rule(
2427
}
2528

2629
if matches!(field.required, IsRequired::Yes) {
27-
anyhow::ensure!(!field.value.is_empty(), "'value' field must exist");
30+
anyhow::ensure!(!is_field_empty, "'value' field must exist");
2831
}
2932

30-
let template = ContentTypeTemplate(field.value.clone());
31-
let Some(_) = content_types.get(&template) else {
32-
return Err(anyhow::anyhow!("Unsupported Content Type: {}", field.value));
33-
};
34-
let ident = template.ident();
35-
36-
Ok(quote! {
37-
crate::validator::rules::ContentTypeRule::Specified {
38-
exp: ContentType::#ident,
39-
}
40-
})
33+
if let Some(value) = &field.value {
34+
let template = ContentTypeTemplate(value.clone());
35+
let Some(_) = content_types.get(&template) else {
36+
return Err(anyhow::anyhow!("Unsupported Content Type: {}", value));
37+
};
38+
let ident = template.ident();
39+
40+
Ok(quote! {
41+
crate::validator::rules::ContentTypeRule::Specified {
42+
exp: ContentType::#ident,
43+
}
44+
})
45+
} else {
46+
Ok(quote! {
47+
crate::validator::rules::ContentTypeRule::NotSpecified
48+
})
49+
}
4150
}

rust/catalyst-signed-doc-macro/src/signed_doc_spec/content_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
#[allow(clippy::missing_docs_in_private_items)]
66
pub(crate) struct ContentType {
77
pub(crate) required: super::IsRequired,
8-
pub(crate) value: String,
8+
pub(crate) value: Option<String>,
99
}

rust/signed_doc/src/validator/rules/template.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl TemplateRule {
4949
return false;
5050
};
5151
match template_content_type {
52-
ContentType::Json | ContentType::JsonSchema => {
52+
ContentType::Json | ContentType::SchemaJson => {
5353
templated_json_schema_check(doc, template_doc)
5454
},
5555
ContentType::Cddl

0 commit comments

Comments
 (0)