@@ -438,6 +438,12 @@ pub enum Content {
438438 TicketClosed010 ( ticket_closed_0_1_0:: Content ) ,
439439 TicketCreated010 ( ticket_created_0_1_0:: Content ) ,
440440 TicketUpdated010 ( ticket_updated_0_1_0:: Content ) ,
441+ Custom {
442+ #[ serde( skip) ]
443+ ty : String ,
444+ #[ serde( flatten) ]
445+ json : serde_json:: Value ,
446+ } ,
441447}
442448
443449impl Content {
@@ -783,14 +789,18 @@ impl Content {
783789 let variant: ticket_updated_0_1_0:: Content = serde_json:: from_value ( json) ?;
784790 Ok ( variant. into ( ) )
785791 } ,
786- variant => Err ( serde_json:: Error :: custom ( format_args ! (
787- "unknown variant `{}`, expected 'dev.cdevents.{{subject}}.{{predicate}}.{{version}}'" ,
788- variant,
789- ) ) ) ,
792+ variant => if variant. starts_with ( "dev.cdeventsx." ) {
793+ Ok ( Self :: Custom { ty : ty. to_string ( ) , json } )
794+ } else {
795+ Err ( serde_json:: Error :: custom ( format_args ! (
796+ "unknown variant `{}`, expected 'dev.cdevents.{{subject}}.{{predicate}}.{{version}}'" ,
797+ variant,
798+ ) ) )
799+ } ,
790800 }
791801 }
792802
793- pub fn ty ( & self ) -> & ' static str {
803+ pub fn ty ( & self ) -> & str {
794804 match self {
795805 Self :: ArtifactDeleted010 ( _) => ARTIFACT_DELETED_0_1_0 ,
796806 Self :: ArtifactDownloaded010 ( _) => ARTIFACT_DOWNLOADED_0_1_0 ,
@@ -877,10 +887,11 @@ impl Content {
877887 Self :: TicketClosed010 ( _) => TICKET_CLOSED_0_1_0 ,
878888 Self :: TicketCreated010 ( _) => TICKET_CREATED_0_1_0 ,
879889 Self :: TicketUpdated010 ( _) => TICKET_UPDATED_0_1_0 ,
890+ Self :: Custom { ty, ..} => ty,
880891 }
881892 }
882893
883- pub fn subject ( & self ) -> & ' static str {
894+ pub fn subject ( & self ) -> & str {
884895 match self {
885896 Self :: ArtifactDeleted010 ( _) => "artifact" ,
886897 Self :: ArtifactDownloaded010 ( _) => "artifact" ,
@@ -967,10 +978,11 @@ impl Content {
967978 Self :: TicketClosed010 ( _) => "ticket" ,
968979 Self :: TicketCreated010 ( _) => "ticket" ,
969980 Self :: TicketUpdated010 ( _) => "ticket" ,
981+ Self :: Custom { ty, ..} => ty. split ( '.' ) . nth ( 2 ) . unwrap_or_default ( ) ,
970982 }
971983 }
972984
973- pub fn predicate ( & self ) -> & ' static str {
985+ pub fn predicate ( & self ) -> & str {
974986 match self {
975987 Self :: ArtifactDeleted010 ( _) => "deleted" ,
976988 Self :: ArtifactDownloaded010 ( _) => "downloaded" ,
@@ -1057,11 +1069,13 @@ impl Content {
10571069 Self :: TicketClosed010 ( _) => "closed" ,
10581070 Self :: TicketCreated010 ( _) => "created" ,
10591071 Self :: TicketUpdated010 ( _) => "updated" ,
1072+ Self :: Custom { ty, ..} => ty. split ( '.' ) . nth ( 3 ) . unwrap_or_default ( ) ,
10601073 }
10611074 }
10621075}
10631076
1064- // due to inconstency in case/format the subject could be not be extracted from the context.type (ty), jsonshema $id, spec filename (shema, examples)
1077+ /// Due to inconstency in case/format the subject could be not be extracted from the context.type (ty), jsonshema $id, spec filename (shema, examples)
1078+ /// Custom type are not supported
10651079pub fn extract_subject_predicate ( ty : & str ) -> Option < ( & str , & str ) > {
10661080 // let mut split = ty.split('.');
10671081 match ty {
@@ -1680,7 +1694,7 @@ impl<> proptest::arbitrary::Arbitrary for Content {
16801694// #[cfg(test)]
16811695// mod tests {
16821696// use super::*;
1683- //
1697+ //
16841698// #[test]
16851699// fn test_true() {
16861700//
@@ -1855,4 +1869,4 @@ impl<> proptest::arbitrary::Arbitrary for Content {
18551869// assert_eq!(extract_subject_predicate(TICKET_UPDATED_0_1_0), Some(("ticket","updated")));
18561870//
18571871// }
1858- // }
1872+ // }
0 commit comments