Add JSON Schema validation, JSON Pointer, JSON Patch and JSON Merge Patch support to jansson_ext - #842
Add JSON Schema validation, JSON Pointer, JSON Patch and JSON Merge Patch support to jansson_ext#842PengZheng wants to merge 42 commits into
Conversation
… test coverage, and fix double free.
…management consistency
…proving error handling for circular references
…istency, improve code coverage, and fix a leak.
…lidator and update email format tests
…s and updating related test cases
… and malformed pointers, and update related tests for comprehensive coverage.
…ring buffer functions
… maps for properties and dependencies, improving memory management and performance.
…r null values and self-references, ensuring robust behavior during JSON manipulation.
…and improving error handling during allocation failures, ensuring robust behavior in URI operations.
…e-zeroing requirement, adding automatic cleanup support, and improving memory management in patch operations.
…vided buffers, ensuring proper clearing before use to prevent memory leaks.
…roving buffer reuse, ensuring robust memory management during URI operations.
Close the remaining OOM gaps in celix_jansson_schema.c so that every allocation failure either propagates as an error code or fails the validation closed, instead of crashing, leaking, or silently producing wrong results: - Runtime validators: first-error sinks, the propertyNames key wrapper and the combination error propagation no longer dereference NULL on OOM; path building fail-closes with an out-of-memory error through the shared path_child_checked helper - Compile time: strdup of pattern/format/contentEncoding/required names and json_deep_copy of enum/const now propagate NOMEM instead of storing NULL state that misbehaves at validation time - Registry: celix_stringHashMap_put and retained-vec pushes are checked, so a failed registration returns NOMEM instead of leaking the node and masking itself as a later REF_UNRESOLVED; the document-fragment walk aborts on a failed $id base derivation instead of continuing with a stale base - validate/validate_uri fail with -1 when the patch array cannot be allocated, matching the existing sink-allocation convention - patternProperties regex compilation is checked like the string pattern keyword and reports INVALID_PATTERN Co-Authored-By: Claude <noreply@anthropic.com>
Cover emit_error_v's `ps = ""` fallback, which runs only when celix_jansson_path_str returns NULL after its empty-string strdup fails on OOM. Injecting strdup at path_str (its only strdup call site) makes path_str return NULL and verifies the type error is still reported with an empty path instead of a NULL one. Co-Authored-By: Claude <noreply@anthropic.com>
Second hardening pass over celix_jansson_schema.c: - required/dependencies arrays with a non-string entry no longer crash on strdup(NULL) but are rejected with INVALID_SCHEMA - the not/allOf/anyOf/oneOf logic vec_push failures now release the stolen node and the collected entries and propagate NOMEM, instead of leaking the node and silently dropping the keyword - the default-fill patch path guards a NULL path_str result before snprintf, and celix_json_patch_add failures (OOM) fail the validation closed with an out-of-memory error instead of silently dropping the default patch (both the property and the root-default sites) - json_deep_copy of "default" propagates NOMEM like enum/const instead of silently dropping the default - has_pattern is only set after regcomp succeeds, so a failed regex_t is never regfree'd (undefined behavior per POSIX) Co-Authored-By: Claude <noreply@anthropic.com>
Nine tests covering the new error paths: logic vec_push OOM for not and combo nodes, non-string required/dependencies entries, the default-fill path when path_str returns NULL, default deep_copy OOM for both the type-schema and $ref forms, and patch_add OOM for property and root defaults. celix_json_patch.h is now included for the patch_add caller reference. Coverage stays at 100% for celix_jansson_schema.c. Co-Authored-By: Claude <noreply@anthropic.com>
…nd improve path management with automatic cleanup
- Remove the 'shared' option from the celix recipe: declaring it made Conan treat the celix package as a shared library, which stopped transitive dependencies (mdnsresponder for DNSSD, civetweb headers) from propagating to the test_package consumer. - Bound the openssl override to <4.0.0: fresh dependency resolutions now pick openssl/4.0.1, which civetweb/1.16 cannot compile against. - Expose the celix lib dir via runenv_info in package_info so consumers can find the shared libraries at runtime (previously masked by the shared option). - Drop the now-unneeded jansson requires from the test package. Co-Authored-By: Claude <noreply@anthropic.com>
StrCacheInvalidatedOnPush/Pop compared the pointer to the freed cached string with the new allocation. glibc malloc routinely reuses the just freed address, so the tests failed on non-sanitizer builds (e.g. the coverage workflow) while passing under ASan's quarantine allocator. Assert the rebuilt path content instead, which still catches a stale cache while being deterministic. Co-Authored-By: Claude <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #842 +/- ##
==========================================
+ Coverage 91.62% 92.40% +0.77%
==========================================
Files 235 247 +12
Lines 28787 31884 +3097
==========================================
+ Hits 26377 29463 +3086
- Misses 2410 2421 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
lcov 2.x fails the capture step with "mismatched end line" when gcov reports several functions sharing a start line with different end lines (e.g. gtest TEST_F bodies and their synthesized ctor/dtors), and fails the --remove step when an exclude pattern matches nothing. Both are new checks in lcov 2.x; the corresponding --ignore-errors categories (mismatch/inconsistent for lcov 2.0/2.1+, unused) do not exist in lcov 1.x, where unknown categories are fatal, so the flags are gated on the lcov major version. CI (Ubuntu 22.04, lcov 1.x) is unaffected. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
|
Very interesting. I did a quick look and this looks like a nice addition. I do need some time to review this correctly, but will start planning that. BTW, I was also working on JSONPath and extending array list and properties so that a more complete JSON support is possible (NULL value, mixed array support, nested properties). When this has been reviewed and merged, I will see if the NULL value, mixed array support and nested properties is still needed. In this branch I was working on, filter also has some support for JSONPath usage; But I was not yet sure too keep that (possible high performance impact on filter evaluation and therefore service lookup). |
This PR lays the foundation of a future JSON Config work, which is a Configuration Admin variant that uses JSON instead of properties. The biggest advantage of using JSON is that we can use JSON Schema as the OSGi Metatype Service for free!
Summary
This PR adds JSON Schema (draft-07) validation, JSON Pointer, JSON Patch, and JSON Merge Patch support to the new
jansson_extlibrary, along with the supporting infrastructure needed to make it production-ready.New capabilities
celix_jansson_schema.h): draft-07 keyword support,$refresolution including remote references, recursion depth guard for circular references, abort-on-first-error mode, and a full instance-path reporting mechanism.celix_jansson_pointer.h): parse/evaluate pointers with buffer-reuse and automatic cleanup support.celix_json_patch.h): apply/validate patch documents, with self-reference and null-value guards.celix_json_merge_patch.h): RFC 7396 merge patch application — null members remove the corresponding member, non-object patches replace the whole document — with full RFC 7396 test coverage (including Appendix A.16) and error-injection tests for all OOM paths.celix_jansson_uri):uriformat validation with array-index and malformed-pointer checks, IPv6 zone-id rejection, and automatic cleanup of URI resources.properties/dependencieshandling refactored from hash tables to string hash maps for better memory management.Robustness & hardening
error-injection(EI) tests covering the OOM paths (stdio_eivsnprintf support added).Tests & tooling
celix_util.hwith unit tests for string buffer functions.test_packagesupport forjansson_ext, including JSON Merge Patch coverage.--ignore-errorsflags for gcov end-line inconsistencies and unused exclude patterns).rat-excludes.txtupdated for the vendored JSON-Schema-Test-Suite corpus.Files
132 files changed, ~28k insertions. The bulk is
libs/jansson_ext/(new library sources, headers, examples, and tests).🤖 Generated with Claude Code