(
service: &ServiceInfo,
method: &MethodInfo,
svc_cfg: &ServiceConfig<'_>,
schema_builder: &mut SchemaBuilder<'_>,
)
| 319 | } |
| 320 | |
| 321 | fn build_operation( |
| 322 | service: &ServiceInfo, |
| 323 | method: &MethodInfo, |
| 324 | svc_cfg: &ServiceConfig<'_>, |
| 325 | schema_builder: &mut SchemaBuilder<'_>, |
| 326 | ) -> Result<Value> { |
| 327 | let mut operation = Map::new(); |
| 328 | let tag = svc_cfg |
| 329 | .tag |
| 330 | .as_ref() |
| 331 | .map(|t| t.to_string()) |
| 332 | .unwrap_or_else(|| service.full_name.clone()); |
| 333 | operation.insert("tags".into(), Value::Array(vec![Value::String(tag)])); |
| 334 | operation.insert( |
| 335 | "operationId".into(), |
| 336 | Value::String(format!( |
| 337 | "{}_{}", |
| 338 | service.full_name.replace('.', "_"), |
| 339 | method.name |
| 340 | )), |
| 341 | ); |
| 342 | let summary = method |
| 343 | .description |
| 344 | .as_deref() |
| 345 | .and_then(|doc| doc.lines().find(|line| !line.trim().is_empty())) |
| 346 | .map(|line| line.trim().to_string()) |
| 347 | .unwrap_or_else(|| method.name.clone()); |
| 348 | operation.insert("summary".into(), Value::String(summary)); |
| 349 | |
| 350 | let mut description_parts = Vec::new(); |
| 351 | if let Some(doc) = method.description.as_deref() { |
| 352 | let trimmed = doc.trim(); |
| 353 | if !trimmed.is_empty() { |
| 354 | description_parts.push(trimmed.to_string()); |
| 355 | } |
| 356 | } |
| 357 | let mut base = format!( |
| 358 | "pRPC method `{}` on service `{}`.", |
| 359 | method.name, service.full_name |
| 360 | ); |
| 361 | if let Some(extra) = svc_cfg |
| 362 | .description |
| 363 | .as_ref() |
| 364 | .map(|c| c.as_ref()) |
| 365 | .or(service.description.as_deref()) |
| 366 | { |
| 367 | base.push_str("\n\n"); |
| 368 | base.push_str(extra); |
| 369 | } |
| 370 | description_parts.push(base); |
| 371 | let description = description_parts.join("\n\n"); |
| 372 | operation.insert("description".into(), Value::String(description)); |
| 373 | |
| 374 | if !is_empty_type(&method.input_type) { |
| 375 | let schema = schema_builder.schema_ref(&method.input_type)?; |
| 376 | let request = json!({ |
| 377 | "required": true, |
| 378 | "content": { |
no test coverage detected