Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

[package]
name = "endpoint-gen"
version = "1.9.0"
version = "1.10.0"
edition = "2024"
repository = "https://github.com/pathscale/EndpointGen/"
description = "Generate Rust code for websocket API endpoints"
license = "MIT"

[dependencies]
# Internal dependencies
endpoint-libs = "1.9.0"
endpoint-libs = "2.0.0-alpha.1"
endpoint-gen-macros = { path = "./endpoint-gen-macros", version = "1.3.4" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
75 changes: 54 additions & 21 deletions src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,29 @@ impl ToRust for EnumElement {
let mut fields = fields
.iter()
.map(|x| {
format!(
r#"
let variant_name = if x.name.chars().last().unwrap().is_lowercase() {
x.name.to_case(Case::Pascal)
} else {
x.name.clone()
};
// A blank description must omit the `///` line entirely: an
// empty doc comment trips clippy::empty_docs downstream.
if x.description.trim().is_empty() {
format!(
r#"
{} = {}
"#,
variant_name, x.value
)
} else {
format!(
r#"
/// {}
{} = {}
"#,
x.description,
if x.name.chars().last().unwrap().is_lowercase() {
x.name.to_case(Case::Pascal)
} else {
x.name.clone()
},
x.value
)
x.description, variant_name, x.value
)
}
})
.sorted_by(|a, b| {
// Sort by the endpoint code
Expand Down Expand Up @@ -417,17 +427,11 @@ pub struct EndpointSchemaElement {

impl From<EndpointSchemaElement> for EndpointSchema {
fn from(val: EndpointSchemaElement) -> Self {
EndpointSchema {
name: val.schema.name,
code: val.schema.code,
parameters: val.schema.parameters,
returns: val.schema.returns,
stream_response: val.schema.stream_response,
description: val.schema.description,
json_schema: val.schema.json_schema,
roles: val.schema.roles,
errors: val.schema.errors,
}
// Was a field-by-field copy, which `#[non_exhaustive]` (endpoint-libs 2.0)
// now forbids from outside that crate — and which was always a no-op, since
// the source field *is* an EndpointSchema. Moving it also means new fields
// (e.g. `meta`) are carried through automatically instead of being dropped.
val.schema
}
}

Expand Down Expand Up @@ -457,3 +461,32 @@ impl GenElement<EndpointSchemaListDefinition> for EndpointSchemaListDefinition {
Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;
use endpoint_libs::model::EnumVariant;

#[test]
fn enum_element_decl_omits_doc_comment_for_blank_descriptions() {
let element = EnumElement {
config: RustGenConfig::default(),
inner: Type::enum_(
"sample",
vec![
EnumVariant::new_with_description("Documented", "Has docs.", 0),
EnumVariant::new("Bare", 1),
EnumVariant::new_with_description("Blank", " ", 2),
],
),
};
let decl = element.to_rust_decl(false, false);
assert!(decl.contains("/// Has docs."));
assert!(
!decl.lines().any(|l| l.trim() == "///"),
"empty doc comment emitted (clippy::empty_docs):\n{decl}"
);
assert!(decl.contains("Bare = 1"));
assert!(decl.contains("Blank = 2"));
}
}
Loading
Loading