format
This commit is contained in:
parent
4ccdce0395
commit
2b1e6a8aae
|
@ -106,7 +106,9 @@ fn method_docs(op: &Operation) -> eyre::Result<String> {
|
|||
MaybeRef::Ref { _ref } => eyre::bail!("pipis"),
|
||||
};
|
||||
match param._in {
|
||||
ParameterIn::Path { param: _ } | ParameterIn::Body { schema: _ } | ParameterIn::FormData { param: _ } => {
|
||||
ParameterIn::Path { param: _ }
|
||||
| ParameterIn::Body { schema: _ }
|
||||
| ParameterIn::FormData { param: _ } => {
|
||||
write!(&mut out, "/// - `{}`", param.name)?;
|
||||
if let Some(description) = ¶m.description {
|
||||
write!(&mut out, ": {}", description)?;
|
||||
|
@ -178,7 +180,12 @@ fn fn_args_from_op(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
|
|||
}
|
||||
|
||||
pub fn param_type(param: &NonBodyParameter, owned: bool) -> eyre::Result<String> {
|
||||
param_type_inner(¶m._type, param.format.as_deref(), param.items.as_ref(), owned)
|
||||
param_type_inner(
|
||||
¶m._type,
|
||||
param.format.as_deref(),
|
||||
param.items.as_ref(),
|
||||
owned,
|
||||
)
|
||||
}
|
||||
|
||||
fn param_type_inner(
|
||||
|
@ -361,10 +368,11 @@ fn create_method_request(
|
|||
|
||||
fn param_is_string(spec: &OpenApiV2, param: &Parameter) -> eyre::Result<bool> {
|
||||
match ¶m._in {
|
||||
ParameterIn::Body { schema } => {
|
||||
crate::schema_is_string(spec, schema)
|
||||
}
|
||||
ParameterIn::Path { param } | ParameterIn::Query { param } | ParameterIn::Header { param } | ParameterIn::FormData { param } => {
|
||||
ParameterIn::Body { schema } => crate::schema_is_string(spec, schema),
|
||||
ParameterIn::Path { param }
|
||||
| ParameterIn::Query { param }
|
||||
| ParameterIn::Header { param }
|
||||
| ParameterIn::FormData { param } => {
|
||||
let is_str = match param._type {
|
||||
ParameterType::String => true,
|
||||
_ => false,
|
||||
|
@ -403,10 +411,7 @@ fn sanitize_path_arg(mut path: &str) -> eyre::Result<String> {
|
|||
Ok(out)
|
||||
}
|
||||
|
||||
fn create_method_response(
|
||||
spec: &OpenApiV2,
|
||||
op: &Operation,
|
||||
) -> eyre::Result<String> {
|
||||
fn create_method_response(spec: &OpenApiV2, op: &Operation) -> eyre::Result<String> {
|
||||
let mut has_empty = false;
|
||||
let mut only_empty = true;
|
||||
for (code, res) in &op.responses.http_codes {
|
||||
|
|
|
@ -248,19 +248,18 @@ impl ParameterIn {
|
|||
fn validate(&self) -> eyre::Result<()> {
|
||||
match self {
|
||||
ParameterIn::Path { param } => {
|
||||
eyre::ensure!(
|
||||
param.required,
|
||||
"path parameters must be required"
|
||||
);
|
||||
eyre::ensure!(param.required, "path parameters must be required");
|
||||
param.validate().wrap_err("path param")
|
||||
},
|
||||
}
|
||||
ParameterIn::Query { param } => param.validate().wrap_err("query param"),
|
||||
ParameterIn::Header { param } => param.validate().wrap_err("header param"),
|
||||
ParameterIn::Body { schema } => if let MaybeRef::Value { value } = schema {
|
||||
ParameterIn::Body { schema } => {
|
||||
if let MaybeRef::Value { value } = schema {
|
||||
value.validate().wrap_err("body param")
|
||||
} else {
|
||||
Ok(())
|
||||
},
|
||||
}
|
||||
}
|
||||
ParameterIn::FormData { param } => param.validate().wrap_err("form param"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -97,9 +97,7 @@ fn create_struct_docs(schema: &Schema) -> eyre::Result<String> {
|
|||
Ok(doc)
|
||||
}
|
||||
|
||||
pub fn create_query_structs_for_path(
|
||||
item: &PathItem,
|
||||
) -> eyre::Result<String> {
|
||||
pub fn create_query_structs_for_path(item: &PathItem) -> eyre::Result<String> {
|
||||
let mut s = String::new();
|
||||
if let Some(op) = &item.get {
|
||||
s.push_str(&create_query_struct(op).wrap_err("GET")?);
|
||||
|
@ -199,7 +197,9 @@ fn create_query_struct(op: &Operation) -> eyre::Result<String> {
|
|||
)?;
|
||||
}
|
||||
ParameterType::Array => {
|
||||
let format = query_param.collection_format.unwrap_or(CollectionFormat::Csv);
|
||||
let format = query_param
|
||||
.collection_format
|
||||
.unwrap_or(CollectionFormat::Csv);
|
||||
let item = query_param
|
||||
.items
|
||||
.as_ref()
|
||||
|
|
Loading…
Reference in a new issue