@@ -19,19 +19,18 @@ use std::collections::HashMap;
19
19
use std:: fmt:: Write ;
20
20
21
21
use anyhow:: { anyhow, bail} ;
22
- use clients_schema:: { Privileges , Property } ;
22
+ use clients_schema:: { Property } ;
23
23
use indexmap:: IndexMap ;
24
24
use indexmap:: indexmap;
25
25
use icu_segmenter:: SentenceSegmenter ;
26
- use itertools:: Itertools ;
27
26
use openapiv3:: {
28
27
MediaType , Parameter , ParameterData , ParameterSchemaOrContent , PathItem , PathStyle , Paths , QueryStyle , ReferenceOr ,
29
28
RequestBody , Response , Responses , StatusCode , Example
30
29
} ;
31
30
use serde_json:: Value ;
32
31
use clients_schema:: SchemaExample ;
33
32
use crate :: components:: TypesAndComponents ;
34
- use crate :: convert_availabilities;
33
+ use crate :: { auths_as_extentions , convert_availabilities, paths_as_extentions } ;
35
34
36
35
/// Add an endpoint to the OpenAPI schema. This will result in the addition of a number of elements to the
37
36
/// openapi schema's `paths` and `components` sections.
@@ -248,6 +247,8 @@ pub fn add_endpoint(
248
247
249
248
let mut new_endpoint: clients_schema:: Endpoint ;
250
249
250
+ let mut longest_urls = Vec :: new ( ) ;
251
+
251
252
let endpoint = if is_multipath && tac. config . merge_multipath_endpoints {
252
253
253
254
// Add redirects for operations that would have been generated otherwise
@@ -274,6 +275,8 @@ pub fn add_endpoint(
274
275
let mut urls = vec ! [ longest_path] ;
275
276
std:: mem:: swap ( & mut endpoint. urls , & mut urls) ;
276
277
278
+ longest_urls = urls;
279
+
277
280
let split_desc = split_summary_desc ( & endpoint. description ) ;
278
281
279
282
// Make sure the description is stays at the top
@@ -282,24 +285,6 @@ pub fn add_endpoint(
282
285
None => String :: new ( ) ,
283
286
} ;
284
287
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
-
303
288
if let Some ( desc) = & split_desc. description {
304
289
write ! ( description, "\n \n {}" , desc) ?;
305
290
}
@@ -335,18 +320,15 @@ pub fn add_endpoint(
335
320
336
321
parameters. append ( & mut query_params. clone ( ) ) ;
337
322
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
-
347
323
// add the x-state extension for availability
348
324
let mut extensions = crate :: availability_as_extensions ( & endpoint. availability , & tac. config . flavor ) ;
349
325
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
+
350
332
if tac. config . include_language_examples {
351
333
// add the x-codeSamples extension
352
334
let mut code_samples = vec ! [ ] ;
@@ -375,8 +357,12 @@ pub fn add_endpoint(
375
357
}
376
358
}
377
359
360
+ // add the x-metaTags extension for product name
378
361
extensions. append ( & mut crate :: product_meta_as_extensions ( namespace, product_meta) ) ;
379
362
363
+ // split summary from description
364
+ let sum_desc = split_summary_desc ( & endpoint. description ) ;
365
+
380
366
// Create the operation, it will be repeated if we have several methods
381
367
let operation = openapiv3:: Operation {
382
368
tags : if let Some ( doc_tag) = & endpoint. doc_tag {
@@ -385,7 +371,7 @@ pub fn add_endpoint(
385
371
vec ! [ namespace. to_string( ) ]
386
372
} ,
387
373
summary : sum_desc. summary ,
388
- description : full_desc ,
374
+ description : sum_desc . description ,
389
375
external_docs : tac. convert_external_docs ( endpoint) ,
390
376
// external_docs: None, // Need values that differ from client purposes
391
377
operation_id : None , // set in clone_operation below with operation_counter
@@ -522,28 +508,6 @@ fn split_summary_desc(desc: &str) -> SplitDesc{
522
508
}
523
509
}
524
510
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
-
547
511
#[ derive( PartialEq , Debug ) ]
548
512
struct SplitDesc {
549
513
summary : Option < String > ,
0 commit comments