@@ -41,6 +41,8 @@ impl MethodType {
4141
4242#[ derive( Deserialize , Debug ) ]
4343pub ( crate ) struct EndpointMetadata {
44+ #[ serde( default ) ]
45+ pub ( crate ) operation_id : Option < String > ,
4446 pub ( crate ) method : MethodType ,
4547 pub ( crate ) path : String ,
4648 #[ serde( default ) ]
@@ -59,7 +61,7 @@ impl EndpointMetadata {
5961 get_crate ( self . _dropshot_crate . as_deref ( ) )
6062 }
6163
62- /// Validates metadata, returning an `EndpointMetadata ` if valid.
64+ /// Validates metadata, returning a `ValidatedEndpointMetadata ` if valid.
6365 ///
6466 /// Note: the only reason we pass in attr here is to provide a span for
6567 /// error reporting. As of Rust 1.76, just passing in `attr.span()` produces
@@ -74,6 +76,7 @@ impl EndpointMetadata {
7476 let errors = errors. new ( ) ;
7577
7678 let EndpointMetadata {
79+ operation_id,
7780 method,
7881 path,
7982 tags,
@@ -130,6 +133,7 @@ impl EndpointMetadata {
130133 None
131134 } else if let Some ( content_type) = content_type {
132135 Some ( ValidatedEndpointMetadata {
136+ operation_id,
133137 method,
134138 path,
135139 tags,
@@ -145,6 +149,7 @@ impl EndpointMetadata {
145149
146150/// A validated form of endpoint metadata.
147151pub ( crate ) struct ValidatedEndpointMetadata {
152+ operation_id : Option < String > ,
148153 method : MethodType ,
149154 path : String ,
150155 tags : Vec < String > ,
@@ -163,6 +168,8 @@ impl ValidatedEndpointMetadata {
163168 ) -> TokenStream {
164169 let path = & self . path ;
165170 let content_type = self . content_type ;
171+ let operation_id =
172+ self . operation_id . as_deref ( ) . unwrap_or ( endpoint_name) ;
166173 let method_ident = format_ident ! ( "{}" , self . method. as_str( ) ) ;
167174
168175 let summary = doc. summary . as_ref ( ) . map ( |summary| {
@@ -192,7 +199,7 @@ impl ValidatedEndpointMetadata {
192199 ApiEndpointKind :: Regular ( endpoint_fn) => {
193200 quote_spanned ! { endpoint_fn. span( ) =>
194201 #dropshot:: ApiEndpoint :: new(
195- #endpoint_name . to_string( ) ,
202+ #operation_id . to_string( ) ,
196203 #endpoint_fn,
197204 #dropshot:: Method :: #method_ident,
198205 #content_type,
@@ -212,7 +219,7 @@ impl ValidatedEndpointMetadata {
212219 // Seems pretty unobjectionable.
213220 quote_spanned ! { attr. pound_token. span( ) =>
214221 #dropshot:: ApiEndpoint :: new_for_types:: <( #( #extractor_types, ) * ) , #ret_ty>(
215- #endpoint_name . to_string( ) ,
222+ #operation_id . to_string( ) ,
216223 #dropshot:: Method :: #method_ident,
217224 #content_type,
218225 #path,
@@ -241,6 +248,8 @@ pub(crate) enum ChannelProtocol {
241248#[ derive( Deserialize , Debug ) ]
242249pub ( crate ) struct ChannelMetadata {
243250 pub ( crate ) protocol : ChannelProtocol ,
251+ #[ serde( default ) ]
252+ pub ( crate ) operation_id : Option < String > ,
244253 pub ( crate ) path : String ,
245254 #[ serde( default ) ]
246255 pub ( crate ) tags : Vec < String > ,
@@ -273,6 +282,7 @@ impl ChannelMetadata {
273282
274283 let ChannelMetadata {
275284 protocol : ChannelProtocol :: WEBSOCKETS ,
285+ operation_id,
276286 path,
277287 tags,
278288 unpublished,
@@ -307,6 +317,7 @@ impl ChannelMetadata {
307317 // Validating channel metadata also validates the corresponding
308318 // endpoint metadata.
309319 let inner = ValidatedEndpointMetadata {
320+ operation_id,
310321 method : MethodType :: GET ,
311322 path,
312323 tags,
0 commit comments