Skip to content

Emit JSON Schema defaults for rfl::DefaultIfMissing (#396) - #78

Open
clockblocker wants to merge 7 commits into
mainfrom
json-schema-default-if-missing
Open

clockblocker wants to merge 7 commits into
mainfrom
json-schema-default-if-missing

Conversation

@clockblocker

Copy link
Copy Markdown
Owner

Summary

Extends rfl::json::to_schema<T, rfl::DefaultIfMissing>() to emit JSON Schema "default" annotations for default-constructible struct fields (including in-class member initializers), matching rfl::DefaultIfMissing read semantics while leaving to_schema<T>() without DefaultIfMissing completely unchanged.

Closes munich-data-engineering#396 (Note: #21 covers wrapped rfl::DefaultVal fields separately.)

Details

  • Parser_default::make_reference safely constructs T{} inside try / catch (...) when rfl::DefaultIfMissing is active and std::is_default_constructible_v<T> holds, falling back cleanly without defaults if construction throws.
  • NamedTupleParser::add_field_to_schema serializes field defaults from T{} via rfl::to_generic<ProcessorsType> (inside try / catch (...)), preserves explicit rfl::DefaultVal fields without duplication, and skips emitting "default": null for empty nullable fields (std::optional, std::unique_ptr, std::shared_ptr, raw pointers) while emitting initialized values (including falsy 0/false/"").
  • Constrained default constructors on wrappers (Variant, Rename, Description, Deprecated, DefaultVal, Commented, Skip, Validator) so std::is_default_constructible_v accurately reports false for wrapped non-default-constructible types.
  • Added comprehensive tests in tests/json/test_json_schema_default_if_missing.cpp, updated tests/json/test_json_schema4.cpp, and documented behavior in docs/content/json_schema.md.

Verification

  • ctest -R "(schema|default)": 76/76 PASSED.
  • Full ctest suite under -Wall -Werror: 592/592 PASSED.

@clockblocker
clockblocker force-pushed the json-schema-default-if-missing branch from addde84 to 8c37c58 Compare November 27, 2026 20:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Add support to JSON Schema "default" keyword

1 participant