Skip to content

Commit 56425ad

Browse files
authored
Allowing newlines in openapi description (#2717)
* removed newline escape * output regen
1 parent a409359 commit 56425ad

File tree

4 files changed

+309
-303
lines changed

4 files changed

+309
-303
lines changed

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,8 @@ fn get_path_parameters(template: &str) -> Vec<&str> {
321321
fn split_summary_desc(desc: &str) -> SplitDesc{
322322
let segmenter = SentenceSegmenter::new();
323323

324-
let desc_no_newlines = desc.replace("\n\n",".\n").replace('\n'," ");
325-
326324
let breakpoints: Vec<usize> = segmenter
327-
.segment_str(&desc_no_newlines)
325+
.segment_str(&desc)
328326
.collect();
329327

330328
if breakpoints.len()<2{
@@ -333,8 +331,8 @@ fn split_summary_desc(desc: &str) -> SplitDesc{
333331
description: None
334332
}
335333
}
336-
let first_line = &desc_no_newlines[breakpoints[0]..breakpoints[1]];
337-
let rest = &desc_no_newlines[breakpoints[1]..breakpoints[breakpoints.len()-1]];
334+
let first_line = &desc[breakpoints[0]..breakpoints[1]];
335+
let rest = &desc[breakpoints[1]..breakpoints[breakpoints.len()-1]];
338336

339337
SplitDesc {
340338
summary: Some(String::from(first_line.trim().strip_suffix('.').unwrap_or(first_line))),
@@ -370,20 +368,20 @@ mod tests {
370368
summary: Some(String::from("One sentence")),
371369
description: None
372370
});
373-
assert_eq!(split_summary_desc("This is\nstill one. sentence: all; together"),
371+
assert_eq!(split_summary_desc("This is - still one. sentence: all; together"),
374372
SplitDesc{
375-
summary: Some(String::from("This is still one. sentence: all; together")),
373+
summary: Some(String::from("This is - still one. sentence: all; together")),
376374
description: None
377375
});
378376
assert_eq!(split_summary_desc("These are two totally. Separate sentences!"),
379377
SplitDesc{
380378
summary: Some(String::from("These are two totally")),
381379
description: Some(String::from("Separate sentences!"))
382380
});
383-
assert_eq!(split_summary_desc("Such a weird way to separate sentences\n\nRight?"),
381+
assert_eq!(split_summary_desc("These -> \n are allowed \n because they're needed \n\n for \n\n\n formatting"),
384382
SplitDesc{
385-
summary: Some(String::from("Such a weird way to separate sentences")),
386-
description: Some(String::from("Right?"))
383+
summary: Some(String::from("These -> \n")),
384+
description: Some(String::from("are allowed \n because they're needed \n\n for \n\n\n formatting"))
387385
});
388386
assert_eq!(split_summary_desc(""),
389387
SplitDesc{
Binary file not shown.

0 commit comments

Comments
 (0)