Skip to content

Commit

Permalink
Parse other number types as well and fix float (#454)
Browse files Browse the repository at this point in the history
  • Loading branch information
VersBinarii authored Dec 19, 2022
1 parent dabff24 commit 080e190
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions poem-openapi/src/types/external/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,15 @@ impl ParseFromJSON for Decimal {
num.as_i64()
.ok_or_else(|| ParseError::custom("Expected a number"))?,
)),
Value::Number(num) if num.is_f64() => Ok(Decimal::from_f64_retain(
Value::Number(num) if num.is_u64() => Ok(Decimal::from(
num.as_u64()
.ok_or_else(|| ParseError::custom("Expected a number"))?,
)),
Value::Number(num) if num.is_f64() => Ok(Decimal::try_from(
num.as_f64()
.ok_or_else(|| ParseError::custom("Expected a float"))?,
)
.ok_or_else(|| ParseError::custom("Error converting to decimal"))?),
.map_err(|_| ParseError::custom("Float out of range"))?),
_ => Err(ParseError::expected_type(value)),
}
}
Expand Down

0 comments on commit 080e190

Please sign in to comment.