@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.
@@ -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";
1
+ export declare const KOKIMOKI_KIT_VERSION = "1.6.3";
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.3";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kokimoki/kit",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",