@kaito-http/core 4.0.0-beta.15 → 4.0.0-beta.16

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.
@@ -64,6 +64,16 @@ var BaseSchema = class {
64
64
  /** @internal */
65
65
  _output;
66
66
  def;
67
+ getSchemaObject() {
68
+ const schema = {};
69
+ if (this.def.description !== void 0) {
70
+ schema.description = this.def.description;
71
+ }
72
+ if (this.def.example !== void 0) {
73
+ schema.example = this.def.example;
74
+ }
75
+ return schema;
76
+ }
67
77
  clone(def) {
68
78
  return new this.constructor({
69
79
  ...this.def,
@@ -107,7 +117,9 @@ var KString = class _KString extends BaseSchema {
107
117
  return this.clone({ [check.type]: check });
108
118
  }
109
119
  toOpenAPI() {
120
+ const baseSchema = this.getSchemaObject();
110
121
  const schema = {
122
+ ...baseSchema,
111
123
  type: "string"
112
124
  };
113
125
  if (this.def.regex) {
@@ -122,9 +134,6 @@ var KString = class _KString extends BaseSchema {
122
134
  if (this.def.max !== void 0) {
123
135
  schema.maxLength = this.def.max.val;
124
136
  }
125
- if (this.def.description) {
126
- schema.description = this.def.description;
127
- }
128
137
  return schema;
129
138
  }
130
139
  /**
@@ -296,7 +305,11 @@ var KNumber = class _KNumber extends BaseSchema {
296
305
  return this.clone({ [check.type]: check });
297
306
  }
298
307
  toOpenAPI() {
299
- const schema = { type: "number" };
308
+ const baseSchema = this.getSchemaObject();
309
+ const schema = {
310
+ ...baseSchema,
311
+ type: "number"
312
+ };
300
313
  if (this.def.min !== void 0) {
301
314
  schema.minimum = this.def.min.val;
302
315
  }
@@ -332,9 +345,6 @@ var KNumber = class _KNumber extends BaseSchema {
332
345
  if (this.def.format) {
333
346
  schema.format = this.def.format.format;
334
347
  }
335
- if (this.def.description) {
336
- schema.description = this.def.description;
337
- }
338
348
  return schema;
339
349
  }
340
350
  min(min) {
@@ -398,9 +408,10 @@ var KBoolean = class _KBoolean extends BaseSchema {
398
408
  return value;
399
409
  }
400
410
  toOpenAPI() {
411
+ const baseSchema = this.getSchemaObject();
401
412
  return {
402
- type: "boolean",
403
- ...this.def.description ? { description: this.def.description } : {}
413
+ ...baseSchema,
414
+ type: "boolean"
404
415
  };
405
416
  }
406
417
  parseSafe(json) {
@@ -428,10 +439,11 @@ var KArray = class _KArray extends BaseSchema {
428
439
  return this.clone({ [check.type]: check });
429
440
  }
430
441
  toOpenAPI() {
442
+ const baseSchema = this.getSchemaObject();
431
443
  return {
444
+ ...baseSchema,
432
445
  type: "array",
433
446
  items: this.def.items.toOpenAPI(),
434
- ...this.def.description ? { description: this.def.description } : {},
435
447
  ...this.def.minItems !== void 0 ? { minItems: this.def.minItems.val } : {},
436
448
  ...this.def.maxItems !== void 0 ? { maxItems: this.def.maxItems.val } : {},
437
449
  ...this.def.uniqueItems !== void 0 ? { uniqueItems: this.def.uniqueItems.val } : {}
@@ -490,9 +502,10 @@ var KNull = class _KNull extends BaseSchema {
490
502
  return value;
491
503
  }
492
504
  toOpenAPI() {
505
+ const baseSchema = this.getSchemaObject();
493
506
  return {
494
- type: "null",
495
- ...this.def.description ? { description: this.def.description } : {}
507
+ ...baseSchema,
508
+ type: "null"
496
509
  };
497
510
  }
498
511
  parseSafe(json) {
@@ -527,7 +540,9 @@ var KObject = class _KObject extends BaseSchema {
527
540
  return result;
528
541
  }
529
542
  toOpenAPI() {
543
+ const baseSchema = this.getSchemaObject();
530
544
  return {
545
+ ...baseSchema,
531
546
  type: "object",
532
547
  properties: Object.fromEntries(
533
548
  Object.entries(this.def.shape).map((entry) => {
@@ -535,8 +550,7 @@ var KObject = class _KObject extends BaseSchema {
535
550
  return [key, value.toOpenAPI()];
536
551
  })
537
552
  ),
538
- required: Object.keys(this.def.shape),
539
- ...this.def.description ? { description: this.def.description } : {}
553
+ required: Object.keys(this.def.shape)
540
554
  };
541
555
  }
542
556
  parseSafe(json) {
@@ -618,6 +632,9 @@ var KRef = class _KRef extends BaseSchema {
618
632
  }
619
633
  return result;
620
634
  }
635
+ example() {
636
+ throw new Error("Cannot set an example on a KRef");
637
+ }
621
638
  toOpenAPI() {
622
639
  return {
623
640
  $ref: `#/components/schemas/${this.def.name}`,
@@ -711,9 +728,10 @@ var KUnion = class _KUnion extends BaseSchema {
711
728
  throw new Error("Value does not match any union option for serialization");
712
729
  }
713
730
  toOpenAPI() {
731
+ const baseSchema = this.getSchemaObject();
714
732
  return {
715
- oneOf: this.def.items.map((option) => option.toOpenAPI()),
716
- ...this.def.description ? { description: this.def.description } : {}
733
+ ...baseSchema,
734
+ oneOf: this.def.items.map((option) => option.toOpenAPI())
717
735
  };
718
736
  }
719
737
  parseSafe(json) {
@@ -749,8 +767,13 @@ var KLiteral = class _KLiteral extends BaseSchema {
749
767
  return value;
750
768
  }
751
769
  toOpenAPI() {
770
+ const baseSchema = this.getSchemaObject();
752
771
  const type = typeof this.def.value;
753
- return { type, enum: [this.def.value] };
772
+ return {
773
+ ...baseSchema,
774
+ type,
775
+ enum: [this.def.value]
776
+ };
754
777
  }
755
778
  parseSafe(json) {
756
779
  return ParseContext.result((ctx) => {
package/dist/index.cjs CHANGED
@@ -222,6 +222,16 @@ var BaseSchema = class {
222
222
  /** @internal */
223
223
  _output;
224
224
  def;
225
+ getSchemaObject() {
226
+ const schema = {};
227
+ if (this.def.description !== void 0) {
228
+ schema.description = this.def.description;
229
+ }
230
+ if (this.def.example !== void 0) {
231
+ schema.example = this.def.example;
232
+ }
233
+ return schema;
234
+ }
225
235
  clone(def) {
226
236
  return new this.constructor({
227
237
  ...this.def,
@@ -265,7 +275,9 @@ var KString = class _KString extends BaseSchema {
265
275
  return this.clone({ [check.type]: check });
266
276
  }
267
277
  toOpenAPI() {
278
+ const baseSchema = this.getSchemaObject();
268
279
  const schema = {
280
+ ...baseSchema,
269
281
  type: "string"
270
282
  };
271
283
  if (this.def.regex) {
@@ -280,9 +292,6 @@ var KString = class _KString extends BaseSchema {
280
292
  if (this.def.max !== void 0) {
281
293
  schema.maxLength = this.def.max.val;
282
294
  }
283
- if (this.def.description) {
284
- schema.description = this.def.description;
285
- }
286
295
  return schema;
287
296
  }
288
297
  /**
@@ -454,7 +463,11 @@ var KNumber = class _KNumber extends BaseSchema {
454
463
  return this.clone({ [check.type]: check });
455
464
  }
456
465
  toOpenAPI() {
457
- const schema = { type: "number" };
466
+ const baseSchema = this.getSchemaObject();
467
+ const schema = {
468
+ ...baseSchema,
469
+ type: "number"
470
+ };
458
471
  if (this.def.min !== void 0) {
459
472
  schema.minimum = this.def.min.val;
460
473
  }
@@ -490,9 +503,6 @@ var KNumber = class _KNumber extends BaseSchema {
490
503
  if (this.def.format) {
491
504
  schema.format = this.def.format.format;
492
505
  }
493
- if (this.def.description) {
494
- schema.description = this.def.description;
495
- }
496
506
  return schema;
497
507
  }
498
508
  min(min) {
@@ -556,9 +566,10 @@ var KBoolean = class _KBoolean extends BaseSchema {
556
566
  return value;
557
567
  }
558
568
  toOpenAPI() {
569
+ const baseSchema = this.getSchemaObject();
559
570
  return {
560
- type: "boolean",
561
- ...this.def.description ? { description: this.def.description } : {}
571
+ ...baseSchema,
572
+ type: "boolean"
562
573
  };
563
574
  }
564
575
  parseSafe(json) {
@@ -586,10 +597,11 @@ var KArray = class _KArray extends BaseSchema {
586
597
  return this.clone({ [check.type]: check });
587
598
  }
588
599
  toOpenAPI() {
600
+ const baseSchema = this.getSchemaObject();
589
601
  return {
602
+ ...baseSchema,
590
603
  type: "array",
591
604
  items: this.def.items.toOpenAPI(),
592
- ...this.def.description ? { description: this.def.description } : {},
593
605
  ...this.def.minItems !== void 0 ? { minItems: this.def.minItems.val } : {},
594
606
  ...this.def.maxItems !== void 0 ? { maxItems: this.def.maxItems.val } : {},
595
607
  ...this.def.uniqueItems !== void 0 ? { uniqueItems: this.def.uniqueItems.val } : {}
@@ -648,9 +660,10 @@ var KNull = class _KNull extends BaseSchema {
648
660
  return value;
649
661
  }
650
662
  toOpenAPI() {
663
+ const baseSchema = this.getSchemaObject();
651
664
  return {
652
- type: "null",
653
- ...this.def.description ? { description: this.def.description } : {}
665
+ ...baseSchema,
666
+ type: "null"
654
667
  };
655
668
  }
656
669
  parseSafe(json) {
@@ -685,7 +698,9 @@ var KObject = class _KObject extends BaseSchema {
685
698
  return result;
686
699
  }
687
700
  toOpenAPI() {
701
+ const baseSchema = this.getSchemaObject();
688
702
  return {
703
+ ...baseSchema,
689
704
  type: "object",
690
705
  properties: Object.fromEntries(
691
706
  Object.entries(this.def.shape).map((entry) => {
@@ -693,8 +708,7 @@ var KObject = class _KObject extends BaseSchema {
693
708
  return [key, value.toOpenAPI()];
694
709
  })
695
710
  ),
696
- required: Object.keys(this.def.shape),
697
- ...this.def.description ? { description: this.def.description } : {}
711
+ required: Object.keys(this.def.shape)
698
712
  };
699
713
  }
700
714
  parseSafe(json) {
@@ -776,6 +790,9 @@ var KRef = class _KRef extends BaseSchema {
776
790
  }
777
791
  return result;
778
792
  }
793
+ example() {
794
+ throw new Error("Cannot set an example on a KRef");
795
+ }
779
796
  toOpenAPI() {
780
797
  return {
781
798
  $ref: `#/components/schemas/${this.def.name}`,
@@ -869,9 +886,10 @@ var KUnion = class _KUnion extends BaseSchema {
869
886
  throw new Error("Value does not match any union option for serialization");
870
887
  }
871
888
  toOpenAPI() {
889
+ const baseSchema = this.getSchemaObject();
872
890
  return {
873
- oneOf: this.def.items.map((option) => option.toOpenAPI()),
874
- ...this.def.description ? { description: this.def.description } : {}
891
+ ...baseSchema,
892
+ oneOf: this.def.items.map((option) => option.toOpenAPI())
875
893
  };
876
894
  }
877
895
  parseSafe(json) {
@@ -907,8 +925,13 @@ var KLiteral = class _KLiteral extends BaseSchema {
907
925
  return value;
908
926
  }
909
927
  toOpenAPI() {
928
+ const baseSchema = this.getSchemaObject();
910
929
  const type = typeof this.def.value;
911
- return { type, enum: [this.def.value] };
930
+ return {
931
+ ...baseSchema,
932
+ type,
933
+ enum: [this.def.value]
934
+ };
912
935
  }
913
936
  parseSafe(json) {
914
937
  return ParseContext.result((ctx) => {
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  SchemaError,
17
17
  isPrimitiveJSONValue,
18
18
  k
19
- } from "./chunk-EPB3QL2T.js";
19
+ } from "./chunk-ISGKY24N.js";
20
20
 
21
21
  // src/router/router.ts
22
22
  import "openapi3-ts/oas31";
@@ -104,6 +104,16 @@ var BaseSchema = class {
104
104
  /** @internal */
105
105
  _output;
106
106
  def;
107
+ getSchemaObject() {
108
+ const schema = {};
109
+ if (this.def.description !== void 0) {
110
+ schema.description = this.def.description;
111
+ }
112
+ if (this.def.example !== void 0) {
113
+ schema.example = this.def.example;
114
+ }
115
+ return schema;
116
+ }
107
117
  clone(def) {
108
118
  return new this.constructor({
109
119
  ...this.def,
@@ -147,7 +157,9 @@ var KString = class _KString extends BaseSchema {
147
157
  return this.clone({ [check.type]: check });
148
158
  }
149
159
  toOpenAPI() {
160
+ const baseSchema = this.getSchemaObject();
150
161
  const schema = {
162
+ ...baseSchema,
151
163
  type: "string"
152
164
  };
153
165
  if (this.def.regex) {
@@ -162,9 +174,6 @@ var KString = class _KString extends BaseSchema {
162
174
  if (this.def.max !== void 0) {
163
175
  schema.maxLength = this.def.max.val;
164
176
  }
165
- if (this.def.description) {
166
- schema.description = this.def.description;
167
- }
168
177
  return schema;
169
178
  }
170
179
  /**
@@ -336,7 +345,11 @@ var KNumber = class _KNumber extends BaseSchema {
336
345
  return this.clone({ [check.type]: check });
337
346
  }
338
347
  toOpenAPI() {
339
- const schema = { type: "number" };
348
+ const baseSchema = this.getSchemaObject();
349
+ const schema = {
350
+ ...baseSchema,
351
+ type: "number"
352
+ };
340
353
  if (this.def.min !== void 0) {
341
354
  schema.minimum = this.def.min.val;
342
355
  }
@@ -372,9 +385,6 @@ var KNumber = class _KNumber extends BaseSchema {
372
385
  if (this.def.format) {
373
386
  schema.format = this.def.format.format;
374
387
  }
375
- if (this.def.description) {
376
- schema.description = this.def.description;
377
- }
378
388
  return schema;
379
389
  }
380
390
  min(min) {
@@ -438,9 +448,10 @@ var KBoolean = class _KBoolean extends BaseSchema {
438
448
  return value;
439
449
  }
440
450
  toOpenAPI() {
451
+ const baseSchema = this.getSchemaObject();
441
452
  return {
442
- type: "boolean",
443
- ...this.def.description ? { description: this.def.description } : {}
453
+ ...baseSchema,
454
+ type: "boolean"
444
455
  };
445
456
  }
446
457
  parseSafe(json) {
@@ -468,10 +479,11 @@ var KArray = class _KArray extends BaseSchema {
468
479
  return this.clone({ [check.type]: check });
469
480
  }
470
481
  toOpenAPI() {
482
+ const baseSchema = this.getSchemaObject();
471
483
  return {
484
+ ...baseSchema,
472
485
  type: "array",
473
486
  items: this.def.items.toOpenAPI(),
474
- ...this.def.description ? { description: this.def.description } : {},
475
487
  ...this.def.minItems !== void 0 ? { minItems: this.def.minItems.val } : {},
476
488
  ...this.def.maxItems !== void 0 ? { maxItems: this.def.maxItems.val } : {},
477
489
  ...this.def.uniqueItems !== void 0 ? { uniqueItems: this.def.uniqueItems.val } : {}
@@ -530,9 +542,10 @@ var KNull = class _KNull extends BaseSchema {
530
542
  return value;
531
543
  }
532
544
  toOpenAPI() {
545
+ const baseSchema = this.getSchemaObject();
533
546
  return {
534
- type: "null",
535
- ...this.def.description ? { description: this.def.description } : {}
547
+ ...baseSchema,
548
+ type: "null"
536
549
  };
537
550
  }
538
551
  parseSafe(json) {
@@ -567,7 +580,9 @@ var KObject = class _KObject extends BaseSchema {
567
580
  return result;
568
581
  }
569
582
  toOpenAPI() {
583
+ const baseSchema = this.getSchemaObject();
570
584
  return {
585
+ ...baseSchema,
571
586
  type: "object",
572
587
  properties: Object.fromEntries(
573
588
  Object.entries(this.def.shape).map((entry) => {
@@ -575,8 +590,7 @@ var KObject = class _KObject extends BaseSchema {
575
590
  return [key, value.toOpenAPI()];
576
591
  })
577
592
  ),
578
- required: Object.keys(this.def.shape),
579
- ...this.def.description ? { description: this.def.description } : {}
593
+ required: Object.keys(this.def.shape)
580
594
  };
581
595
  }
582
596
  parseSafe(json) {
@@ -658,6 +672,9 @@ var KRef = class _KRef extends BaseSchema {
658
672
  }
659
673
  return result;
660
674
  }
675
+ example() {
676
+ throw new Error("Cannot set an example on a KRef");
677
+ }
661
678
  toOpenAPI() {
662
679
  return {
663
680
  $ref: `#/components/schemas/${this.def.name}`,
@@ -751,9 +768,10 @@ var KUnion = class _KUnion extends BaseSchema {
751
768
  throw new Error("Value does not match any union option for serialization");
752
769
  }
753
770
  toOpenAPI() {
771
+ const baseSchema = this.getSchemaObject();
754
772
  return {
755
- oneOf: this.def.items.map((option) => option.toOpenAPI()),
756
- ...this.def.description ? { description: this.def.description } : {}
773
+ ...baseSchema,
774
+ oneOf: this.def.items.map((option) => option.toOpenAPI())
757
775
  };
758
776
  }
759
777
  parseSafe(json) {
@@ -789,8 +807,13 @@ var KLiteral = class _KLiteral extends BaseSchema {
789
807
  return value;
790
808
  }
791
809
  toOpenAPI() {
810
+ const baseSchema = this.getSchemaObject();
792
811
  const type = typeof this.def.value;
793
- return { type, enum: [this.def.value] };
812
+ return {
813
+ ...baseSchema,
814
+ type,
815
+ enum: [this.def.value]
816
+ };
794
817
  }
795
818
  parseSafe(json) {
796
819
  return ParseContext.result((ctx) => {
@@ -51,8 +51,9 @@ declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends B
51
51
  abstract parse(json: unknown): Output;
52
52
  abstract parseSafe(json: unknown): ParseResult<Output>;
53
53
  abstract serialize(value: Output): Input;
54
- abstract toOpenAPI(): SchemaObject | ReferenceObject;
55
54
  protected readonly def: Def;
55
+ abstract toOpenAPI(): SchemaObject | ReferenceObject;
56
+ protected getSchemaObject(): SchemaObject;
56
57
  protected clone(def: Partial<Def>): this;
57
58
  protected constructor(def: Def);
58
59
  or<OtherInput extends JSONValue, OtherOutput, Def extends BaseSchemaDef<OtherInput>>(other: BaseSchema<OtherInput, OtherOutput, Def>): KUnion<(this | BaseSchema<OtherInput, OtherOutput, Def>)["_input"], (this | BaseSchema<OtherInput, OtherOutput, Def>)["_output"]>;
@@ -246,6 +247,7 @@ interface RefDef<Input extends Record<keyof Output, JSONValue>, Output extends R
246
247
  declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
247
248
  static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
248
249
  serialize(value: Output): Input;
250
+ example(): never;
249
251
  toOpenAPI(): ReferenceObject;
250
252
  parseSafe(json: unknown): ParseResult<Output>;
251
253
  parse(json: unknown): Output;
@@ -51,8 +51,9 @@ declare abstract class BaseSchema<Input extends JSONValue, Output, Def extends B
51
51
  abstract parse(json: unknown): Output;
52
52
  abstract parseSafe(json: unknown): ParseResult<Output>;
53
53
  abstract serialize(value: Output): Input;
54
- abstract toOpenAPI(): SchemaObject | ReferenceObject;
55
54
  protected readonly def: Def;
55
+ abstract toOpenAPI(): SchemaObject | ReferenceObject;
56
+ protected getSchemaObject(): SchemaObject;
56
57
  protected clone(def: Partial<Def>): this;
57
58
  protected constructor(def: Def);
58
59
  or<OtherInput extends JSONValue, OtherOutput, Def extends BaseSchemaDef<OtherInput>>(other: BaseSchema<OtherInput, OtherOutput, Def>): KUnion<(this | BaseSchema<OtherInput, OtherOutput, Def>)["_input"], (this | BaseSchema<OtherInput, OtherOutput, Def>)["_output"]>;
@@ -246,6 +247,7 @@ interface RefDef<Input extends Record<keyof Output, JSONValue>, Output extends R
246
247
  declare class KRef<Input extends Record<keyof Output, JSONValue>, Output extends Record<keyof Input, JSONValue>> extends BaseSchema<Input, Output, RefDef<Input, Output>> {
247
248
  static create: <Input_1 extends Record<keyof Output_1, JSONValue>, Output_1 extends Record<keyof Input_1, JSONValue>>(name: string, shape: { [K in keyof Input_1 | keyof Output_1]: BaseSchema<Input_1[K], Output_1[K], BaseSchemaDef<Input_1[K]>>; }) => KRef<Input_1, Output_1>;
248
249
  serialize(value: Output): Input;
250
+ example(): never;
249
251
  toOpenAPI(): ReferenceObject;
250
252
  parseSafe(json: unknown): ParseResult<Output>;
251
253
  parse(json: unknown): Output;
@@ -16,7 +16,7 @@ import {
16
16
  SchemaError,
17
17
  isPrimitiveJSONValue,
18
18
  k
19
- } from "../chunk-EPB3QL2T.js";
19
+ } from "../chunk-ISGKY24N.js";
20
20
  export {
21
21
  BaseSchema,
22
22
  KArray,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kaito-http/core",
3
3
  "type": "module",
4
- "version": "4.0.0-beta.15",
4
+ "version": "4.0.0-beta.16",
5
5
  "author": "Alistair Smith <hi@alistair.sh>",
6
6
  "repository": "https://github.com/kaito-http/kaito",
7
7
  "dependencies": {