Skip to content

Commit 3e4a761

Browse files
committed
add ref_rule
1 parent 24bb4d5 commit 3e4a761

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! `RefRule` generation
2+
3+
use proc_macro2::TokenStream;
4+
use quote::quote;
5+
6+
/// `signed_doc.json` "ref" field JSON defintion
7+
#[derive(serde::Deserialize)]
8+
pub(crate) struct Ref {}
9+
10+
/// Generating `RefRule` instantiation
11+
pub(crate) fn ref_rule(_ref_spec: &Ref) -> anyhow::Result<TokenStream> {
12+
let res = quote! {
13+
crate::validator::rules::RefRule::NotSpecified
14+
};
15+
Ok(res)
16+
}

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! `catalyst_signed_documents_rules!` macro implementation
22
3+
pub(crate) mod doc_ref;
4+
35
use proc_macro2::TokenStream;
46
use quote::quote;
57

@@ -10,9 +12,10 @@ pub(crate) fn catalyst_signed_documents_rules_impl() -> anyhow::Result<TokenStre
1012
let spec = CatalystSignedDocSpec::load_signed_doc_spec()?;
1113

1214
let mut rules_definitions = Vec::new();
13-
for (doc_name, _doc_spec) in spec.docs {
15+
for (doc_name, doc_spec) in spec.docs {
1416
let const_type_name_ident = doc_name.ident();
1517

18+
let ref_rule = doc_ref::ref_rule(&doc_spec.metadata.doc_ref)?;
1619
// TODO: implement a proper initialization for all specific validation rules
1720
let rules = quote! {
1821
crate::validator::rules::Rules {
@@ -27,7 +30,7 @@ pub(crate) fn catalyst_signed_documents_rules_impl() -> anyhow::Result<TokenStre
2730
},
2831
content: crate::validator::rules::ContentRule::NotSpecified,
2932
parameters: crate::validator::rules::ParametersRule::NotSpecified,
30-
doc_ref: crate::validator::rules::RefRule::NotSpecified,
33+
doc_ref: #ref_rule,
3134
reply: crate::validator::rules::ReplyRule::NotSpecified,
3235
section: crate::validator::rules::SectionRule::NotSpecified,
3336
kid: crate::validator::rules::SignatureKidRule {

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

Lines changed: 11 additions & 3 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

@@ -43,15 +42,24 @@ pub(crate) struct DocSpec {
4342
/// Document type UUID v4 value
4443
#[serde(rename = "type")]
4544
pub(crate) doc_type: String,
45+
46+
/// Document type metadata definitions
47+
pub(crate) metadata: Metadata,
48+
}
49+
50+
/// Document's metadata fields defintion
51+
#[derive(serde::Deserialize)]
52+
pub(crate) struct Metadata {
53+
#[serde(rename = "ref")]
54+
pub(crate) doc_ref: crate::rules::doc_ref::Ref,
4655
}
4756

4857
impl CatalystSignedDocSpec {
4958
/// Loading a Catalyst Signed Documents spec from the `signed_doc.json`
5059
// #[allow(dependency_on_unit_never_type_fallback)]
5160
pub(crate) fn load_signed_doc_spec() -> anyhow::Result<CatalystSignedDocSpec> {
5261
let signed_doc_str = include_str!("../../../specs/signed_doc.json");
53-
let signed_doc_spec = serde_json::from_str(signed_doc_str)
54-
.context("Catalyst Signed Documents spec must be a JSON object")?;
62+
let signed_doc_spec = serde_json::from_str(signed_doc_str)?;
5563
Ok(signed_doc_spec)
5664
}
5765
}

0 commit comments

Comments
 (0)