Skip to content

test(lotus_json): assert LotusJson<Option<T>> is nullable in schema#7347

Open
0xDevNinja wants to merge 1 commit into
ChainSafe:mainfrom
0xDevNinja:0xdevninja/issue-4331-optional-nullable-schema
Open

test(lotus_json): assert LotusJson<Option<T>> is nullable in schema#7347
0xDevNinja wants to merge 1 commit into
ChainSafe:mainfrom
0xDevNinja:0xdevninja/issue-4331-optional-nullable-schema

Conversation

@0xDevNinja

@0xDevNinja 0xDevNinja commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Closes #4331.

LotusJson<Option<T>> delegates its schema to Option<T::LotusJson>, which schemars already renders as nullable ("type": [..., "null"] / a null branch in anyOf). This adds a small regression test locking that behaviour in, as suggested in the issue — verifying that:

  • LotusJson<Option<T>> produces a schema that permits null (i.e. is optional in the OpenRPC spec), and
  • the non-optional LotusJson<T> counterpart does not permit null.

The helper schema_allows_null accepts both the "type" union form (used for primitives/arrays) and the anyOf/oneOf form (used for $ref object types), so the test stays robust across inner types.

No production code changes — test only.

Reference tests

cargo test -p forest-filecoin --lib lotus_json::opt:: — 3 passed (existing snapshot + quickcheck, plus the new optional_is_nullable_in_schema).

Other information and links

Issue originally raised by @ruseinov in #4330 (comment).

Summary by CodeRabbit

  • Tests
    • Added regression coverage confirming optional Lotus JSON values accept null.
    • Confirmed non-optional Lotus JSON values continue to reject null.

Add a regression test verifying that the JSON/OpenRPC schema generated
for LotusJson<Option<T>> permits null (is optional), while the
non-optional LotusJson<T> counterpart does not.

Closes ChainSafe#4331
@0xDevNinja 0xDevNinja requested a review from a team as a code owner July 13, 2026 10:07
@0xDevNinja 0xDevNinja requested review from hanabi1224 and sudo-shashank and removed request for a team July 13, 2026 10:07
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 8482053a-d875-4765-b7dc-d27736e9d53b

📥 Commits

Reviewing files that changed from the base of the PR and between 17c49db and de41e74.

📒 Files selected for processing (1)
  • src/lotus_json/opt.rs
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • filecoin-project/lotus (manual)

Walkthrough

Changes

LotusJson schema nullability

Layer / File(s) Summary
Schema nullability regression coverage
src/lotus_json/opt.rs
Adds schema_allows_null and verifies that LotusJson<Option<Cid>> accepts null, while LotusJson<Cid> does not.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: hanabi1224, sudo-shashank

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: a regression test for nullable schema handling in LotusJson<Option>.
Linked Issues check ✅ Passed The added test verifies that LotusJson<Option> is represented as nullable/optional in the schema, matching issue #4331.
Out of Scope Changes check ✅ Passed The PR only adds a focused regression test and helper logic in the test file, with no unrelated feature or production changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

Ensure LotusJson<Option<T>> is marked as optional in the OpenRPC spec

1 participant