Open lyssieth opened 1 year ago
It's not a bug, if you set this field to read-only
, then this object will be given a default value (via Default::default
) when used as a request, you may consider create a newtype MyOffsetDateTime
, and implement Default::default
for it.
Huh. That's definitely a bit strange, but I can understand it.
Is there a better way to handle a type that will only ever be returned from the server, and can't be sent to the server, then?
In v3.0.6
can use default
to specify a function that creates a default value, which is more convenient than defining a newtype.
fn default_offset_datetime() -> OffsetDateTime {
OffsetDateTime::now_utc()
}
#[derive(Debug, Object, PartialEq)]
struct Obj {
#[oai(read_only, default = "default_offset_datetime")]
time: OffsetDateTime,
}
I'll let you know when v3.0.5
is released. 🙂
Alright, thank you! I'll be keeping a keen eye out :>
I'm trying to create a type that contains a
time::OffsetDateTime
, but trying to deriveObject
on it with thetime
field being#[oai(read_only)]
(since it's determined by the server) fails to compile.I'm unsure whether I'm doing everything as expected by the API, or in general correctly.
Expected Behavior
Compiling as expected, without any warnings
Actual Behavior
error[E0277]: the trait bound
time::OffsetDateTime: std::default::Defaultis not satisfied
Steps to Reproduce the Problem
And then trying to compile.
Specifications
poem-openapi
v. 3.0.4time
v. 0.3.28stable-x86_64-unknown-linux-gnu
), but likely affects all