Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Fixed

- A generated Python model rejects an explicit `None` for an omittable field whose type serde can't read from `null`. Since 0.21 the client sends an explicit `None` as `null`, which the server refuses, so `Model(page=None)` for a `#[serde(default)] page: Page` failed with a 400. It now raises a `ValidationError` where the model is built. Leaving the field out is unchanged. Whether a value may be `null` is now part of the shared field contract and is decided from the schema, not from Python's rendered annotation. Before, only primitives and containers were checked. Now these reject `null` too: structs with fields, tuple structs, tagged enums, newtypes and wrappers such as `Box` of those, and primitives such as `chrono::DateTime`, `uuid::Uuid` and `url::Url`. Unit structs, untagged enums with a variant that accepts `null`, newtypes of an `Option`, generic parameters and fields with a custom codec on their side (`deserialize_with` in a request, `serialize_with` in a response), including a newtype's inner field, still accept `None`.
- A generated Python module with an omittable field of a unit type, `()` or a unit struct, imports again. The field was annotated `None | None`, which Python can't evaluate, so importing the module raised `TypeError`. It is now `None`.

## 0.23.0

Expand Down
22 changes: 22 additions & 0 deletions reflectapi-demo/src/tests/serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,28 @@ fn test_struct_with_serde_default_named_types() {
assert_snapshot!(TestStructWithSerdeDefaultNamedTypes);
}

#[derive(Default, reflectapi::Input, reflectapi::Output, serde::Deserialize, serde::Serialize)]
struct TestUnitMarker;

#[derive(Default, reflectapi::Input, reflectapi::Output, serde::Deserialize, serde::Serialize)]
struct TestOptionalNewtype(Option<String>);

/// Each type already renders with `None` in it, so the omission default
/// must not add another.
#[derive(reflectapi::Input, reflectapi::Output, serde::Deserialize, serde::Serialize)]
struct TestStructWithSerdeDefaultNoneTypes {
#[serde(default)]
marker: TestUnitMarker,
#[serde(default)]
nothing: (),
#[serde(default)]
optional_newtype: TestOptionalNewtype,
}
#[test]
fn test_struct_with_serde_default_none_types() {
assert_snapshot!(TestStructWithSerdeDefaultNoneTypes);
}

#[derive(reflectapi::Input, reflectapi::Output, serde::Deserialize, serde::Serialize)]
struct TestStructWithSerdeSkip {
#[serde(skip)]
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading