@orpc/openapi 0.0.0-next.8f9385e → 0.0.0-next.93e7a4c
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-UPDKQRQG.js +665 -0
- package/dist/fetch.js +28 -666
- package/dist/index.js +438 -252
- package/dist/src/fetch/bracket-notation.d.ts +84 -0
- package/dist/src/fetch/index.d.ts +9 -3
- package/dist/src/fetch/input-builder-full.d.ts +11 -0
- package/dist/src/fetch/input-builder-simple.d.ts +6 -0
- package/dist/src/fetch/openapi-handler-server.d.ts +7 -0
- package/dist/src/fetch/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/fetch/openapi-handler.d.ts +28 -0
- package/dist/src/fetch/openapi-payload-codec.d.ts +13 -0
- package/dist/src/fetch/openapi-procedure-matcher.d.ts +19 -0
- package/dist/src/fetch/schema-coercer.d.ts +10 -0
- package/dist/src/generator.d.ts +5 -3
- package/dist/src/utils.d.ts +17 -0
- package/dist/src/zod-to-json-schema.d.ts +2 -2
- package/package.json +11 -8
- package/dist/src/fetch/base-handler.d.ts +0 -15
- package/dist/src/fetch/server-handler.d.ts +0 -3
- package/dist/src/fetch/serverless-handler.d.ts +0 -3
package/dist/index.js
CHANGED
|
@@ -1,24 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIPayloadCodec,
|
|
3
|
+
forEachContractProcedure,
|
|
4
|
+
standardizeHTTPPath
|
|
5
|
+
} from "./chunk-UPDKQRQG.js";
|
|
6
|
+
|
|
1
7
|
// src/generator.ts
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
8
|
+
import { isContractProcedure } from "@orpc/contract";
|
|
9
|
+
import { unlazy } from "@orpc/server";
|
|
4
10
|
import { findDeepMatches, isPlainObject, omit } from "@orpc/shared";
|
|
5
|
-
import { preSerialize } from "@orpc/transformer";
|
|
6
11
|
import {
|
|
7
12
|
OpenApiBuilder
|
|
8
13
|
} from "openapi3-ts/oas31";
|
|
9
14
|
|
|
10
|
-
// src/
|
|
11
|
-
import {
|
|
12
|
-
getCustomJSONSchema,
|
|
13
|
-
getCustomZodFileMimeType,
|
|
14
|
-
getCustomZodType
|
|
15
|
-
} from "@orpc/zod";
|
|
16
|
-
import escapeStringRegexp from "escape-string-regexp";
|
|
17
|
-
import {
|
|
18
|
-
Format
|
|
19
|
-
} from "json-schema-typed/draft-2020-12";
|
|
15
|
+
// ../zod/src/coercer.ts
|
|
16
|
+
import { guard } from "@orpc/shared";
|
|
20
17
|
|
|
21
|
-
// ../../node_modules/.pnpm/zod@3.
|
|
18
|
+
// ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
|
|
22
19
|
var util;
|
|
23
20
|
(function(util2) {
|
|
24
21
|
util2.assertEqual = (val) => val;
|
|
@@ -169,6 +166,9 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
169
166
|
"not_finite"
|
|
170
167
|
]);
|
|
171
168
|
var ZodError = class _ZodError extends Error {
|
|
169
|
+
get errors() {
|
|
170
|
+
return this.issues;
|
|
171
|
+
}
|
|
172
172
|
constructor(issues) {
|
|
173
173
|
super();
|
|
174
174
|
this.issues = [];
|
|
@@ -187,9 +187,6 @@ var ZodError = class _ZodError extends Error {
|
|
|
187
187
|
this.name = "ZodError";
|
|
188
188
|
this.issues = issues;
|
|
189
189
|
}
|
|
190
|
-
get errors() {
|
|
191
|
-
return this.issues;
|
|
192
|
-
}
|
|
193
190
|
format(_mapper) {
|
|
194
191
|
const mapper = _mapper || function(issue) {
|
|
195
192
|
return issue.message;
|
|
@@ -396,8 +393,11 @@ function addIssueToContext(ctx, issueData) {
|
|
|
396
393
|
path: ctx.path,
|
|
397
394
|
errorMaps: [
|
|
398
395
|
ctx.common.contextualErrorMap,
|
|
396
|
+
// contextual error map is first priority
|
|
399
397
|
ctx.schemaErrorMap,
|
|
398
|
+
// then schema-bound map if available
|
|
400
399
|
overrideMap,
|
|
400
|
+
// then global override map
|
|
401
401
|
overrideMap === errorMap ? void 0 : errorMap
|
|
402
402
|
// then global default map
|
|
403
403
|
].filter((x) => !!x)
|
|
@@ -548,34 +548,6 @@ function processCreateParams(params) {
|
|
|
548
548
|
return { errorMap: customMap, description };
|
|
549
549
|
}
|
|
550
550
|
var ZodType = class {
|
|
551
|
-
constructor(def) {
|
|
552
|
-
this.spa = this.safeParseAsync;
|
|
553
|
-
this._def = def;
|
|
554
|
-
this.parse = this.parse.bind(this);
|
|
555
|
-
this.safeParse = this.safeParse.bind(this);
|
|
556
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
557
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
558
|
-
this.spa = this.spa.bind(this);
|
|
559
|
-
this.refine = this.refine.bind(this);
|
|
560
|
-
this.refinement = this.refinement.bind(this);
|
|
561
|
-
this.superRefine = this.superRefine.bind(this);
|
|
562
|
-
this.optional = this.optional.bind(this);
|
|
563
|
-
this.nullable = this.nullable.bind(this);
|
|
564
|
-
this.nullish = this.nullish.bind(this);
|
|
565
|
-
this.array = this.array.bind(this);
|
|
566
|
-
this.promise = this.promise.bind(this);
|
|
567
|
-
this.or = this.or.bind(this);
|
|
568
|
-
this.and = this.and.bind(this);
|
|
569
|
-
this.transform = this.transform.bind(this);
|
|
570
|
-
this.brand = this.brand.bind(this);
|
|
571
|
-
this.default = this.default.bind(this);
|
|
572
|
-
this.catch = this.catch.bind(this);
|
|
573
|
-
this.describe = this.describe.bind(this);
|
|
574
|
-
this.pipe = this.pipe.bind(this);
|
|
575
|
-
this.readonly = this.readonly.bind(this);
|
|
576
|
-
this.isNullable = this.isNullable.bind(this);
|
|
577
|
-
this.isOptional = this.isOptional.bind(this);
|
|
578
|
-
}
|
|
579
551
|
get description() {
|
|
580
552
|
return this._def.description;
|
|
581
553
|
}
|
|
@@ -639,6 +611,43 @@ var ZodType = class {
|
|
|
639
611
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
640
612
|
return handleResult(ctx, result);
|
|
641
613
|
}
|
|
614
|
+
"~validate"(data) {
|
|
615
|
+
var _a, _b;
|
|
616
|
+
const ctx = {
|
|
617
|
+
common: {
|
|
618
|
+
issues: [],
|
|
619
|
+
async: !!this["~standard"].async
|
|
620
|
+
},
|
|
621
|
+
path: [],
|
|
622
|
+
schemaErrorMap: this._def.errorMap,
|
|
623
|
+
parent: null,
|
|
624
|
+
data,
|
|
625
|
+
parsedType: getParsedType(data)
|
|
626
|
+
};
|
|
627
|
+
if (!this["~standard"].async) {
|
|
628
|
+
try {
|
|
629
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
630
|
+
return isValid(result) ? {
|
|
631
|
+
value: result.value
|
|
632
|
+
} : {
|
|
633
|
+
issues: ctx.common.issues
|
|
634
|
+
};
|
|
635
|
+
} catch (err) {
|
|
636
|
+
if ((_b = (_a = err === null || err === void 0 ? void 0 : err.message) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === null || _b === void 0 ? void 0 : _b.includes("encountered")) {
|
|
637
|
+
this["~standard"].async = true;
|
|
638
|
+
}
|
|
639
|
+
ctx.common = {
|
|
640
|
+
issues: [],
|
|
641
|
+
async: true
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
646
|
+
value: result.value
|
|
647
|
+
} : {
|
|
648
|
+
issues: ctx.common.issues
|
|
649
|
+
});
|
|
650
|
+
}
|
|
642
651
|
async parseAsync(data, params) {
|
|
643
652
|
const result = await this.safeParseAsync(data, params);
|
|
644
653
|
if (result.success)
|
|
@@ -716,6 +725,39 @@ var ZodType = class {
|
|
|
716
725
|
superRefine(refinement) {
|
|
717
726
|
return this._refinement(refinement);
|
|
718
727
|
}
|
|
728
|
+
constructor(def) {
|
|
729
|
+
this.spa = this.safeParseAsync;
|
|
730
|
+
this._def = def;
|
|
731
|
+
this.parse = this.parse.bind(this);
|
|
732
|
+
this.safeParse = this.safeParse.bind(this);
|
|
733
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
734
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
735
|
+
this.spa = this.spa.bind(this);
|
|
736
|
+
this.refine = this.refine.bind(this);
|
|
737
|
+
this.refinement = this.refinement.bind(this);
|
|
738
|
+
this.superRefine = this.superRefine.bind(this);
|
|
739
|
+
this.optional = this.optional.bind(this);
|
|
740
|
+
this.nullable = this.nullable.bind(this);
|
|
741
|
+
this.nullish = this.nullish.bind(this);
|
|
742
|
+
this.array = this.array.bind(this);
|
|
743
|
+
this.promise = this.promise.bind(this);
|
|
744
|
+
this.or = this.or.bind(this);
|
|
745
|
+
this.and = this.and.bind(this);
|
|
746
|
+
this.transform = this.transform.bind(this);
|
|
747
|
+
this.brand = this.brand.bind(this);
|
|
748
|
+
this.default = this.default.bind(this);
|
|
749
|
+
this.catch = this.catch.bind(this);
|
|
750
|
+
this.describe = this.describe.bind(this);
|
|
751
|
+
this.pipe = this.pipe.bind(this);
|
|
752
|
+
this.readonly = this.readonly.bind(this);
|
|
753
|
+
this.isNullable = this.isNullable.bind(this);
|
|
754
|
+
this.isOptional = this.isOptional.bind(this);
|
|
755
|
+
this["~standard"] = {
|
|
756
|
+
version: 1,
|
|
757
|
+
vendor: "zod",
|
|
758
|
+
validate: (data) => this["~validate"](data)
|
|
759
|
+
};
|
|
760
|
+
}
|
|
719
761
|
optional() {
|
|
720
762
|
return ZodOptional.create(this, this._def);
|
|
721
763
|
}
|
|
@@ -726,7 +768,7 @@ var ZodType = class {
|
|
|
726
768
|
return this.nullable().optional();
|
|
727
769
|
}
|
|
728
770
|
array() {
|
|
729
|
-
return ZodArray.create(this
|
|
771
|
+
return ZodArray.create(this);
|
|
730
772
|
}
|
|
731
773
|
promise() {
|
|
732
774
|
return ZodPromise.create(this, this._def);
|
|
@@ -792,16 +834,20 @@ var ZodType = class {
|
|
|
792
834
|
};
|
|
793
835
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
794
836
|
var cuid2Regex = /^[0-9a-z]+$/;
|
|
795
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
837
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
796
838
|
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
797
839
|
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
840
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
798
841
|
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
799
842
|
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
800
843
|
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
801
844
|
var emojiRegex;
|
|
802
845
|
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
803
|
-
var
|
|
846
|
+
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
847
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
848
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
804
849
|
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
850
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
805
851
|
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
806
852
|
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
807
853
|
function timeRegexSource(args) {
|
|
@@ -834,6 +880,33 @@ function isValidIP(ip, version) {
|
|
|
834
880
|
}
|
|
835
881
|
return false;
|
|
836
882
|
}
|
|
883
|
+
function isValidJWT(jwt, alg) {
|
|
884
|
+
if (!jwtRegex.test(jwt))
|
|
885
|
+
return false;
|
|
886
|
+
try {
|
|
887
|
+
const [header] = jwt.split(".");
|
|
888
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
889
|
+
const decoded = JSON.parse(atob(base64));
|
|
890
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
891
|
+
return false;
|
|
892
|
+
if (!decoded.typ || !decoded.alg)
|
|
893
|
+
return false;
|
|
894
|
+
if (alg && decoded.alg !== alg)
|
|
895
|
+
return false;
|
|
896
|
+
return true;
|
|
897
|
+
} catch (_a) {
|
|
898
|
+
return false;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
function isValidCidr(ip, version) {
|
|
902
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
903
|
+
return true;
|
|
904
|
+
}
|
|
905
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
906
|
+
return true;
|
|
907
|
+
}
|
|
908
|
+
return false;
|
|
909
|
+
}
|
|
837
910
|
var ZodString = class _ZodString extends ZodType {
|
|
838
911
|
_parse(input) {
|
|
839
912
|
if (this._def.coerce) {
|
|
@@ -1090,6 +1163,26 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1090
1163
|
});
|
|
1091
1164
|
status.dirty();
|
|
1092
1165
|
}
|
|
1166
|
+
} else if (check.kind === "jwt") {
|
|
1167
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1168
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1169
|
+
addIssueToContext(ctx, {
|
|
1170
|
+
validation: "jwt",
|
|
1171
|
+
code: ZodIssueCode.invalid_string,
|
|
1172
|
+
message: check.message
|
|
1173
|
+
});
|
|
1174
|
+
status.dirty();
|
|
1175
|
+
}
|
|
1176
|
+
} else if (check.kind === "cidr") {
|
|
1177
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1178
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1179
|
+
addIssueToContext(ctx, {
|
|
1180
|
+
validation: "cidr",
|
|
1181
|
+
code: ZodIssueCode.invalid_string,
|
|
1182
|
+
message: check.message
|
|
1183
|
+
});
|
|
1184
|
+
status.dirty();
|
|
1185
|
+
}
|
|
1093
1186
|
} else if (check.kind === "base64") {
|
|
1094
1187
|
if (!base64Regex.test(input.data)) {
|
|
1095
1188
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1100,6 +1193,16 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1100
1193
|
});
|
|
1101
1194
|
status.dirty();
|
|
1102
1195
|
}
|
|
1196
|
+
} else if (check.kind === "base64url") {
|
|
1197
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1198
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1199
|
+
addIssueToContext(ctx, {
|
|
1200
|
+
validation: "base64url",
|
|
1201
|
+
code: ZodIssueCode.invalid_string,
|
|
1202
|
+
message: check.message
|
|
1203
|
+
});
|
|
1204
|
+
status.dirty();
|
|
1205
|
+
}
|
|
1103
1206
|
} else {
|
|
1104
1207
|
util.assertNever(check);
|
|
1105
1208
|
}
|
|
@@ -1146,9 +1249,21 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1146
1249
|
base64(message) {
|
|
1147
1250
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1148
1251
|
}
|
|
1252
|
+
base64url(message) {
|
|
1253
|
+
return this._addCheck({
|
|
1254
|
+
kind: "base64url",
|
|
1255
|
+
...errorUtil.errToObj(message)
|
|
1256
|
+
});
|
|
1257
|
+
}
|
|
1258
|
+
jwt(options) {
|
|
1259
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1260
|
+
}
|
|
1149
1261
|
ip(options) {
|
|
1150
1262
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1151
1263
|
}
|
|
1264
|
+
cidr(options) {
|
|
1265
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1266
|
+
}
|
|
1152
1267
|
datetime(options) {
|
|
1153
1268
|
var _a, _b;
|
|
1154
1269
|
if (typeof options === "string") {
|
|
@@ -1239,8 +1354,7 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1239
1354
|
});
|
|
1240
1355
|
}
|
|
1241
1356
|
/**
|
|
1242
|
-
*
|
|
1243
|
-
* @see {@link ZodString.min}
|
|
1357
|
+
* Equivalent to `.min(1)`
|
|
1244
1358
|
*/
|
|
1245
1359
|
nonempty(message) {
|
|
1246
1360
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -1302,9 +1416,15 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1302
1416
|
get isIP() {
|
|
1303
1417
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1304
1418
|
}
|
|
1419
|
+
get isCIDR() {
|
|
1420
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1421
|
+
}
|
|
1305
1422
|
get isBase64() {
|
|
1306
1423
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1307
1424
|
}
|
|
1425
|
+
get isBase64url() {
|
|
1426
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1427
|
+
}
|
|
1308
1428
|
get minLength() {
|
|
1309
1429
|
let min = null;
|
|
1310
1430
|
for (const ch of this._def.checks) {
|
|
@@ -1582,17 +1702,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1582
1702
|
}
|
|
1583
1703
|
_parse(input) {
|
|
1584
1704
|
if (this._def.coerce) {
|
|
1585
|
-
|
|
1705
|
+
try {
|
|
1706
|
+
input.data = BigInt(input.data);
|
|
1707
|
+
} catch (_a) {
|
|
1708
|
+
return this._getInvalidInput(input);
|
|
1709
|
+
}
|
|
1586
1710
|
}
|
|
1587
1711
|
const parsedType = this._getType(input);
|
|
1588
1712
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1589
|
-
|
|
1590
|
-
addIssueToContext(ctx2, {
|
|
1591
|
-
code: ZodIssueCode.invalid_type,
|
|
1592
|
-
expected: ZodParsedType.bigint,
|
|
1593
|
-
received: ctx2.parsedType
|
|
1594
|
-
});
|
|
1595
|
-
return INVALID;
|
|
1713
|
+
return this._getInvalidInput(input);
|
|
1596
1714
|
}
|
|
1597
1715
|
let ctx = void 0;
|
|
1598
1716
|
const status = new ParseStatus();
|
|
@@ -1639,6 +1757,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1639
1757
|
}
|
|
1640
1758
|
return { status: status.value, value: input.data };
|
|
1641
1759
|
}
|
|
1760
|
+
_getInvalidInput(input) {
|
|
1761
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1762
|
+
addIssueToContext(ctx, {
|
|
1763
|
+
code: ZodIssueCode.invalid_type,
|
|
1764
|
+
expected: ZodParsedType.bigint,
|
|
1765
|
+
received: ctx.parsedType
|
|
1766
|
+
});
|
|
1767
|
+
return INVALID;
|
|
1768
|
+
}
|
|
1642
1769
|
gte(value, message) {
|
|
1643
1770
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1644
1771
|
}
|
|
@@ -3778,7 +3905,37 @@ var nullableType = ZodNullable.create;
|
|
|
3778
3905
|
var preprocessType = ZodEffects.createWithPreprocess;
|
|
3779
3906
|
var pipelineType = ZodPipeline.create;
|
|
3780
3907
|
|
|
3908
|
+
// ../zod/src/schemas.ts
|
|
3909
|
+
import wcmatch from "wildcard-match";
|
|
3910
|
+
var customZodTypeSymbol = Symbol("customZodTypeSymbol");
|
|
3911
|
+
var customZodFileMimeTypeSymbol = Symbol("customZodFileMimeTypeSymbol");
|
|
3912
|
+
var CUSTOM_JSON_SCHEMA_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA");
|
|
3913
|
+
var CUSTOM_JSON_SCHEMA_INPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_INPUT");
|
|
3914
|
+
var CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL = Symbol("CUSTOM_JSON_SCHEMA_OUTPUT");
|
|
3915
|
+
function getCustomZodType(def) {
|
|
3916
|
+
return customZodTypeSymbol in def ? def[customZodTypeSymbol] : void 0;
|
|
3917
|
+
}
|
|
3918
|
+
function getCustomZodFileMimeType(def) {
|
|
3919
|
+
return customZodFileMimeTypeSymbol in def ? def[customZodFileMimeTypeSymbol] : void 0;
|
|
3920
|
+
}
|
|
3921
|
+
function getCustomJSONSchema(def, options) {
|
|
3922
|
+
if (options?.mode === "input" && CUSTOM_JSON_SCHEMA_INPUT_SYMBOL in def) {
|
|
3923
|
+
return def[CUSTOM_JSON_SCHEMA_INPUT_SYMBOL];
|
|
3924
|
+
}
|
|
3925
|
+
if (options?.mode === "output" && CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL in def) {
|
|
3926
|
+
return def[CUSTOM_JSON_SCHEMA_OUTPUT_SYMBOL];
|
|
3927
|
+
}
|
|
3928
|
+
if (CUSTOM_JSON_SCHEMA_SYMBOL in def) {
|
|
3929
|
+
return def[CUSTOM_JSON_SCHEMA_SYMBOL];
|
|
3930
|
+
}
|
|
3931
|
+
return void 0;
|
|
3932
|
+
}
|
|
3933
|
+
|
|
3781
3934
|
// src/zod-to-json-schema.ts
|
|
3935
|
+
import escapeStringRegexp from "escape-string-regexp";
|
|
3936
|
+
import {
|
|
3937
|
+
Format
|
|
3938
|
+
} from "json-schema-typed/draft-2020-12";
|
|
3782
3939
|
var NON_LOGIC_KEYWORDS = [
|
|
3783
3940
|
// Core Documentation Keywords
|
|
3784
3941
|
"$anchor",
|
|
@@ -3809,10 +3966,15 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
3809
3966
|
var UNSUPPORTED_JSON_SCHEMA = { not: {} };
|
|
3810
3967
|
var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
|
|
3811
3968
|
function zodToJsonSchema(schema, options) {
|
|
3969
|
+
if (schema["~standard"].vendor !== "zod") {
|
|
3970
|
+
console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
|
|
3971
|
+
return {};
|
|
3972
|
+
}
|
|
3973
|
+
const schema__ = schema;
|
|
3812
3974
|
if (!options?.isHandledCustomJSONSchema) {
|
|
3813
|
-
const customJSONSchema = getCustomJSONSchema(
|
|
3975
|
+
const customJSONSchema = getCustomJSONSchema(schema__._def, options);
|
|
3814
3976
|
if (customJSONSchema) {
|
|
3815
|
-
const json = zodToJsonSchema(
|
|
3977
|
+
const json = zodToJsonSchema(schema__, {
|
|
3816
3978
|
...options,
|
|
3817
3979
|
isHandledCustomJSONSchema: true
|
|
3818
3980
|
});
|
|
@@ -3823,13 +3985,13 @@ function zodToJsonSchema(schema, options) {
|
|
|
3823
3985
|
}
|
|
3824
3986
|
}
|
|
3825
3987
|
const childOptions = { ...options, isHandledCustomJSONSchema: false };
|
|
3826
|
-
const customType = getCustomZodType(
|
|
3988
|
+
const customType = getCustomZodType(schema__._def);
|
|
3827
3989
|
switch (customType) {
|
|
3828
3990
|
case "Blob": {
|
|
3829
3991
|
return { type: "string", contentMediaType: "*/*" };
|
|
3830
3992
|
}
|
|
3831
3993
|
case "File": {
|
|
3832
|
-
const mimeType = getCustomZodFileMimeType(
|
|
3994
|
+
const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
|
|
3833
3995
|
return { type: "string", contentMediaType: mimeType };
|
|
3834
3996
|
}
|
|
3835
3997
|
case "Invalid Date": {
|
|
@@ -3846,10 +4008,10 @@ function zodToJsonSchema(schema, options) {
|
|
|
3846
4008
|
}
|
|
3847
4009
|
}
|
|
3848
4010
|
const _expectedCustomType = customType;
|
|
3849
|
-
const typeName =
|
|
4011
|
+
const typeName = schema__._def.typeName;
|
|
3850
4012
|
switch (typeName) {
|
|
3851
4013
|
case ZodFirstPartyTypeKind.ZodString: {
|
|
3852
|
-
const schema_ =
|
|
4014
|
+
const schema_ = schema__;
|
|
3853
4015
|
const json = { type: "string" };
|
|
3854
4016
|
for (const check of schema_._def.checks) {
|
|
3855
4017
|
switch (check.kind) {
|
|
@@ -3917,6 +4079,12 @@ function zodToJsonSchema(schema, options) {
|
|
|
3917
4079
|
case "ip":
|
|
3918
4080
|
json.format = Format.IPv4;
|
|
3919
4081
|
break;
|
|
4082
|
+
case "jwt":
|
|
4083
|
+
json.pattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$";
|
|
4084
|
+
break;
|
|
4085
|
+
case "base64url":
|
|
4086
|
+
json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
|
|
4087
|
+
break;
|
|
3920
4088
|
default: {
|
|
3921
4089
|
const _expect = check.kind;
|
|
3922
4090
|
}
|
|
@@ -3925,7 +4093,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
3925
4093
|
return json;
|
|
3926
4094
|
}
|
|
3927
4095
|
case ZodFirstPartyTypeKind.ZodNumber: {
|
|
3928
|
-
const schema_ =
|
|
4096
|
+
const schema_ = schema__;
|
|
3929
4097
|
const json = { type: "number" };
|
|
3930
4098
|
for (const check of schema_._def.checks) {
|
|
3931
4099
|
switch (check.kind) {
|
|
@@ -3970,23 +4138,23 @@ function zodToJsonSchema(schema, options) {
|
|
|
3970
4138
|
return UNDEFINED_JSON_SCHEMA;
|
|
3971
4139
|
}
|
|
3972
4140
|
case ZodFirstPartyTypeKind.ZodLiteral: {
|
|
3973
|
-
const schema_ =
|
|
4141
|
+
const schema_ = schema__;
|
|
3974
4142
|
return { const: schema_._def.value };
|
|
3975
4143
|
}
|
|
3976
4144
|
case ZodFirstPartyTypeKind.ZodEnum: {
|
|
3977
|
-
const schema_ =
|
|
4145
|
+
const schema_ = schema__;
|
|
3978
4146
|
return {
|
|
3979
4147
|
enum: schema_._def.values
|
|
3980
4148
|
};
|
|
3981
4149
|
}
|
|
3982
4150
|
case ZodFirstPartyTypeKind.ZodNativeEnum: {
|
|
3983
|
-
const schema_ =
|
|
4151
|
+
const schema_ = schema__;
|
|
3984
4152
|
return {
|
|
3985
4153
|
enum: Object.values(schema_._def.values)
|
|
3986
4154
|
};
|
|
3987
4155
|
}
|
|
3988
4156
|
case ZodFirstPartyTypeKind.ZodArray: {
|
|
3989
|
-
const schema_ =
|
|
4157
|
+
const schema_ = schema__;
|
|
3990
4158
|
const def = schema_._def;
|
|
3991
4159
|
const json = { type: "array" };
|
|
3992
4160
|
if (def.exactLength) {
|
|
@@ -4002,7 +4170,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4002
4170
|
return json;
|
|
4003
4171
|
}
|
|
4004
4172
|
case ZodFirstPartyTypeKind.ZodTuple: {
|
|
4005
|
-
const schema_ =
|
|
4173
|
+
const schema_ = schema__;
|
|
4006
4174
|
const prefixItems = [];
|
|
4007
4175
|
const json = { type: "array" };
|
|
4008
4176
|
for (const item of schema_._def.items) {
|
|
@@ -4020,7 +4188,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4020
4188
|
return json;
|
|
4021
4189
|
}
|
|
4022
4190
|
case ZodFirstPartyTypeKind.ZodObject: {
|
|
4023
|
-
const schema_ =
|
|
4191
|
+
const schema_ = schema__;
|
|
4024
4192
|
const json = { type: "object" };
|
|
4025
4193
|
const properties = {};
|
|
4026
4194
|
const required = [];
|
|
@@ -4056,7 +4224,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4056
4224
|
return json;
|
|
4057
4225
|
}
|
|
4058
4226
|
case ZodFirstPartyTypeKind.ZodRecord: {
|
|
4059
|
-
const schema_ =
|
|
4227
|
+
const schema_ = schema__;
|
|
4060
4228
|
const json = { type: "object" };
|
|
4061
4229
|
json.additionalProperties = zodToJsonSchema(
|
|
4062
4230
|
schema_._def.valueType,
|
|
@@ -4065,14 +4233,14 @@ function zodToJsonSchema(schema, options) {
|
|
|
4065
4233
|
return json;
|
|
4066
4234
|
}
|
|
4067
4235
|
case ZodFirstPartyTypeKind.ZodSet: {
|
|
4068
|
-
const schema_ =
|
|
4236
|
+
const schema_ = schema__;
|
|
4069
4237
|
return {
|
|
4070
4238
|
type: "array",
|
|
4071
4239
|
items: zodToJsonSchema(schema_._def.valueType, childOptions)
|
|
4072
4240
|
};
|
|
4073
4241
|
}
|
|
4074
4242
|
case ZodFirstPartyTypeKind.ZodMap: {
|
|
4075
|
-
const schema_ =
|
|
4243
|
+
const schema_ = schema__;
|
|
4076
4244
|
return {
|
|
4077
4245
|
type: "array",
|
|
4078
4246
|
items: {
|
|
@@ -4088,7 +4256,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4088
4256
|
}
|
|
4089
4257
|
case ZodFirstPartyTypeKind.ZodUnion:
|
|
4090
4258
|
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
|
|
4091
|
-
const schema_ =
|
|
4259
|
+
const schema_ = schema__;
|
|
4092
4260
|
const anyOf = [];
|
|
4093
4261
|
for (const s of schema_._def.options) {
|
|
4094
4262
|
anyOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4096,7 +4264,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4096
4264
|
return { anyOf };
|
|
4097
4265
|
}
|
|
4098
4266
|
case ZodFirstPartyTypeKind.ZodIntersection: {
|
|
4099
|
-
const schema_ =
|
|
4267
|
+
const schema_ = schema__;
|
|
4100
4268
|
const allOf = [];
|
|
4101
4269
|
for (const s of [schema_._def.left, schema_._def.right]) {
|
|
4102
4270
|
allOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4104,7 +4272,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4104
4272
|
return { allOf };
|
|
4105
4273
|
}
|
|
4106
4274
|
case ZodFirstPartyTypeKind.ZodLazy: {
|
|
4107
|
-
const schema_ =
|
|
4275
|
+
const schema_ = schema__;
|
|
4108
4276
|
const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
|
|
4109
4277
|
const lazyDepth = childOptions?.lazyDepth ?? 0;
|
|
4110
4278
|
if (lazyDepth > maxLazyDepth) {
|
|
@@ -4121,44 +4289,44 @@ function zodToJsonSchema(schema, options) {
|
|
|
4121
4289
|
return {};
|
|
4122
4290
|
}
|
|
4123
4291
|
case ZodFirstPartyTypeKind.ZodOptional: {
|
|
4124
|
-
const schema_ =
|
|
4292
|
+
const schema_ = schema__;
|
|
4125
4293
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4126
4294
|
return {
|
|
4127
4295
|
anyOf: [UNDEFINED_JSON_SCHEMA, inner]
|
|
4128
4296
|
};
|
|
4129
4297
|
}
|
|
4130
4298
|
case ZodFirstPartyTypeKind.ZodReadonly: {
|
|
4131
|
-
const schema_ =
|
|
4299
|
+
const schema_ = schema__;
|
|
4132
4300
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4133
4301
|
}
|
|
4134
4302
|
case ZodFirstPartyTypeKind.ZodDefault: {
|
|
4135
|
-
const schema_ =
|
|
4303
|
+
const schema_ = schema__;
|
|
4136
4304
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4137
4305
|
}
|
|
4138
4306
|
case ZodFirstPartyTypeKind.ZodEffects: {
|
|
4139
|
-
const schema_ =
|
|
4307
|
+
const schema_ = schema__;
|
|
4140
4308
|
if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
|
|
4141
4309
|
return {};
|
|
4142
4310
|
}
|
|
4143
4311
|
return zodToJsonSchema(schema_._def.schema, childOptions);
|
|
4144
4312
|
}
|
|
4145
4313
|
case ZodFirstPartyTypeKind.ZodCatch: {
|
|
4146
|
-
const schema_ =
|
|
4314
|
+
const schema_ = schema__;
|
|
4147
4315
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4148
4316
|
}
|
|
4149
4317
|
case ZodFirstPartyTypeKind.ZodBranded: {
|
|
4150
|
-
const schema_ =
|
|
4318
|
+
const schema_ = schema__;
|
|
4151
4319
|
return zodToJsonSchema(schema_._def.type, childOptions);
|
|
4152
4320
|
}
|
|
4153
4321
|
case ZodFirstPartyTypeKind.ZodPipeline: {
|
|
4154
|
-
const schema_ =
|
|
4322
|
+
const schema_ = schema__;
|
|
4155
4323
|
return zodToJsonSchema(
|
|
4156
4324
|
childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
|
|
4157
4325
|
childOptions
|
|
4158
4326
|
);
|
|
4159
4327
|
}
|
|
4160
4328
|
case ZodFirstPartyTypeKind.ZodNullable: {
|
|
4161
|
-
const schema_ =
|
|
4329
|
+
const schema_ = schema__;
|
|
4162
4330
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4163
4331
|
return {
|
|
4164
4332
|
anyOf: [{ type: "null" }, inner]
|
|
@@ -4210,206 +4378,224 @@ function extractJSONSchema(schema, check, matches = []) {
|
|
|
4210
4378
|
}
|
|
4211
4379
|
|
|
4212
4380
|
// src/generator.ts
|
|
4213
|
-
function generateOpenAPI(opts, options) {
|
|
4381
|
+
async function generateOpenAPI(opts, options) {
|
|
4214
4382
|
const throwOnMissingTagDefinition = options?.throwOnMissingTagDefinition ?? false;
|
|
4215
4383
|
const ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
4384
|
+
const payloadCodec = options?.payloadCodec ?? new OpenAPIPayloadCodec();
|
|
4216
4385
|
const builder = new OpenApiBuilder({
|
|
4217
4386
|
...omit(opts, ["router"]),
|
|
4218
4387
|
openapi: "3.1.0"
|
|
4219
4388
|
});
|
|
4220
4389
|
const rootTags = opts.tags?.map((tag) => tag.name) ?? [];
|
|
4221
|
-
const
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
}
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
|
|
4230
|
-
const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
|
|
4231
|
-
const params = (() => {
|
|
4232
|
-
const names = path.match(/\{([^}]+)\}/g);
|
|
4233
|
-
if (!names || !names.length) {
|
|
4234
|
-
return void 0;
|
|
4390
|
+
const pending = [{
|
|
4391
|
+
path: [],
|
|
4392
|
+
router: opts.router
|
|
4393
|
+
}];
|
|
4394
|
+
for (const item of pending) {
|
|
4395
|
+
const lazies = forEachContractProcedure(item, ({ contract, path }) => {
|
|
4396
|
+
if (!isContractProcedure(contract)) {
|
|
4397
|
+
return;
|
|
4235
4398
|
}
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
);
|
|
4399
|
+
const internal = contract["~orpc"];
|
|
4400
|
+
if (ignoreUndefinedPathProcedures && internal.route?.path === void 0) {
|
|
4401
|
+
return;
|
|
4240
4402
|
}
|
|
4241
|
-
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
|
|
4246
|
-
|
|
4247
|
-
|
|
4403
|
+
const httpPath = internal.route?.path ? standardizeHTTPPath(internal.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
4404
|
+
const method = internal.route?.method ?? "POST";
|
|
4405
|
+
let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
|
|
4406
|
+
const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
|
|
4407
|
+
const params = (() => {
|
|
4408
|
+
const names = httpPath.match(/\{([^}]+)\}/g);
|
|
4409
|
+
if (!names || !names.length) {
|
|
4410
|
+
return void 0;
|
|
4248
4411
|
}
|
|
4249
|
-
if (
|
|
4412
|
+
if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
|
|
4250
4413
|
throw new Error(
|
|
4251
|
-
`
|
|
4414
|
+
`When path has parameters, input schema must be an object [${path.join(".")}]`
|
|
4252
4415
|
);
|
|
4253
4416
|
}
|
|
4254
|
-
|
|
4255
|
-
|
|
4256
|
-
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
examples: examples?.length ? examples : void 0,
|
|
4261
|
-
...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
|
|
4262
|
-
};
|
|
4263
|
-
inputSchema = {
|
|
4264
|
-
...inputSchema,
|
|
4265
|
-
properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
|
|
4266
|
-
(acc, [key, value]) => {
|
|
4267
|
-
if (key !== name) {
|
|
4268
|
-
acc[key] = value;
|
|
4269
|
-
}
|
|
4270
|
-
return acc;
|
|
4271
|
-
},
|
|
4272
|
-
{}
|
|
4273
|
-
) : void 0,
|
|
4274
|
-
required: inputSchema.required?.filter((v) => v !== name),
|
|
4275
|
-
examples: inputSchema.examples?.map((example) => {
|
|
4276
|
-
if (!isPlainObject(example))
|
|
4277
|
-
return example;
|
|
4278
|
-
return Object.entries(example).reduce(
|
|
4279
|
-
(acc, [key, value]) => {
|
|
4280
|
-
if (key !== name) {
|
|
4281
|
-
acc[key] = value;
|
|
4282
|
-
}
|
|
4283
|
-
return acc;
|
|
4284
|
-
},
|
|
4285
|
-
{}
|
|
4417
|
+
return names.map((raw) => raw.slice(1, -1)).map((name) => {
|
|
4418
|
+
let schema = inputSchema.properties?.[name];
|
|
4419
|
+
const required = inputSchema.required?.includes(name);
|
|
4420
|
+
if (schema === void 0) {
|
|
4421
|
+
throw new Error(
|
|
4422
|
+
`Parameter ${name} is missing in input schema [${path.join(".")}]`
|
|
4286
4423
|
);
|
|
4287
|
-
}
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4292
|
-
|
|
4293
|
-
schema,
|
|
4294
|
-
example: internal.inputExample?.[name]
|
|
4295
|
-
};
|
|
4296
|
-
});
|
|
4297
|
-
})();
|
|
4298
|
-
const query = (() => {
|
|
4299
|
-
if (method !== "GET" || Object.keys(inputSchema).length === 0) {
|
|
4300
|
-
return void 0;
|
|
4301
|
-
}
|
|
4302
|
-
if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
|
|
4303
|
-
throw new Error(
|
|
4304
|
-
`When method is GET, input schema must be an object [${path_.join(".")}]`
|
|
4305
|
-
);
|
|
4306
|
-
}
|
|
4307
|
-
return Object.entries(inputSchema.properties ?? {}).map(
|
|
4308
|
-
([name, schema]) => {
|
|
4424
|
+
}
|
|
4425
|
+
if (!required) {
|
|
4426
|
+
throw new Error(
|
|
4427
|
+
`Parameter ${name} must be required in input schema [${path.join(".")}]`
|
|
4428
|
+
);
|
|
4429
|
+
}
|
|
4309
4430
|
const examples = inputSchema.examples?.filter((example) => {
|
|
4310
4431
|
return isPlainObject(example) && name in example;
|
|
4311
4432
|
}).map((example) => {
|
|
4312
4433
|
return example[name];
|
|
4313
4434
|
});
|
|
4314
|
-
|
|
4435
|
+
schema = {
|
|
4315
4436
|
examples: examples?.length ? examples : void 0,
|
|
4316
4437
|
...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
|
|
4317
4438
|
};
|
|
4439
|
+
inputSchema = {
|
|
4440
|
+
...inputSchema,
|
|
4441
|
+
properties: inputSchema.properties ? Object.entries(inputSchema.properties).reduce(
|
|
4442
|
+
(acc, [key, value]) => {
|
|
4443
|
+
if (key !== name) {
|
|
4444
|
+
acc[key] = value;
|
|
4445
|
+
}
|
|
4446
|
+
return acc;
|
|
4447
|
+
},
|
|
4448
|
+
{}
|
|
4449
|
+
) : void 0,
|
|
4450
|
+
required: inputSchema.required?.filter((v) => v !== name),
|
|
4451
|
+
examples: inputSchema.examples?.map((example) => {
|
|
4452
|
+
if (!isPlainObject(example))
|
|
4453
|
+
return example;
|
|
4454
|
+
return Object.entries(example).reduce(
|
|
4455
|
+
(acc, [key, value]) => {
|
|
4456
|
+
if (key !== name) {
|
|
4457
|
+
acc[key] = value;
|
|
4458
|
+
}
|
|
4459
|
+
return acc;
|
|
4460
|
+
},
|
|
4461
|
+
{}
|
|
4462
|
+
);
|
|
4463
|
+
})
|
|
4464
|
+
};
|
|
4318
4465
|
return {
|
|
4319
4466
|
name,
|
|
4320
|
-
in: "
|
|
4321
|
-
|
|
4322
|
-
|
|
4323
|
-
schema: schema_,
|
|
4467
|
+
in: "path",
|
|
4468
|
+
required: true,
|
|
4469
|
+
schema,
|
|
4324
4470
|
example: internal.inputExample?.[name]
|
|
4325
4471
|
};
|
|
4472
|
+
});
|
|
4473
|
+
})();
|
|
4474
|
+
const query = (() => {
|
|
4475
|
+
if (method !== "GET" || Object.keys(inputSchema).length === 0) {
|
|
4476
|
+
return void 0;
|
|
4326
4477
|
}
|
|
4327
|
-
|
|
4328
|
-
|
|
4329
|
-
|
|
4330
|
-
|
|
4331
|
-
|
|
4332
|
-
return
|
|
4333
|
-
|
|
4334
|
-
|
|
4335
|
-
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4345
|
-
|
|
4346
|
-
|
|
4478
|
+
if (typeof inputSchema !== "object" || inputSchema.type !== "object") {
|
|
4479
|
+
throw new Error(
|
|
4480
|
+
`When method is GET, input schema must be an object [${path.join(".")}]`
|
|
4481
|
+
);
|
|
4482
|
+
}
|
|
4483
|
+
return Object.entries(inputSchema.properties ?? {}).map(
|
|
4484
|
+
([name, schema]) => {
|
|
4485
|
+
const examples = inputSchema.examples?.filter((example) => {
|
|
4486
|
+
return isPlainObject(example) && name in example;
|
|
4487
|
+
}).map((example) => {
|
|
4488
|
+
return example[name];
|
|
4489
|
+
});
|
|
4490
|
+
const schema_ = {
|
|
4491
|
+
examples: examples?.length ? examples : void 0,
|
|
4492
|
+
...schema === true ? {} : schema === false ? UNSUPPORTED_JSON_SCHEMA : schema
|
|
4493
|
+
};
|
|
4494
|
+
return {
|
|
4495
|
+
name,
|
|
4496
|
+
in: "query",
|
|
4497
|
+
style: "deepObject",
|
|
4498
|
+
required: inputSchema?.required?.includes(name) ?? false,
|
|
4499
|
+
schema: schema_,
|
|
4500
|
+
example: internal.inputExample?.[name]
|
|
4501
|
+
};
|
|
4347
4502
|
}
|
|
4348
|
-
|
|
4349
|
-
}
|
|
4350
|
-
const
|
|
4351
|
-
|
|
4352
|
-
|
|
4353
|
-
|
|
4354
|
-
}
|
|
4355
|
-
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4371
|
-
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4503
|
+
);
|
|
4504
|
+
})();
|
|
4505
|
+
const parameters = [...params ?? [], ...query ?? []];
|
|
4506
|
+
const requestBody = (() => {
|
|
4507
|
+
if (method === "GET") {
|
|
4508
|
+
return void 0;
|
|
4509
|
+
}
|
|
4510
|
+
const { schema, matches } = extractJSONSchema(inputSchema, isFileSchema);
|
|
4511
|
+
const files = matches;
|
|
4512
|
+
const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
|
|
4513
|
+
if (files.length) {
|
|
4514
|
+
parameters.push({
|
|
4515
|
+
name: "content-disposition",
|
|
4516
|
+
in: "header",
|
|
4517
|
+
required: schema === void 0,
|
|
4518
|
+
schema: {
|
|
4519
|
+
type: "string",
|
|
4520
|
+
pattern: "filename",
|
|
4521
|
+
example: 'filename="file.png"',
|
|
4522
|
+
description: "To define the file name. Required when the request body is a file."
|
|
4523
|
+
}
|
|
4524
|
+
});
|
|
4525
|
+
}
|
|
4526
|
+
const content = {};
|
|
4527
|
+
for (const file of files) {
|
|
4528
|
+
content[file.contentMediaType] = {
|
|
4529
|
+
schema: file
|
|
4530
|
+
};
|
|
4531
|
+
}
|
|
4532
|
+
if (schema !== void 0) {
|
|
4533
|
+
content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
|
|
4534
|
+
schema,
|
|
4535
|
+
example: internal.inputExample
|
|
4536
|
+
};
|
|
4537
|
+
}
|
|
4538
|
+
return {
|
|
4539
|
+
required: Boolean(
|
|
4540
|
+
internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
|
|
4541
|
+
),
|
|
4542
|
+
content
|
|
4375
4543
|
};
|
|
4376
|
-
}
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
4544
|
+
})();
|
|
4545
|
+
const successResponse = (() => {
|
|
4546
|
+
const { schema, matches } = extractJSONSchema(outputSchema, isFileSchema);
|
|
4547
|
+
const files = matches;
|
|
4548
|
+
const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
|
|
4549
|
+
const content = {};
|
|
4550
|
+
for (const file of files) {
|
|
4551
|
+
content[file.contentMediaType] = {
|
|
4552
|
+
schema: file
|
|
4553
|
+
};
|
|
4554
|
+
}
|
|
4555
|
+
if (schema !== void 0) {
|
|
4556
|
+
content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
|
|
4557
|
+
schema,
|
|
4558
|
+
example: internal.outputExample
|
|
4559
|
+
};
|
|
4560
|
+
}
|
|
4561
|
+
return {
|
|
4562
|
+
description: "OK",
|
|
4563
|
+
content
|
|
4381
4564
|
};
|
|
4565
|
+
})();
|
|
4566
|
+
if (throwOnMissingTagDefinition && internal.route?.tags) {
|
|
4567
|
+
const missingTag = internal.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
4568
|
+
if (missingTag !== void 0) {
|
|
4569
|
+
throw new Error(
|
|
4570
|
+
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
|
|
4571
|
+
);
|
|
4572
|
+
}
|
|
4382
4573
|
}
|
|
4383
|
-
|
|
4384
|
-
|
|
4385
|
-
|
|
4574
|
+
const operation = {
|
|
4575
|
+
summary: internal.route?.summary,
|
|
4576
|
+
description: internal.route?.description,
|
|
4577
|
+
deprecated: internal.route?.deprecated,
|
|
4578
|
+
tags: internal.route?.tags ? [...internal.route.tags] : void 0,
|
|
4579
|
+
operationId: path.join("."),
|
|
4580
|
+
parameters: parameters.length ? parameters : void 0,
|
|
4581
|
+
requestBody,
|
|
4582
|
+
responses: {
|
|
4583
|
+
200: successResponse
|
|
4584
|
+
}
|
|
4386
4585
|
};
|
|
4387
|
-
|
|
4388
|
-
|
|
4389
|
-
|
|
4390
|
-
if (missingTag !== void 0) {
|
|
4391
|
-
throw new Error(
|
|
4392
|
-
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path_.join(".")}]`
|
|
4393
|
-
);
|
|
4394
|
-
}
|
|
4395
|
-
}
|
|
4396
|
-
const operation = {
|
|
4397
|
-
summary: internal.summary,
|
|
4398
|
-
description: internal.description,
|
|
4399
|
-
deprecated: internal.deprecated,
|
|
4400
|
-
tags: internal.tags,
|
|
4401
|
-
operationId: path_.join("."),
|
|
4402
|
-
parameters: parameters.length ? parameters : void 0,
|
|
4403
|
-
requestBody,
|
|
4404
|
-
responses: {
|
|
4405
|
-
200: successResponse
|
|
4406
|
-
}
|
|
4407
|
-
};
|
|
4408
|
-
builder.addPath(path, {
|
|
4409
|
-
[method.toLocaleLowerCase()]: operation
|
|
4586
|
+
builder.addPath(httpPath, {
|
|
4587
|
+
[method.toLocaleLowerCase()]: operation
|
|
4588
|
+
});
|
|
4410
4589
|
});
|
|
4411
|
-
|
|
4412
|
-
|
|
4590
|
+
for (const lazy of lazies) {
|
|
4591
|
+
const { default: router } = await unlazy(lazy.router);
|
|
4592
|
+
pending.push({
|
|
4593
|
+
path: lazy.path,
|
|
4594
|
+
router
|
|
4595
|
+
});
|
|
4596
|
+
}
|
|
4597
|
+
}
|
|
4598
|
+
return payloadCodec.serialize(builder.getSpec());
|
|
4413
4599
|
}
|
|
4414
4600
|
function isFileSchema(schema) {
|
|
4415
4601
|
if (typeof schema !== "object" || schema === null)
|