@kaito-http/core 4.0.0-beta.15 → 4.0.0-beta.17
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/{chunk-EPB3QL2T.js → chunk-ISGKY24N.js} +40 -17
- package/dist/index.cjs +61 -36
- package/dist/index.d.cts +3 -4
- package/dist/index.d.ts +3 -4
- package/dist/index.js +22 -20
- package/dist/schema/schema.cjs +40 -17
- package/dist/schema/schema.d.cts +3 -1
- package/dist/schema/schema.d.ts +3 -1
- package/dist/schema/schema.js +1 -1
- package/package.json +1 -1
|
@@ -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
|
|
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
|
-
|
|
403
|
-
|
|
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
|
-
|
|
495
|
-
|
|
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
|
-
|
|
716
|
-
|
|
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 {
|
|
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
|
|
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
|
-
|
|
561
|
-
|
|
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
|
-
|
|
653
|
-
|
|
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
|
-
|
|
874
|
-
|
|
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 {
|
|
930
|
+
return {
|
|
931
|
+
...baseSchema,
|
|
932
|
+
type,
|
|
933
|
+
enum: [this.def.value]
|
|
934
|
+
};
|
|
912
935
|
}
|
|
913
936
|
parseSafe(json) {
|
|
914
937
|
return ParseContext.result((ctx) => {
|
|
@@ -1128,36 +1151,38 @@ var Router = class _Router {
|
|
|
1128
1151
|
const OPENAPI_VERSION = "3.1.0";
|
|
1129
1152
|
const paths = {};
|
|
1130
1153
|
for (const route of this.#state.routes) {
|
|
1131
|
-
const path = route.path;
|
|
1132
1154
|
if (!route.openapi) {
|
|
1133
1155
|
continue;
|
|
1134
1156
|
}
|
|
1135
|
-
const pathWithColonParamsReplaceWithCurlyBraces = path.replace(/:(\w+)/g, "{$1}");
|
|
1157
|
+
const pathWithColonParamsReplaceWithCurlyBraces = route.path.replace(/:(\w+)/g, "{$1}");
|
|
1136
1158
|
if (!paths[pathWithColonParamsReplaceWithCurlyBraces]) {
|
|
1137
1159
|
paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
|
|
1138
1160
|
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
}
|
|
1151
|
-
"text/event-stream": {
|
|
1152
|
-
schema: route.openapi.body.schema.toOpenAPI()
|
|
1153
|
-
}
|
|
1154
|
-
};
|
|
1161
|
+
let contentType;
|
|
1162
|
+
const type = route.openapi.type;
|
|
1163
|
+
switch (type) {
|
|
1164
|
+
case "json":
|
|
1165
|
+
contentType = "application/json";
|
|
1166
|
+
break;
|
|
1167
|
+
case "sse":
|
|
1168
|
+
contentType = "text/event-stream";
|
|
1169
|
+
break;
|
|
1170
|
+
default:
|
|
1171
|
+
throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
|
|
1172
|
+
}
|
|
1155
1173
|
const item = {
|
|
1156
1174
|
description: route.openapi?.description ?? "Successful response",
|
|
1157
1175
|
responses: {
|
|
1158
1176
|
200: {
|
|
1159
1177
|
description: route.openapi?.description ?? "Successful response",
|
|
1160
|
-
content
|
|
1178
|
+
content: {
|
|
1179
|
+
[contentType]: {
|
|
1180
|
+
schema: k.object({
|
|
1181
|
+
success: k.literal(true),
|
|
1182
|
+
data: route.openapi.schema
|
|
1183
|
+
}).toOpenAPI()
|
|
1184
|
+
}
|
|
1185
|
+
}
|
|
1161
1186
|
}
|
|
1162
1187
|
}
|
|
1163
1188
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -132,9 +132,8 @@ type JSONOutputSpec<Result extends JSONValue> = {
|
|
|
132
132
|
schema: AnySchemaFor<Result>;
|
|
133
133
|
description?: string;
|
|
134
134
|
};
|
|
135
|
-
type OutputSpec<Result> = {
|
|
135
|
+
type OutputSpec<Result> = Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>> & {
|
|
136
136
|
description?: string;
|
|
137
|
-
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>>;
|
|
138
137
|
};
|
|
139
138
|
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
|
|
140
139
|
body?: AnySchemaFor<Body>;
|
|
@@ -143,11 +142,11 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
143
142
|
};
|
|
144
143
|
path: Path;
|
|
145
144
|
method: Method;
|
|
146
|
-
openapi?: OutputSpec<
|
|
145
|
+
openapi?: NoInfer<OutputSpec<Result>>;
|
|
147
146
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
147
|
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
149
148
|
};
|
|
150
|
-
type AnyRoute = Route<any, any, any, any,
|
|
149
|
+
type AnyRoute = Route<any, any, any, any, string, any, KaitoMethod, any, any>;
|
|
151
150
|
|
|
152
151
|
/**
|
|
153
152
|
* A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
|
package/dist/index.d.ts
CHANGED
|
@@ -132,9 +132,8 @@ type JSONOutputSpec<Result extends JSONValue> = {
|
|
|
132
132
|
schema: AnySchemaFor<Result>;
|
|
133
133
|
description?: string;
|
|
134
134
|
};
|
|
135
|
-
type OutputSpec<Result> = {
|
|
135
|
+
type OutputSpec<Result> = Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>> & {
|
|
136
136
|
description?: string;
|
|
137
|
-
body: Result extends KaitoSSEResponse<infer R> ? SSEOutputSpec<Extract<R, JSONValue>> : JSONOutputSpec<Extract<Result, JSONValue>>;
|
|
138
137
|
};
|
|
139
138
|
type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Result, Path extends string, AdditionalParams extends string, Method extends KaitoMethod, Query extends Record<string, JSONValue>, Body extends JSONValue> = {
|
|
140
139
|
body?: AnySchemaFor<Body>;
|
|
@@ -143,11 +142,11 @@ type Route<ContextFrom, ContextTo, RouterInput extends readonly unknown[], Resul
|
|
|
143
142
|
};
|
|
144
143
|
path: Path;
|
|
145
144
|
method: Method;
|
|
146
|
-
openapi?: OutputSpec<
|
|
145
|
+
openapi?: NoInfer<OutputSpec<Result>>;
|
|
147
146
|
router: Router<ContextFrom, ContextTo, AdditionalParams, AnyRoute, RouterInput>;
|
|
148
147
|
run(data: RouteRunData<ExtractRouteParams<Path> | AdditionalParams, ContextTo, Query, Body>): Promise<Result> | Result;
|
|
149
148
|
};
|
|
150
|
-
type AnyRoute = Route<any, any, any, any,
|
|
149
|
+
type AnyRoute = Route<any, any, any, any, string, any, KaitoMethod, any, any>;
|
|
151
150
|
|
|
152
151
|
/**
|
|
153
152
|
* A helper to check if the environment is Node.js-like and the `NODE_ENV` environment variable is set to `'development'`
|
package/dist/index.js
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
SchemaError,
|
|
17
17
|
isPrimitiveJSONValue,
|
|
18
18
|
k
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-ISGKY24N.js";
|
|
20
20
|
|
|
21
21
|
// src/router/router.ts
|
|
22
22
|
import "openapi3-ts/oas31";
|
|
@@ -318,36 +318,38 @@ var Router = class _Router {
|
|
|
318
318
|
const OPENAPI_VERSION = "3.1.0";
|
|
319
319
|
const paths = {};
|
|
320
320
|
for (const route of this.#state.routes) {
|
|
321
|
-
const path = route.path;
|
|
322
321
|
if (!route.openapi) {
|
|
323
322
|
continue;
|
|
324
323
|
}
|
|
325
|
-
const pathWithColonParamsReplaceWithCurlyBraces = path.replace(/:(\w+)/g, "{$1}");
|
|
324
|
+
const pathWithColonParamsReplaceWithCurlyBraces = route.path.replace(/:(\w+)/g, "{$1}");
|
|
326
325
|
if (!paths[pathWithColonParamsReplaceWithCurlyBraces]) {
|
|
327
326
|
paths[pathWithColonParamsReplaceWithCurlyBraces] = {};
|
|
328
327
|
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
}
|
|
341
|
-
"text/event-stream": {
|
|
342
|
-
schema: route.openapi.body.schema.toOpenAPI()
|
|
343
|
-
}
|
|
344
|
-
};
|
|
328
|
+
let contentType;
|
|
329
|
+
const type = route.openapi.type;
|
|
330
|
+
switch (type) {
|
|
331
|
+
case "json":
|
|
332
|
+
contentType = "application/json";
|
|
333
|
+
break;
|
|
334
|
+
case "sse":
|
|
335
|
+
contentType = "text/event-stream";
|
|
336
|
+
break;
|
|
337
|
+
default:
|
|
338
|
+
throw new Error(`Unknown output type in route ${route.method} ${route.path}: ${type}`);
|
|
339
|
+
}
|
|
345
340
|
const item = {
|
|
346
341
|
description: route.openapi?.description ?? "Successful response",
|
|
347
342
|
responses: {
|
|
348
343
|
200: {
|
|
349
344
|
description: route.openapi?.description ?? "Successful response",
|
|
350
|
-
content
|
|
345
|
+
content: {
|
|
346
|
+
[contentType]: {
|
|
347
|
+
schema: k.object({
|
|
348
|
+
success: k.literal(true),
|
|
349
|
+
data: route.openapi.schema
|
|
350
|
+
}).toOpenAPI()
|
|
351
|
+
}
|
|
352
|
+
}
|
|
351
353
|
}
|
|
352
354
|
}
|
|
353
355
|
};
|
package/dist/schema/schema.cjs
CHANGED
|
@@ -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
|
|
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
|
-
|
|
443
|
-
|
|
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
|
-
|
|
535
|
-
|
|
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
|
-
|
|
756
|
-
|
|
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 {
|
|
812
|
+
return {
|
|
813
|
+
...baseSchema,
|
|
814
|
+
type,
|
|
815
|
+
enum: [this.def.value]
|
|
816
|
+
};
|
|
794
817
|
}
|
|
795
818
|
parseSafe(json) {
|
|
796
819
|
return ParseContext.result((ctx) => {
|
package/dist/schema/schema.d.cts
CHANGED
|
@@ -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;
|
package/dist/schema/schema.d.ts
CHANGED
|
@@ -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;
|
package/dist/schema/schema.js
CHANGED