For array types whose items are nullable ({"type": ["T", "null"]}), contrib/schemagen/weaseljson_schemagen.py emits std::vector<std::optional<T>> (or std::vector<std::unique_ptr<T>> for recursive objects). However, the generated cbNull callback in the _builder template (lines 967-975) simply calls valueComplete() for nullable slots and never appends an empty element when the current frame is an array.
Parsing {"items": [null, "a", null]} succeeds, but the resulting items->size() is 1 and contains only "a". The two null entries are silently dropped, so vector indices no longer correspond to JSON array indices.
The same problem affects arrays of nullable integers, booleans, numbers, enums, objects, and root-level nullable arrays. For nullable object items using std::unique_ptr, a null element should append a null pointer; for std::optional items, an empty optional should be appended.
Expected behavior: every null item contributes one element to the generated container.
For array types whose items are nullable (`{"type": ["T", "null"]}`), `contrib/schemagen/weaseljson_schemagen.py` emits `std::vector<std::optional<T>>` (or `std::vector<std::unique_ptr<T>>` for recursive objects). However, the generated `cbNull` callback in the `_builder` template (lines 967-975) simply calls `valueComplete()` for nullable slots and never appends an empty element when the current frame is an array.
Reproducer schema:
```json
{
"type": "object",
"properties": {
"items": {
"type": "array",
"items": { "type": ["string", "null"] }
}
}
}
```
Parsing `{"items": [null, "a", null]}` succeeds, but the resulting `items->size()` is 1 and contains only `"a"`. The two `null` entries are silently dropped, so vector indices no longer correspond to JSON array indices.
The same problem affects arrays of nullable integers, booleans, numbers, enums, objects, and root-level nullable arrays. For nullable object items using `std::unique_ptr`, a `null` element should append a null pointer; for `std::optional` items, an empty optional should be appended.
Expected behavior: every `null` item contributes one element to the generated container.
weaselbot
was assigned by andrew2026-06-18 14:05:36 +00:00
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
For array types whose items are nullable (
{"type": ["T", "null"]}),contrib/schemagen/weaseljson_schemagen.pyemitsstd::vector<std::optional<T>>(orstd::vector<std::unique_ptr<T>>for recursive objects). However, the generatedcbNullcallback in the_buildertemplate (lines 967-975) simply callsvalueComplete()for nullable slots and never appends an empty element when the current frame is an array.Reproducer schema:
Parsing
{"items": [null, "a", null]}succeeds, but the resultingitems->size()is 1 and contains only"a". The twonullentries are silently dropped, so vector indices no longer correspond to JSON array indices.The same problem affects arrays of nullable integers, booleans, numbers, enums, objects, and root-level nullable arrays. For nullable object items using
std::unique_ptr, anullelement should append a null pointer; forstd::optionalitems, an empty optional should be appended.Expected behavior: every
nullitem contributes one element to the generated container.