@@ -19,19 +19,18 @@ use std::collections::HashMap;
1919use std:: fmt:: Write ;
2020
2121use anyhow:: { anyhow, bail} ;
22- use clients_schema:: { Privileges , Property } ;
22+ use clients_schema:: { Property } ;
2323use indexmap:: IndexMap ;
2424use indexmap:: indexmap;
2525use icu_segmenter:: SentenceSegmenter ;
26- use itertools:: Itertools ;
2726use openapiv3:: {
2827 MediaType , Parameter , ParameterData , ParameterSchemaOrContent , PathItem , PathStyle , Paths , QueryStyle , ReferenceOr ,
2928 RequestBody , Response , Responses , StatusCode , Example
3029} ;
3130use serde_json:: Value ;
3231use clients_schema:: SchemaExample ;
3332use crate :: components:: TypesAndComponents ;
34- use crate :: convert_availabilities;
33+ use crate :: { auths_as_extentions , convert_availabilities, paths_as_extentions } ;
3534
3635/// Add an endpoint to the OpenAPI schema. This will result in the addition of a number of elements to the
3736/// openapi schema's `paths` and `components` sections.
@@ -248,6 +247,8 @@ pub fn add_endpoint(
248247
249248 let mut new_endpoint: clients_schema:: Endpoint ;
250249
250+ let mut longest_urls = Vec :: new ( ) ;
251+
251252 let endpoint = if is_multipath && tac. config . merge_multipath_endpoints {
252253
253254 // Add redirects for operations that would have been generated otherwise
@@ -274,6 +275,8 @@ pub fn add_endpoint(
274275 let mut urls = vec ! [ longest_path] ;
275276 std:: mem:: swap ( & mut endpoint. urls , & mut urls) ;
276277
278+ longest_urls = urls;
279+
277280 let split_desc = split_summary_desc ( & endpoint. description ) ;
278281
279282 // Make sure the description is stays at the top
@@ -282,24 +285,6 @@ pub fn add_endpoint(
282285 None => String :: new ( ) ,
283286 } ;
284287
285- // Convert removed paths to descriptions
286- write ! ( description, "**All methods and paths for this operation:**\n \n " ) ?;
287-
288- for url in urls {
289- for method in url. methods {
290- let lower_method = method. to_lowercase ( ) ;
291- let path = & url. path ;
292- write ! (
293- description,
294- r#"<div>
295- <span class="operation-verb {lower_method}">{method}</span>
296- <span class="operation-path">{path}</span>
297- </div>
298- "#
299- ) ?;
300- }
301- }
302-
303288 if let Some ( desc) = & split_desc. description {
304289 write ! ( description, "\n \n {}" , desc) ?;
305290 }
@@ -335,18 +320,15 @@ pub fn add_endpoint(
335320
336321 parameters. append ( & mut query_params. clone ( ) ) ;
337322
338- let sum_desc = split_summary_desc ( & endpoint. description ) ;
339-
340- let privilege_desc = add_privileges ( & endpoint. privileges ) ;
341-
342- let full_desc = match ( sum_desc. description , privilege_desc) {
343- ( Some ( a) , Some ( b) ) => Some ( a+ & b) ,
344- ( opt_a, opt_b) => opt_a. or ( opt_b)
345- } ;
346-
347323 // add the x-state extension for availability
348324 let mut extensions = crate :: availability_as_extensions ( & endpoint. availability , & tac. config . flavor ) ;
349325
326+ // add the x-variations extension for paths
327+ extensions. append ( & mut paths_as_extentions ( longest_urls. clone ( ) ) ) ;
328+
329+ // add the x-req-auth extension for auth privileges
330+ extensions. append ( & mut auths_as_extentions ( & endpoint. privileges ) ) ;
331+
350332 if tac. config . include_language_examples {
351333 // add the x-codeSamples extension
352334 let mut code_samples = vec ! [ ] ;
@@ -375,8 +357,12 @@ pub fn add_endpoint(
375357 }
376358 }
377359
360+ // add the x-metaTags extension for product name
378361 extensions. append ( & mut crate :: product_meta_as_extensions ( namespace, product_meta) ) ;
379362
363+ // split summary from description
364+ let sum_desc = split_summary_desc ( & endpoint. description ) ;
365+
380366 // Create the operation, it will be repeated if we have several methods
381367 let operation = openapiv3:: Operation {
382368 tags : if let Some ( doc_tag) = & endpoint. doc_tag {
@@ -385,7 +371,7 @@ pub fn add_endpoint(
385371 vec ! [ namespace. to_string( ) ]
386372 } ,
387373 summary : sum_desc. summary ,
388- description : full_desc ,
374+ description : sum_desc . description ,
389375 external_docs : tac. convert_external_docs ( endpoint) ,
390376 // external_docs: None, // Need values that differ from client purposes
391377 operation_id : None , // set in clone_operation below with operation_counter
@@ -522,28 +508,6 @@ fn split_summary_desc(desc: &str) -> SplitDesc{
522508 }
523509}
524510
525- fn add_privileges ( privileges : & Option < Privileges > ) -> Option < String > {
526- if let Some ( privs) = privileges {
527- let mut result = "\n \n ## Required authorization\n \n " . to_string ( ) ;
528- if !privs. index . is_empty ( ) {
529- result += "* Index privileges: " ;
530- result += & privs. index . iter ( )
531- . map ( |a| format ! ( "`{a}`" ) )
532- . join ( "," ) ;
533- result += "\n " ;
534- }
535- if !privs. cluster . is_empty ( ) {
536- result += "* Cluster privileges: " ;
537- result += & privs. cluster . iter ( )
538- . map ( |a| format ! ( "`{a}`" ) )
539- . join ( "," ) ;
540- result += "\n " ;
541- }
542- return Some ( result)
543- }
544- None
545- }
546-
547511#[ derive( PartialEq , Debug ) ]
548512struct SplitDesc {
549513 summary : Option < String > ,
0 commit comments