Skip to content

Commit 38d8bd7

Browse files
committed
removing newlines + unit test
1 parent b135142 commit 38d8bd7

File tree

4 files changed

+41
-21
lines changed

4 files changed

+41
-21
lines changed

compiler-rs/clients_schema_to_openapi/src/paths.rs

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,10 @@ fn get_path_parameters(template: &str) -> Vec<&str> {
317317
fn split_summary_desc(desc: &str) -> SplitDesc{
318318
let segmenter = SentenceSegmenter::new();
319319

320+
let desc_no_newlines = desc.replace('\n'," ");
321+
320322
let breakpoints: Vec<usize> = segmenter
321-
.segment_str(desc)
323+
.segment_str(&desc_no_newlines)
322324
.collect();
323325

324326
if breakpoints.len()<2{
@@ -327,15 +329,16 @@ fn split_summary_desc(desc: &str) -> SplitDesc{
327329
description: None
328330
}
329331
}
330-
let first_line = &desc[breakpoints[0]..breakpoints[1]];
331-
let rest = &desc[breakpoints[1]..breakpoints[breakpoints.len()-1]];
332+
let first_line = &desc_no_newlines[breakpoints[0]..breakpoints[1]];
333+
let rest = &desc_no_newlines[breakpoints[1]..breakpoints[breakpoints.len()-1]];
332334

333335
SplitDesc {
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}
336+
summary: Some(String::from(first_line.trim().strip_suffix('.').unwrap_or(first_line))),
337+
description: if !rest.is_empty() {Some(String::from(rest.trim()))} else {None}
336338
}
337339
}
338340

341+
#[derive(PartialEq,Debug)]
339342
struct SplitDesc {
340343
summary: Option<String>,
341344
description: Option<String>
@@ -355,4 +358,28 @@ mod tests {
355358
assert_eq!(get_path_parameters("{index}{id/"), vec! {"index"});
356359
assert_eq!(get_path_parameters("{index{id}/"), vec! {"index{id"});
357360
}
361+
362+
#[test]
363+
fn test_split_summary_desc() {
364+
assert_eq!(split_summary_desc("One sentence."),
365+
SplitDesc{
366+
summary: Some(String::from("One sentence")),
367+
description: None
368+
});
369+
assert_eq!(split_summary_desc("This is\nstill one. sentence: all; together"),
370+
SplitDesc{
371+
summary: Some(String::from("This is still one. sentence: all; together")),
372+
description: None
373+
});
374+
assert_eq!(split_summary_desc("These are two totally. Separate sentences!"),
375+
SplitDesc{
376+
summary: Some(String::from("These are two totally")),
377+
description: Some(String::from("Separate sentences!"))
378+
});
379+
assert_eq!(split_summary_desc(""),
380+
SplitDesc{
381+
summary: None,
382+
description: None
383+
});
384+
}
358385
}
Binary file not shown.

output/openapi/elasticsearch-openapi.json

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,8 +3800,7 @@
38003800
"tags": [
38013801
"cluster.pending_tasks"
38023802
],
3803-
"summary": "Returns a list of any cluster-level changes (e.g. create index, update mapping,\n",
3804-
"description": "allocate or fail shard) which have not yet been executed.",
3803+
"summary": "Returns a list of any cluster-level changes (e.g. create index, update mapping, allocate or fail shard) which have not yet been executed",
38053804
"externalDocs": {
38063805
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-pending.html"
38073806
},
@@ -14021,8 +14020,7 @@
1402114020
"tags": [
1402214021
"indices.rollover"
1402314022
],
14024-
"summary": "Updates an alias to point to a new index when the existing index\n",
14025-
"description": "is considered to be too large or too old.",
14023+
"summary": "Updates an alias to point to a new index when the existing index is considered to be too large or too old",
1402614024
"externalDocs": {
1402714025
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html"
1402814026
},
@@ -14059,8 +14057,7 @@
1405914057
"tags": [
1406014058
"indices.rollover"
1406114059
],
14062-
"summary": "Updates an alias to point to a new index when the existing index\n",
14063-
"description": "is considered to be too large or too old.",
14060+
"summary": "Updates an alias to point to a new index when the existing index is considered to be too large or too old",
1406414061
"externalDocs": {
1406514062
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-rollover-index.html"
1406614063
},
@@ -24716,8 +24713,7 @@
2471624713
"tags": [
2471724714
"reindex"
2471824715
],
24719-
"summary": "Allows to copy documents from one index to another, optionally filtering the source\n",
24720-
"description": "documents by a query, changing the destination index settings, or fetching the\ndocuments from a remote cluster.",
24716+
"summary": "Allows to copy documents from one index to another, optionally filtering the source documents by a query, changing the destination index settings, or fetching the documents from a remote cluster",
2472124717
"externalDocs": {
2472224718
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-reindex.html"
2472324719
},
@@ -34733,7 +34729,7 @@
3473334729
"update_by_query"
3473434730
],
3473534731
"summary": "Updates documents that match the specified query",
34736-
"description": "If no query is specified,\n performs an update on every document in the index without changing the source,\nfor example to pick up a mapping change.",
34732+
"description": "If no query is specified, performs an update on every document in the index without changing the source, for example to pick up a mapping change.",
3473734733
"externalDocs": {
3473834734
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/docs-update-by-query.html"
3473934735
},

output/openapi/elasticsearch-serverless-openapi.json

Lines changed: 4 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)