1
0
Fork 0

better documentation for body params

This commit is contained in:
Cyborus 2024-02-09 16:10:02 -05:00
parent 7bab7c4a5f
commit 11c0798775
No known key found for this signature in database
2 changed files with 113 additions and 98 deletions

View file

@ -1,4 +1,4 @@
use crate::openapi::*;
use crate::{openapi::*, schema_ref_type_name};
use eyre::{OptionExt, WrapErr};
use heck::ToSnakeCase;
use std::fmt::Write;
@ -102,9 +102,8 @@ fn method_docs(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
}
for param in params {
let param = param.deref(spec)?;
match param._in {
match &param._in {
ParameterIn::Path { param: _ }
| ParameterIn::Body { schema: _ }
| ParameterIn::FormData { param: _ } => {
write!(&mut out, "/// - `{}`", param.name)?;
if let Some(description) = &param.description {
@ -112,6 +111,16 @@ fn method_docs(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
}
writeln!(&mut out)?;
}
ParameterIn::Body { schema } => {
write!(&mut out, "/// - `{}`", param.name)?;
let ty = schema_ref_type_name(spec, &schema)?;
if let Some(description) = &param.description {
write!(&mut out, ": {}\n\n/// See [`{}`]", description, ty)?;
} else {
write!(&mut out, ": See [`{}`]", ty)?;
}
writeln!(&mut out)?;
}
_ => (),
}
}