Skip to content

Commit

Permalink
Merge branch 'main' into rollover-etc-summaries
Browse files Browse the repository at this point in the history
  • Loading branch information
shainaraskas committed Jul 17, 2024
2 parents d6fd9c8 + 5615a46 commit 52a517b
Show file tree
Hide file tree
Showing 15 changed files with 630 additions and 421 deletions.
16 changes: 13 additions & 3 deletions compiler-rs/clients_schema_to_openapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::io::{BufWriter, Write};
use std::path::Path;
use indexmap::IndexMap;

use clients_schema::{Availabilities, Endpoint, IndexedModel};
use clients_schema::{Availabilities, Endpoint, IndexedModel, Stability};
use openapiv3::{Components, OpenAPI};
use tracing::warn;

Expand Down Expand Up @@ -149,15 +149,25 @@ fn info(model: &IndexedModel) -> openapiv3::Info {
}
}

pub fn availability_as_extension(availabilities: &Option<Availabilities>) -> IndexMap<String, serde_json::Value> {
pub fn availability_as_extensions(availabilities: &Option<Availabilities>) -> IndexMap<String, serde_json::Value> {
let mut result = IndexMap::new();

if let Some(avails) = availabilities {
// We may have several availabilities, but since generally exists only on stateful (stack)
for (_, availability) in avails {
if let Some(since) = &availability.since {
result.insert("x-available-since".to_string(), serde_json::Value::String(since.clone()));
break;
}
if let Some(stability) = &availability.stability {
match stability {
Stability::Beta => {
result.insert("x-beta".to_string(), serde_json::Value::Bool(true));
}
Stability::Experimental => {
result.insert("x-technical-preview".to_string(), serde_json::Value::Bool(true));
}
_ => {}
}
}
}
}
Expand Down
20 changes: 9 additions & 11 deletions compiler-rs/clients_schema_to_openapi/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ pub fn add_endpoint(
deprecated: endpoint.deprecation.is_some(),
security: None,
servers: vec![],
extensions: crate::availability_as_extension(&endpoint.availability),
extensions: crate::availability_as_extensions(&endpoint.availability),
};


Expand Down Expand Up @@ -321,10 +321,8 @@ fn get_path_parameters(template: &str) -> Vec<&str> {
fn split_summary_desc(desc: &str) -> SplitDesc{
let segmenter = SentenceSegmenter::new();

let desc_no_newlines = desc.replace("\n\n",".\n").replace('\n'," ");

let breakpoints: Vec<usize> = segmenter
.segment_str(&desc_no_newlines)
.segment_str(&desc)
.collect();

if breakpoints.len()<2{
Expand All @@ -333,8 +331,8 @@ fn split_summary_desc(desc: &str) -> SplitDesc{
description: None
}
}
let first_line = &desc_no_newlines[breakpoints[0]..breakpoints[1]];
let rest = &desc_no_newlines[breakpoints[1]..breakpoints[breakpoints.len()-1]];
let first_line = &desc[breakpoints[0]..breakpoints[1]];
let rest = &desc[breakpoints[1]..breakpoints[breakpoints.len()-1]];

SplitDesc {
summary: Some(String::from(first_line.trim().strip_suffix('.').unwrap_or(first_line))),
Expand Down Expand Up @@ -370,20 +368,20 @@ mod tests {
summary: Some(String::from("One sentence")),
description: None
});
assert_eq!(split_summary_desc("This is\nstill one. sentence: all; together"),
assert_eq!(split_summary_desc("This is - still one. sentence: all; together"),
SplitDesc{
summary: Some(String::from("This is still one. sentence: all; together")),
summary: Some(String::from("This is - still one. sentence: all; together")),
description: None
});
assert_eq!(split_summary_desc("These are two totally. Separate sentences!"),
SplitDesc{
summary: Some(String::from("These are two totally")),
description: Some(String::from("Separate sentences!"))
});
assert_eq!(split_summary_desc("Such a weird way to separate sentences\n\nRight?"),
assert_eq!(split_summary_desc("These -> \n are allowed \n because they're needed \n\n for \n\n\n formatting"),
SplitDesc{
summary: Some(String::from("Such a weird way to separate sentences")),
description: Some(String::from("Right?"))
summary: Some(String::from("These -> \n")),
description: Some(String::from("are allowed \n because they're needed \n\n for \n\n\n formatting"))
});
assert_eq!(split_summary_desc(""),
SplitDesc{
Expand Down
2 changes: 1 addition & 1 deletion compiler-rs/clients_schema_to_openapi/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ impl<'a> TypesAndComponents<'a> {
data.external_docs = self.convert_external_docs(prop);
data.deprecated = prop.deprecation.is_some();
data.description = prop.description.clone();
data.extensions = crate::availability_as_extension(&prop.availability);
data.extensions = crate::availability_as_extensions(&prop.availability);
// TODO: prop.aliases as extensions
// TODO: prop.server_default as extension
// TODO: prop.doc_id as extension (new representation of since and stability)
Expand Down
Binary file modified compiler-rs/compiler-wasm-lib/pkg/compiler_wasm_lib_bg.wasm
Binary file not shown.
Loading

0 comments on commit 52a517b

Please sign in to comment.