Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 21, 14:45 UTC
fix(json-schema): accept document-root references in strict mode
jkomyno committed
Aug 27, 2026 at 15:39 UTC
9feca8f95d892406d8cfc416119448dc2bb25190
5 files changed
+100
-4
python/composio/utils/strict_schema.py
+3
-1
@@ -292,7 +292,9 @@ class _Walker:
292
293
ref = node.get("$ref")
294
if isinstance(ref, str):
295
- resolved = ref.startswith("#/") and _try_resolve_pointer(self.root, ref).ok
295
+ resolved = (ref == "#" or ref.startswith("#/")) and _try_resolve_pointer(
296
+ self.root, ref
297
+ ).ok
298
if not resolved:
299
self.reject(path, "$ref", f'unresolved $ref "{ref}"')
300
# The referenced definition is normalized where it is declared.
python/tests/fixtures/json-schema-conversion/strict-cases.json
+44
@@ -1539,6 +1539,50 @@
1539
}
1540
}
1541
},
1542
+ {
1543
+ "id": "root-ref-kept",
1544
+ "description": "A local $ref to the document root resolves and is kept.",
1545
+ "schema": {
1546
+ "type": "object",
1547
+ "properties": {
1548
+ "child": {
1549
+ "$ref": "#"
1550
+ },
1551
+ "label": {
1552
+ "type": "string"
1553
+ }
1554
+ },
1555
+ "required": ["label"]
1556
+ },
1557
+ "strict": {
1558
+ "schema": {
1559
+ "type": "object",
1560
+ "properties": {
1561
+ "child": {
1562
+ "anyOf": [
1563
+ {
1564
+ "$ref": "#"
1565
+ },
1566
+ {
1567
+ "type": "null"
1568
+ }
1569
+ ]
1570
+ },
1571
+ "label": {
1572
+ "type": "string"
1573
+ }
1574
+ },
1575
+ "required": ["child", "label"],
1576
+ "additionalProperties": false
1577
+ }
1578
+ },
1579
+ "changes": [
1580
+ {
1581
+ "path": "properties.child",
1582
+ "reason": "optional-property-nullable"
1583
+ }
1584
+ ]
1585
+ },
1586
{
1587
"id": "dangling-ref-unsupported",
1588
"description": "A $ref without a target is reported at its own path.",
ts/packages/core/src/utils/jsonSchema.ts
+4
-3
@@ -792,9 +792,10 @@ export function toStrictJsonSchema(schema: unknown): StrictJsonSchemaResult {
792
const out = walkChildren(node, mode, depth, path);
793
794
if (typeof node.$ref === 'string') {
795
- const resolution = node.$ref.startsWith('#/')
796
- ? tryResolvePointer(root, node.$ref)
797
- : ({ kind: 'unresolved', reason: 'malformed-pointer' } as const);
795
+ const resolution =
796
+ node.$ref === '#' || node.$ref.startsWith('#/')
797
+ ? tryResolvePointer(root, node.$ref)
798
+ : ({ kind: 'unresolved', reason: 'malformed-pointer' } as const);
799
if (resolution.kind === 'unresolved') {
800
unsupported.push({
801
path,
ts/packages/core/test/fixtures/json-schema-conversion/generate-strict-cases.mjs
+5
@@ -231,6 +231,11 @@ const cases = [
231
'A local $ref outside $defs resolves and is kept.',
232
obj({ a: obj({ x: { type: 'string' } }, ['x']), b: { $ref: '#/properties/a' } }, ['a', 'b']),
233
],
234
+ [
235
+ 'root-ref-kept',
236
+ 'A local $ref to the document root resolves and is kept.',
237
+ obj({ child: { $ref: '#' }, label: { type: 'string' } }, ['label']),
238
+ ],
239
[
240
'dangling-ref-unsupported',
241
'A $ref without a target is reported at its own path.',
ts/packages/core/test/fixtures/json-schema-conversion/strict-cases.json
+44
@@ -1539,6 +1539,50 @@
1539
}
1540
}
1541
},
1542
+ {
1543
+ "id": "root-ref-kept",
1544
+ "description": "A local $ref to the document root resolves and is kept.",
1545
+ "schema": {
1546
+ "type": "object",
1547
+ "properties": {
1548
+ "child": {
1549
+ "$ref": "#"
1550
+ },
1551
+ "label": {
1552
+ "type": "string"
1553
+ }
1554
+ },
1555
+ "required": ["label"]
1556
+ },
1557
+ "strict": {
1558
+ "schema": {
1559
+ "type": "object",
1560
+ "properties": {
1561
+ "child": {
1562
+ "anyOf": [
1563
+ {
1564
+ "$ref": "#"
1565
+ },
1566
+ {
1567
+ "type": "null"
1568
+ }
1569
+ ]
1570
+ },
1571
+ "label": {
1572
+ "type": "string"
1573
+ }
1574
+ },
1575
+ "required": ["child", "label"],
1576
+ "additionalProperties": false
1577
+ }
1578
+ },
1579
+ "changes": [
1580
+ {
1581
+ "path": "properties.child",
1582
+ "reason": "optional-property-nullable"
1583
+ }
1584
+ ]
1585
+ },
1586
{
1587
"id": "dangling-ref-unsupported",
1588
"description": "A $ref without a target is reported at its own path.",