poem-web / poem

A full-featured and easy-to-use web framework with the Rust programming language.
Apache License 2.0
3.62k stars 295 forks source link

Implemented nullable fields for openapi spec generation #865

Open skytz opened 3 months ago

skytz commented 3 months ago

I've added the ability to set nullable fields on a struct with poem_api::Object derive.

Following the spec here: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#fixed-fields-20

Either for each individual field, with nullable attibute, or at the struct level with nullable_all.

It also solves this opened issue: https://github.com/poem-web/poem/issues/701

kidqueb commented 1 month ago

Gave this a shot and it worked great, thank you. Hopefully get this gets merged in soon.

Edit: Revisiting, I get the limitation now. Trying to get it to set optional/nullable fields to Some(None) for null, Some(Some(T)) for the value and None when its completely omitted..

Edit edit: Found MaybeUndefined and we're back to working great