Skip to content

Commit fb694e1

Browse files
authored
Deref fix: Arrays and allOf (#7)
* Add support for arrays and innofensive console.log * Derefe allOf * 0.3.5
1 parent 0128b7e commit fb694e1

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

deno.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@deco/mcp",
3-
"version": "0.3.4",
3+
"version": "0.3.5",
44
"exports": "./mod.ts",
55
"tasks": {
66
"check": "deno fmt && deno lint && deno check mod.ts"

mcp/utils.ts

+40-9
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,50 @@ export function dereferenceSchema(
4444

4545
const result: JSONSchema7 = { ...schema };
4646

47-
// Handle allOf
48-
if (result.allOf) {
49-
result.allOf = result.allOf.map((subSchema: any) =>
47+
// Handle arrays with items
48+
if (result.type === "array" && result.items) {
49+
result.items = dereferenceSchema(
50+
result.items as JSONSchema7,
51+
definitions,
52+
visited,
53+
) as JSONSchema7;
54+
}
55+
56+
// Handle and merge allOf into the main schema
57+
if (result.allOf && Array.isArray(result.allOf) && result.allOf.length > 0) {
58+
// First dereference all schemas in allOf
59+
const dereferencedAllOf = result.allOf.map((subSchema: any) =>
5060
dereferenceSchema(
5161
subSchema as JSONSchema7,
5262
definitions,
5363
visited,
54-
)
55-
) as JSONSchema7[];
64+
) as JSONSchema7
65+
);
66+
67+
// Merge all properties from allOf schemas into the main schema
68+
for (const subSchema of dereferencedAllOf) {
69+
// Merge properties if they exist
70+
if (subSchema.properties) {
71+
result.properties = {
72+
...(result.properties || {}),
73+
...(subSchema.properties || {}),
74+
};
75+
}
76+
77+
// Merge required fields if they exist
78+
if (subSchema.required && Array.isArray(subSchema.required)) {
79+
result.required = [
80+
...(result.required || []),
81+
...subSchema.required,
82+
];
83+
}
84+
}
85+
86+
// Remove the allOf array since we've merged its contents
87+
delete result.allOf;
88+
} else if (result.allOf && !Array.isArray(result.allOf)) {
89+
// Handle case where allOf is not an array
90+
delete result.allOf;
5691
}
5792

5893
// Handle anyOf
@@ -102,10 +137,6 @@ export function dereferenceSchema(
102137
);
103138
}
104139

105-
if ("allOf" in result && !Array.isArray(result.allOf)) {
106-
delete result.allOf;
107-
}
108-
109140
return result;
110141
}
111142

0 commit comments

Comments
 (0)