@@ -3,8 +3,19 @@ use serde_yaml::{Mapping, Value};
33/// Where to apply a vendor (x-*) attribute.
44pub enum VendorLocation < ' a > {
55 Schema ( & ' a str ) ,
6- SchemaField { schema : & ' a str , field : & ' a str } ,
7- Operation { path : & ' a str , method : & ' a str } ,
6+ SchemaField {
7+ schema : & ' a str ,
8+ field : & ' a str ,
9+ } ,
10+ Operation {
11+ path : & ' a str ,
12+ method : & ' a str ,
13+ } ,
14+ OperationField {
15+ path : & ' a str ,
16+ method : & ' a str ,
17+ field : & ' a str ,
18+ } ,
819}
920
1021/// Main helper struct that holds a mutable borrow of the OpenAPI root mapping.
@@ -86,6 +97,19 @@ impl<'a> VendorAttributes<'a> {
8697 Self :: insert_into_map ( op_map, attr, val) ;
8798 Ok ( self )
8899 }
100+ VendorLocation :: OperationField {
101+ path,
102+ method,
103+ field,
104+ } => {
105+ let field_map =
106+ self . get_map_mut ( & [ "paths" , path, method, field] )
107+ . map_err ( |_| {
108+ format ! ( "operation field not found: {} {} {}" , method, path, field)
109+ } ) ?;
110+ Self :: insert_into_map ( field_map, attr, val) ;
111+ Ok ( self )
112+ }
89113 }
90114 }
91115
@@ -166,13 +190,43 @@ impl<'a, 'b> OperationContext<'a, 'b> {
166190 }
167191 }
168192
193+ fn try_set_field ( & mut self , field : & str , attr : & str , val : Value ) {
194+ if self . error . is_some ( ) {
195+ return ;
196+ }
197+ if let Err ( e) = self . vendor . set_attr (
198+ VendorLocation :: OperationField {
199+ path : self . path ,
200+ method : self . method ,
201+ field,
202+ } ,
203+ attr,
204+ val,
205+ ) {
206+ self . error = Some ( e) ;
207+ }
208+ }
209+
169210 pub fn generic_parameter ( mut self , generic : & str ) -> Self {
170211 self . try_set ( "x-rust-generic-parameter" , Value :: String ( generic. into ( ) ) ) ;
171212 self
172213 }
173214
174- pub fn return_type ( mut self , rust_type : & str ) -> Self {
175- self . try_set ( "x-rust-return-type" , Value :: String ( rust_type. into ( ) ) ) ;
215+ pub fn params_generic_parameter ( mut self , generic : & str ) -> Self {
216+ self . try_set (
217+ "x-rust-params-generic-parameter" ,
218+ Value :: String ( generic. into ( ) ) ,
219+ ) ;
220+ self
221+ }
222+
223+ pub fn return_type ( mut self , typ : & str ) -> Self {
224+ self . try_set ( "x-rust-return-type" , Value :: String ( typ. into ( ) ) ) ;
225+ self
226+ }
227+
228+ pub fn request_type ( mut self , typ : & str ) -> Self {
229+ self . try_set_field ( "requestBody" , "x-rust-type" , Value :: String ( typ. into ( ) ) ) ;
176230 self
177231 }
178232
0 commit comments