Skip to content

Conversation

@jy95
Copy link
Owner

@jy95 jy95 commented Aug 23, 2025

Summary by CodeRabbit

  • New Features
    • Added a configurable option to control the default expansion depth of JSON Schemas. Set how many levels expand on load (0 = root only, 1 = root + direct children, Infinity = all levels). Defaults to root only; behavior remains unchanged unless configured.

@coderabbitai
Copy link

coderabbitai bot commented Aug 23, 2025

Walkthrough

Added a new public option defaultExpandDepth: number to JSVOptions with documented semantics (0 root only, 1 includes direct children, Infinity all levels). Updated JSVOptionsService to initialize defaultExpandDepth to 0 in its default options. No other changes shown.

Changes

Cohort / File(s) Summary
Options interface and service defaults
projects/ngx-json-schema-viewer/src/lib/services/jsv-options.ts
Added defaultExpandDepth: number to JSVOptions with docblock (0 min, default 0, Infinity allowed). Updated JSVOptionsService default options to include defaultExpandDepth: 0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Poem

A nibble of depth in the schema tree,
Hop-hop I set how far to see.
0 I peek, 1 I pry,
Infinity? I skyward fly!
With whiskers twitching, defaults set—
A tidy burrow, no regrets. 🐇✨

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch jy95-patch-1

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

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

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
projects/ngx-json-schema-viewer/src/lib/services/jsv-options.ts (1)

92-97: Prevent runtime errors and enforce the documented range when merging options

setOptions(userOptions?: Partial<JSVOptions>) marks the parameter optional, but spreading undefined/null will throw. Also, nothing enforces @min 0 or integer semantics. Sanitize here so every caller benefits.

-    setOptions(userOptions?: Partial<JSVOptions>) {
-        this.options = {
-            ...this.options,
-            ...userOptions
-        }
-    }
+    setOptions(userOptions?: Partial<JSVOptions>) {
+        // Coalesce and sanitize before merging
+        const sanitized: Partial<JSVOptions> = { ...(userOptions ?? {}) };
+
+        if (sanitized.defaultExpandDepth !== undefined) {
+            const val = sanitized.defaultExpandDepth as number;
+            if (val === Infinity) {
+                sanitized.defaultExpandDepth = Infinity;
+            } else if (Number.isFinite(val)) {
+                sanitized.defaultExpandDepth = Math.max(0, Math.floor(val));
+            } else {
+                // NaN, -Infinity, non-number → fallback to default
+                sanitized.defaultExpandDepth = 0;
+            }
+        }
+
+        this.options = {
+            ...this.options,
+            ...sanitized
+        };
+    }
🧹 Nitpick comments (2)
projects/ngx-json-schema-viewer/src/lib/services/jsv-options.ts (2)

37-46: Add is good; tighten docs and consider optionality to avoid consumer breakages

The option is a nice addition. Two small tweaks:

  • Clarify that values should be non-negative integers or Infinity; decimals are floored, negatives clamped to 0 (matches suggested sanitization below).
  • Since JSVOptions is exported, adding a required field can be a compile-time breaking change for consumers who construct JSVOptions objects. Consider making it optional on the public type while keeping your internal default at 0.

Apply this doc/type diff:

     /**
      * Defines how deep the schema should be expanded by default
      * Examples:
       *  - 0: only the root level is expanded
       *  - 1: root level and its direct children are expanded
       *  - Infinity: expand all levels
-     * @default 0
-     * @min 0
+     * Accepts a non-negative integer (0+) or Infinity.
+     * Decimals are floored; negatives are clamped to 0.
+     * @default 0
+     * @min 0
      */
-    defaultExpandDepth: number
+    defaultExpandDepth?: number

1-1: Make the options token optional to improve DX (no provider required)

If consumers forget to provide JSV_OPTIONS, DI will currently error. Since you already seed sensible defaults, making the token optional reduces friction without behavior changes.

-import { Inject, Injectable, InjectionToken } from '@angular/core';
+import { Inject, Injectable, InjectionToken, Optional } from '@angular/core';
@@
-    constructor(@Inject(JSV_OPTIONS) userOptions: Partial<JSVOptions>) {
+    constructor(@Optional() @Inject(JSV_OPTIONS) userOptions?: Partial<JSVOptions>) {

No other changes are required if you adopt the setOptions coalescing in the previous comment.

Also applies to: 59-61

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between e7a1309 and edaef81.

📒 Files selected for processing (1)
  • projects/ngx-json-schema-viewer/src/lib/services/jsv-options.ts (3 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: test
🔇 Additional comments (2)
projects/ngx-json-schema-viewer/src/lib/services/jsv-options.ts (2)

85-86: Default value wired correctly

defaultExpandDepth: 0 in the service defaults aligns with the docs. LGTM.

Please confirm that components consuming this option correctly handle Infinity and non-integer inputs (post-sanitization), and consider adding a README snippet demonstrating usage:

  • Root only (0)
  • One level (1)
  • Fully expanded (Infinity)

103-103: No-op change

Nothing actionable in this hunk.

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.

1 participant