fix(gts-macros): add additionalProperties: false to derived schemas#63
fix(gts-macros): add additionalProperties: false to derived schemas#63Artifizer merged 5 commits intoGlobalTypeSystem:mainfrom
Conversation
Child/derived schemas generated by `gts_schema_with_refs_allof()` were missing `"additionalProperties": false` at the root level, while base GTS schemas always included it. This caused schema-vs-schema compatibility validation (OP#12) to reject all derived schemas with: "derived schema '...' loosens additionalProperties from false in base" The fix adds `"additionalProperties": false` to both child schema generation paths (generic and non-generic), ensuring derived schemas match the base schema constraint and pass Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 📝 WalkthroughWalkthroughBumped five workspace package versions to 0.8.1, updated gts-macros to emit "additionalProperties": false in two generated JSON Schema locations, incremented several package versions, and removed a test User schema file. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Signed-off-by: Artifizer <artifizer@gmail.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
gts-macros/src/lib.rs (1)
1225-1236:⚠️ Potential issue | 🟠 MajorRoot-level
additionalProperties: falsewithallOfmakes derived schemas unsatisfiable in draft-07.In draft-07,
additionalPropertiesonly considers properties defined in the same schema object, not those fromallOfsubschemas. Since the root level has nopropertiesdefined (only nested within the secondallOfsubschema),additionalProperties: falseforbids all properties, making these schemas reject valid instances.Remove
additionalProperties: falsefrom the root of both schemas, or upgrade to JSON Schema 2019-09+ and useunevaluatedProperties: falseinstead.🛠️ Suggested fix
serde_json::json!({ "$id": format!("gts://{}", schema_id), "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", - "additionalProperties": false, "allOf": [ { "$ref": format!("gts://{}", parent_schema_id) }, { "type": "object", "properties": nested_properties } ] })Also applies to: 1332-1342
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@gts-macros/src/lib.rs` around lines 1225 - 1236, The root-level "additionalProperties": false in the constructed JSON schema makes derived schemas unsatisfiable under draft-07 because properties live inside the second allOf subschema; update the schema construction in the block that builds the serde_json::json! (the object that includes "$id": format!("gts://{}", schema_id), "$schema", "type": "object", "additionalProperties": false, "allOf": [...]) by removing the root-level additionalProperties entry (or alternatively switch the "$schema" to a 2019-09+ draft and replace additionalProperties with "unevaluatedProperties": false), or move additionalProperties:false into the same subschema that defines "properties" (the second allOf element built from nested_properties) so that the restriction applies where properties are declared; apply the same change to the other occurrence noted (around the second range mentioned).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@gts-macros/src/lib.rs`:
- Around line 1225-1236: The root-level "additionalProperties": false in the
constructed JSON schema makes derived schemas unsatisfiable under draft-07
because properties live inside the second allOf subschema; update the schema
construction in the block that builds the serde_json::json! (the object that
includes "$id": format!("gts://{}", schema_id), "$schema", "type": "object",
"additionalProperties": false, "allOf": [...]) by removing the root-level
additionalProperties entry (or alternatively switch the "$schema" to a 2019-09+
draft and replace additionalProperties with "unevaluatedProperties": false), or
move additionalProperties:false into the same subschema that defines
"properties" (the second allOf element built from nested_properties) so that the
restriction applies where properties are declared; apply the same change to the
other occurrence noted (around the second range mentioned).
Signed-off-by: Artifizer <artifizer@gmail.com>
Signed-off-by: Artifizer <artifizer@gmail.com>
Summary by CodeRabbit
Chores
Refactor
Tests