11use std:: any:: Any ;
22
3- use async_trait:: async_trait;
4- use serde:: { Deserialize , Serialize } ;
5-
63use crate :: {
74 error:: ShieldError ,
85 form:: Form ,
@@ -11,6 +8,38 @@ use crate::{
118 response:: Response ,
129 session:: { BaseSession , MethodSession } ,
1310} ;
11+ use async_trait:: async_trait;
12+ use serde:: { Deserialize , Serialize } ;
13+ #[ cfg( feature = "utoipa" ) ]
14+ use utoipa:: openapi:: HttpMethod ;
15+
16+ #[ derive( Clone , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
17+ pub enum ActionMethod {
18+ Get ,
19+ Post ,
20+ Put ,
21+ Delete ,
22+ Options ,
23+ Head ,
24+ Patch ,
25+ Trace ,
26+ }
27+
28+ #[ cfg( feature = "utoipa" ) ]
29+ impl From < ActionMethod > for HttpMethod {
30+ fn from ( value : ActionMethod ) -> Self {
31+ match value {
32+ ActionMethod :: Get => Self :: Get ,
33+ ActionMethod :: Post => Self :: Post ,
34+ ActionMethod :: Put => Self :: Put ,
35+ ActionMethod :: Delete => Self :: Delete ,
36+ ActionMethod :: Options => Self :: Options ,
37+ ActionMethod :: Head => Self :: Head ,
38+ ActionMethod :: Patch => Self :: Patch ,
39+ ActionMethod :: Trace => Self :: Trace ,
40+ }
41+ }
42+ }
1443
1544// TODO: Think of a better name.
1645#[ derive( Clone , Debug , Deserialize , Serialize ) ]
@@ -46,6 +75,12 @@ pub trait Action<P: Provider, S>: ErasedAction + Send + Sync {
4675
4776 fn name ( & self ) -> String ;
4877
78+ fn openapi_summary ( & self ) -> & ' static str ;
79+
80+ fn openapi_description ( & self ) -> & ' static str ;
81+
82+ fn method ( & self ) -> ActionMethod ;
83+
4984 fn condition ( & self , _provider : & P , _session : & MethodSession < S > ) -> Result < bool , ShieldError > {
5085 Ok ( true )
5186 }
@@ -66,6 +101,12 @@ pub trait ErasedAction: Send + Sync {
66101
67102 fn erased_name ( & self ) -> String ;
68103
104+ fn erased_openapi_summary ( & self ) -> & ' static str ;
105+
106+ fn erased_openapi_description ( & self ) -> & ' static str ;
107+
108+ fn erased_method ( & self ) -> ActionMethod ;
109+
69110 fn erased_condition (
70111 & self ,
71112 provider : & ( dyn Any + Send + Sync ) ,
@@ -100,6 +141,18 @@ macro_rules! erased_action {
100141 self . name( )
101142 }
102143
144+ fn erased_openapi_summary( & self ) -> & ' static str {
145+ self . openapi_summary( )
146+ }
147+
148+ fn erased_openapi_description( & self ) -> & ' static str {
149+ self . openapi_description( )
150+ }
151+
152+ fn erased_method( & self ) -> $crate:: ActionMethod {
153+ self . method( )
154+ }
155+
103156 fn erased_condition(
104157 & self ,
105158 provider: & ( dyn std:: any:: Any + Send + Sync ) ,
0 commit comments