@kokimoki/kit 1.6.1 → 1.6.2

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.
@@ -143,7 +143,25 @@ 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
+ },
164
+ });
147
165
  await promises_1.default.writeFile(".kokimoki/schema.json", JSON.stringify(jsonSchema, null, 2));
148
166
  // // write schema defaults as json
149
167
  // await fs.writeFile(
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const KOKIMOKI_KIT_VERSION = "1.6.1";
1
+ export declare const KOKIMOKI_KIT_VERSION = "1.6.2";
package/dist/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.KOKIMOKI_KIT_VERSION = void 0;
4
- exports.KOKIMOKI_KIT_VERSION = "1.6.1";
4
+ exports.KOKIMOKI_KIT_VERSION = "1.6.2";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokimoki/kit",
3
- "version": "1.6.1",
3
+ "version": "1.6.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",