Skip to content

Add JSON Schema validation, JSON Pointer and JSON Patch support to jansson_ext - #842

Draft
PengZheng wants to merge 39 commits into
masterfrom
feature/json-schema
Draft

Add JSON Schema validation, JSON Pointer and JSON Patch support to jansson_ext#842
PengZheng wants to merge 39 commits into
masterfrom
feature/json-schema

Conversation

@PengZheng

@PengZheng PengZheng commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

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, and JSON Patch support to the new jansson_ext library, along with the supporting infrastructure needed to make it production-ready.

New capabilities

  • JSON Schema validation (celix_jansson_schema.h): draft-07 keyword support, $ref resolution including remote references, recursion depth guard for circular references, abort-on-first-error mode, and a full instance-path reporting mechanism.
  • JSON Pointer (celix_jansson_pointer.h): parse/evaluate pointers with buffer-reuse and automatic cleanup support.
  • JSON Patch (celix_json_patch.h): apply/validate patch documents, with self-reference and null-value guards.
  • URI validation (celix_jansson_uri): uri format validation with array-index and malformed-pointer checks, IPv6 zone-id rejection, and automatic cleanup of URI resources.
  • String format checkers: email (Ragel-generated SMTP state machine, corrupted tables fixed), time, IPv4/IPv6 validation.
  • String hash maps: properties/dependencies handling refactored from hash tables to string hash maps for better memory management.

Robustness & hardening

  • Multiple hardening passes fixing unhandled allocation failures (OOM) throughout schema validation, JSON pointer operations, URI handling, and patch operations — with error-injection (EI) tests covering the OOM paths (stdio_ei vsnprintf support added).
  • Fixes for leaks (double-free, path string management) found during coverage analysis.

Tests & tooling

  • ~9,000 lines of new unit tests, including the upstream JSON-Schema-Test-Suite draft-07 corpus.
  • C++ compatibility for celix_util.h with unit tests for string buffer functions.
  • Conan test_package support for jansson_ext.
  • Coverage build fix: test execution enabled and lcov --ignore-errors flag removed.
  • rat-excludes.txt updated for the vendored JSON-Schema-Test-Suite corpus.

Files

127 files changed, ~27.4k insertions. The bulk is libs/jansson_ext/ (new library sources, headers, examples, and tests).


🤖 Generated with Claude Code

PengZheng and others added 30 commits August 4, 2026 16:44
…proving error handling for circular references
…istency, improve code coverage, and fix a leak.
… and malformed pointers, and update related tests for comprehensive coverage.
… 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>
PengZheng and others added 9 commits August 9, 2026 20:17
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-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.43%. Comparing base (d4b2ec3) to head (9e8f1c7).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #842      +/-   ##
==========================================
+ Coverage   91.62%   92.43%   +0.80%     
==========================================
  Files         235      246      +11     
  Lines       28787    31849    +3062     
==========================================
+ Hits        26377    29439    +3062     
  Misses       2410     2410              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PengZheng
PengZheng requested a review from pnoltes August 10, 2026 07:26
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.

2 participants