Skip to content

Commit

Permalink
feat: Allow more types to be prased into strings (#545)
Browse files Browse the repository at this point in the history
  • Loading branch information
VersBinarii authored Jun 6, 2023
1 parent 282e8b3 commit 4b149b0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions poem-openapi/src/types/external/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,11 @@ impl Type for String {
impl ParseFromJSON for String {
fn parse_from_json(value: Option<Value>) -> ParseResult<Self> {
let value = value.unwrap_or_default();
if let Value::String(value) = value {
Ok(value)
} else {
Err(ParseError::expected_type(value))
match value {
Value::String(val) => Ok(val),
Value::Number(num) => Ok(num.to_string()),
Value::Bool(val) => Ok(val.to_string()),
_ => Err(ParseError::expected_type(value)),
}
}
}
Expand Down

0 comments on commit 4b149b0

Please sign in to comment.