@kokimoki/kit 1.6.1 → 1.6.3
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/dist/kokimoki-kit-plugin.js +24 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
@@ -143,7 +143,30 @@ function kokimokiKitPlugin(config) {
|
|
143
143
|
defaultProjectStylePath: config.defaultProjectStylePath,
|
144
144
|
}, null, 2));
|
145
145
|
// write schema
|
146
|
-
const jsonSchema = v4_1.z.toJSONSchema(config.schema
|
146
|
+
const jsonSchema = v4_1.z.toJSONSchema(config.schema, {
|
147
|
+
override(ctx) {
|
148
|
+
// check if schema is discriminated union
|
149
|
+
if (ctx.zodSchema._zod.def.type === "union" &&
|
150
|
+
"discriminator" in ctx.zodSchema._zod.def) {
|
151
|
+
const discriminator = ctx.zodSchema._zod.def
|
152
|
+
.discriminator;
|
153
|
+
ctx.jsonSchema.type = "object";
|
154
|
+
ctx.jsonSchema.discriminator = { propertyName: discriminator };
|
155
|
+
ctx.jsonSchema.required = [discriminator];
|
156
|
+
ctx.jsonSchema.oneOf = ctx.jsonSchema.anyOf.map((objectSchema) => ({
|
157
|
+
properties: objectSchema.properties,
|
158
|
+
additionalProperties: objectSchema.additionalProperties,
|
159
|
+
required: (objectSchema.required ?? []).filter((prop) => prop !== discriminator),
|
160
|
+
}));
|
161
|
+
delete ctx.jsonSchema.anyOf;
|
162
|
+
}
|
163
|
+
// Remove fields that have a default from the required list
|
164
|
+
if (ctx.jsonSchema.properties && ctx.jsonSchema.required) {
|
165
|
+
const properties = ctx.jsonSchema.properties;
|
166
|
+
ctx.jsonSchema.required = ctx.jsonSchema.required.filter((field) => !("default" in properties[field]));
|
167
|
+
}
|
168
|
+
},
|
169
|
+
});
|
147
170
|
await promises_1.default.writeFile(".kokimoki/schema.json", JSON.stringify(jsonSchema, null, 2));
|
148
171
|
// // write schema defaults as json
|
149
172
|
// await fs.writeFile(
|
package/dist/version.d.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export declare const KOKIMOKI_KIT_VERSION = "1.6.
|
1
|
+
export declare const KOKIMOKI_KIT_VERSION = "1.6.3";
|
package/dist/version.js
CHANGED