Skip to content

Commit 9c0992b

Browse files
committed
chore: minor
1 parent f9640c4 commit 9c0992b

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

rust/catalyst-signed-doc-macro/src/field.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ impl TryInto<TokenStream> for IsRequired {
3131
/// Document's metadata fields definition
3232
#[derive(serde::Deserialize)]
3333
#[allow(clippy::missing_docs_in_private_items)]
34-
pub(crate) struct Metadata {
34+
pub(crate) struct Headers {
3535
#[serde(rename = "content type")]
36-
pub(crate) content_type: ContentType,
36+
pub(crate) content_type: ContentType,
3737
}
3838

39-
/// `signed_doc.json` "ref" field JSON object
39+
/// `signed_doc.json` "content type" field JSON object
4040
#[derive(serde::Deserialize)]
4141
#[allow(clippy::missing_docs_in_private_items)]
4242
pub(crate) struct ContentType {
@@ -50,30 +50,30 @@ impl TryInto<TokenStream> for ContentType {
5050

5151
fn try_into(self) -> Result<TokenStream, Self::Error> {
5252
let exp = match self.value.as_str() {
53-
"application/cbor" => quote! { ContentType::Cbor },
54-
"application/cddl" => quote! { ContentType::Cddl },
55-
"application/json" => quote! { ContentType::Json },
56-
"application/json+schema" => quote! { ContentType::JsonSchema },
57-
"text/css; charset=utf-8" => quote! { ContentType::Css },
58-
"text/css; charset=utf-8; template=handlebars" => quote! { ContentType::CssHandlebars },
59-
"text/html; charset=utf-8" => quote! { ContentType::Html },
53+
"application/cbor" => quote! { ContentTypeRule::Cbor },
54+
"application/cddl" => quote! { ContentTypeRule::Cddl },
55+
"application/json" => quote! { ContentTypeRule::Json },
56+
"application/json+schema" => quote! { ContentTypeRule::JsonSchema },
57+
"text/css; charset=utf-8" => quote! { ContentTypeRule::Css },
58+
"text/css; charset=utf-8; template=handlebars" => quote! { ContentTypeRule::CssHandlebars },
59+
"text/html; charset=utf-8" => quote! { ContentTypeRule::Html },
6060
"text/html; charset=utf-8; template=handlebars" => {
61-
quote! { ContentType::HtmlHandlebars }
61+
quote! { ContentTypeRule::HtmlHandlebars }
6262
},
63-
"text/markdown; charset=utf-8" => quote! { ContentType::Markdown },
63+
"text/markdown; charset=utf-8" => quote! { ContentTypeRule::Markdown },
6464
"text/markdown; charset=utf-8; template=handlebars" => {
65-
quote! { ContentType::MarkdownHandlebars }
65+
quote! { ContentTypeRule::MarkdownHandlebars }
6666
},
67-
"text/plain; charset=utf-8" => quote! { ContentType::Plain },
67+
"text/plain; charset=utf-8" => quote! { ContentTypeRule::Plain },
6868
"text/plain; charset=utf-8; template=handlebars" => {
69-
quote! { ContentType::PlainHandlebars }
69+
quote! { ContentTypeRule::PlainHandlebars }
7070
},
7171
_ => return Err(anyhow::anyhow!("Unsupported Content Type: {}", self.value)),
7272
};
7373

7474
Ok(quote! {
7575
crate::validator::rules::ContentTypeRule {
76-
exp: #exp,
76+
exp: crate::validator::rules::#exp,
7777
}
7878
})
7979
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn catalyst_signed_documents_rules_impl() -> anyhow::Result<TokenStre
1313
for (doc_name, doc_spec) in spec.docs {
1414
let const_type_name_ident = doc_name.ident();
1515

16-
let content_type_rule: TokenStream = doc_spec.metadata.content_type.try_into()?;
16+
let content_type_rule: TokenStream = doc_spec.headers.content_type.try_into()?;
1717

1818
// TODO: implement a proper initialization for all specific validation rules
1919
let rules = quote! {

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
33
use std::collections::HashMap;
44

5-
use anyhow::Context;
65
use proc_macro2::Ident;
76
use quote::format_ident;
87

@@ -45,8 +44,8 @@ pub(crate) struct DocSpec {
4544
/// Document type UUID v4 value
4645
#[serde(rename = "type")]
4746
pub(crate) doc_type: String,
48-
/// Document type metadata definitions
49-
pub(crate) metadata: field::Metadata,
47+
/// `headers` field
48+
pub(crate) headers: field::Headers,
5049
}
5150

5251
impl CatalystSignedDocSpec {
@@ -55,7 +54,7 @@ impl CatalystSignedDocSpec {
5554
pub(crate) fn load_signed_doc_spec() -> anyhow::Result<CatalystSignedDocSpec> {
5655
let signed_doc_str = include_str!("../../../specs/signed_doc.json");
5756
let signed_doc_spec = serde_json::from_str(signed_doc_str)
58-
.context("Catalyst Signed Documents spec must be a JSON object")?;
57+
.map_err(|e| anyhow::anyhow!("Invalid Catalyst Signed Documents JSON Spec: {e}"))?;
5958
Ok(signed_doc_spec)
6059
}
6160
}

0 commit comments

Comments
 (0)