Improve JsonSchema for autocompletion#2474
Conversation
|
/ok-to-test |
WalkthroughAdds schema title support, min/max property constraints, and componentRef entries; updates JsonSchemaGenerator to set titles, enforce single top-level property when present, adjust component variant naming, and tighten imports and conditionals. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
|
This pull request needs "/ok-to-test" from an authorized committer. |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
annot/src/main/java/com/predic8/membrane/annot/generator/kubernetes/model/SchemaObject.java (1)
177-179: Consider adding validation for non-negative values.Per JSON Schema specification,
minPropertiesandmaxPropertiesmust be non-negative integers. Currently, callers could pass negative values. This is a minor concern since the callers are internal generator code, but a defensive check could prevent subtle bugs.🔎 Proposed defensive validation
- public SchemaObject minProperties(int n) { this.minProperties = n; return this; } - public SchemaObject maxProperties(int n) { this.maxProperties = n; return this; } + public SchemaObject minProperties(int n) { + if (n < 0) throw new IllegalArgumentException("minProperties must be non-negative"); + this.minProperties = n; + return this; + } + + public SchemaObject maxProperties(int n) { + if (n < 0) throw new IllegalArgumentException("maxProperties must be non-negative"); + this.maxProperties = n; + return this; + }
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java(5 hunks)annot/src/main/java/com/predic8/membrane/annot/generator/kubernetes/model/SchemaObject.java(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-23T13:04:11.388Z
Learnt from: predic8
Repo: membrane/api-gateway PR: 2240
File: annot/src/main/java/com/predic8/membrane/annot/generator/JsonSchemaGenerator.java:210-215
Timestamp: 2025-10-23T13:04:11.388Z
Learning: In JsonSchemaGenerator.java, when allowForeign is true for non-list child elements, use a property named "ref" (not "$ref") with type "string" to provide IDE completion hints for Spring bean references while avoiding JSON Schema keyword collision.
Applied to files:
annot/src/main/java/com/predic8/membrane/annot/generator/kubernetes/model/SchemaObject.java
⏰ 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). (2)
- GitHub Check: Automated tests
- GitHub Check: Analyze (java)
🔇 Additional comments (2)
annot/src/main/java/com/predic8/membrane/annot/generator/kubernetes/model/SchemaObject.java (2)
34-36: LGTM!Using
Integer(boxed type) is the right choice here since it allows null-checking to conditionally omit these properties from the generated JSON when not set.
53-55: LGTM!The null-guarded serialization correctly emits
minPropertiesandmaxPropertiesonly when explicitly set, following the existing patterns in this class.
title in JSON schema generation
Summary by CodeRabbit
New Features
Refactor
Tests
✏️ Tip: You can customize this high-level summary in your review settings.