@@ -21,6 +21,7 @@ use std::fmt::Write;
21
21
use anyhow:: { anyhow, bail} ;
22
22
use clients_schema:: Property ;
23
23
use indexmap:: indexmap;
24
+ use icu_segmenter:: SentenceSegmenter ;
24
25
use openapiv3:: {
25
26
MediaType , Parameter , ParameterData , ParameterSchemaOrContent , PathItem , PathStyle , Paths , QueryStyle , ReferenceOr ,
26
27
RequestBody , Response , Responses , StatusCode ,
@@ -191,13 +192,13 @@ pub fn add_endpoint(
191
192
192
193
parameters. append ( & mut query_params. clone ( ) ) ;
193
194
194
- let sum_desc = split_summary_desc ( endpoint. description . clone ( ) ) ;
195
+ let sum_desc = split_summary_desc ( & endpoint. description ) ;
195
196
196
197
// Create the operation, it will be repeated if we have several methods
197
198
let operation = openapiv3:: Operation {
198
199
tags : vec ! [ endpoint. name. clone( ) ] ,
199
- summary : Some ( sum_desc. summary ) ,
200
- description : Some ( sum_desc. description ) ,
200
+ summary : sum_desc. summary ,
201
+ description : sum_desc. description ,
201
202
external_docs : tac. convert_external_docs ( endpoint) ,
202
203
operation_id : None , // set in clone_operation below with operation_counter
203
204
parameters,
@@ -313,23 +314,31 @@ fn get_path_parameters(template: &str) -> Vec<&str> {
313
314
result
314
315
}
315
316
316
- fn split_summary_desc ( desc : String ) -> SplitDesc {
317
- let mut parts = desc. split ( [ '.' , '\n' , ':' ] ) ;
318
- let first_line = parts. next ( ) . unwrap_or_else ( || "" ) ;
319
-
320
- let new_desc = desc. replace ( first_line, "" ) ;
321
- let trim = new_desc. trim ( ) ;
322
- let remove_period = trim. strip_prefix ( '.' ) . unwrap_or_else ( || trim) ;
323
- let remove_column = remove_period. strip_prefix ( ':' ) . unwrap_or_else ( || remove_period) ;
317
+ fn split_summary_desc ( desc : & str ) -> SplitDesc {
318
+ let segmenter = SentenceSegmenter :: new ( ) ;
319
+
320
+ let breakpoints: Vec < usize > = segmenter
321
+ . segment_str ( desc)
322
+ . collect ( ) ;
323
+
324
+ if breakpoints. len ( ) <2 {
325
+ return SplitDesc {
326
+ summary : None ,
327
+ description : None
328
+ }
329
+ }
330
+ let first_line = & desc[ breakpoints[ 0 ] ..breakpoints[ 1 ] ] ;
331
+ let rest = & desc[ breakpoints[ 1 ] ..breakpoints[ breakpoints. len ( ) -1 ] ] ;
332
+
324
333
SplitDesc {
325
- summary : String :: from ( first_line. trim ( ) ) ,
326
- description : String :: from ( remove_column . trim ( ) )
334
+ summary : Option :: from ( String :: from ( first_line. trim ( ) . strip_suffix ( '.' ) . unwrap_or ( first_line ) ) ) ,
335
+ description : if !rest . is_empty ( ) { Option :: from ( String :: from ( rest . trim ( ) ) ) } else { None }
327
336
}
328
337
}
329
338
330
339
struct SplitDesc {
331
- summary : String ,
332
- description : String
340
+ summary : Option < String > ,
341
+ description : Option < String >
333
342
}
334
343
335
344
#[ cfg( test) ]
0 commit comments