-
Notifications
You must be signed in to change notification settings - Fork 0
feat: defaultExpandDepth #335
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
WalkthroughAdded 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
Estimated code review effort🎯 2 (Simple) | ⏱️ ~7 minutes Poem
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 unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 spreadingundefined/nullwill throw. Also, nothing enforces@min 0or 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 breakagesThe 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
JSVOptionsis exported, adding a required field can be a compile-time breaking change for consumers who constructJSVOptionsobjects. 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
setOptionscoalescing 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.
📒 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: 0in the service defaults aligns with the docs. LGTM.Please confirm that components consuming this option correctly handle
Infinityand 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 changeNothing actionable in this hunk.
Summary by CodeRabbit