@mastra/schema-compat 1.0.0-beta.3 → 1.0.0-beta.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/index.cjs +13 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/provider-compats/openai.d.ts.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @mastra/schema-compat
|
|
2
2
|
|
|
3
|
+
## 1.0.0-beta.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Fix OpenAI structured output compatibility for fields with `.default()` values ([#11434](https://github.com/mastra-ai/mastra/pull/11434))
|
|
8
|
+
|
|
9
|
+
When using Zod schemas with `.default()` fields (e.g., `z.number().default(1)`), OpenAI's structured output API was failing with errors like `Missing '<field>' in required`. This happened because `zod-to-json-schema` doesn't include fields with defaults in the `required` array, but OpenAI requires all properties to be required.
|
|
10
|
+
|
|
11
|
+
This fix converts `.default()` fields to `.nullable()` with a transform that returns the default value when `null` is received, ensuring compatibility with OpenAI's strict mode while preserving the original default value semantics.
|
|
12
|
+
|
|
3
13
|
## 1.0.0-beta.3
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/dist/index.cjs
CHANGED
|
@@ -4874,6 +4874,19 @@ var OpenAISchemaCompatLayer = class extends SchemaCompatLayer3 {
|
|
|
4874
4874
|
return processedInner.nullable();
|
|
4875
4875
|
}
|
|
4876
4876
|
return value;
|
|
4877
|
+
} else if (isDefault(zod.z)(value)) {
|
|
4878
|
+
const innerType = "_def" in value ? value._def.innerType : value._zod?.def?.innerType;
|
|
4879
|
+
const defaultValue = "_def" in value ? value._def.defaultValue : value._zod?.def?.defaultValue;
|
|
4880
|
+
if (innerType) {
|
|
4881
|
+
const processedInner = this.processZodType(innerType);
|
|
4882
|
+
return processedInner.nullable().transform((val) => {
|
|
4883
|
+
if (val === null) {
|
|
4884
|
+
return typeof defaultValue === "function" ? defaultValue() : defaultValue;
|
|
4885
|
+
}
|
|
4886
|
+
return val;
|
|
4887
|
+
});
|
|
4888
|
+
}
|
|
4889
|
+
return value;
|
|
4877
4890
|
} else if (isObj2(zod.z)(value)) {
|
|
4878
4891
|
return this.defaultZodObjectHandler(value);
|
|
4879
4892
|
} else if (isUnion2(zod.z)(value)) {
|