@orpc/openapi 0.14.0 → 0.16.0
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/fetch.js +10 -8
- package/dist/index.js +216 -73
- package/dist/src/zod-to-json-schema.d.ts +2 -2
- package/package.json +8 -7
package/dist/fetch.js
CHANGED
|
@@ -45,7 +45,7 @@ function createOpenAPIHandler(createHonoRouter) {
|
|
|
45
45
|
procedure,
|
|
46
46
|
path
|
|
47
47
|
});
|
|
48
|
-
const output = await caller(mergedInput);
|
|
48
|
+
const output = await caller(mergedInput, { signal: options.signal });
|
|
49
49
|
const { body, headers } = serializer.serialize(output);
|
|
50
50
|
return new Response(body, {
|
|
51
51
|
status: 200,
|
|
@@ -58,7 +58,9 @@ function createOpenAPIHandler(createHonoRouter) {
|
|
|
58
58
|
hooks: options,
|
|
59
59
|
execute: handler,
|
|
60
60
|
input: options.request,
|
|
61
|
-
meta:
|
|
61
|
+
meta: {
|
|
62
|
+
signal: options.signal
|
|
63
|
+
}
|
|
62
64
|
});
|
|
63
65
|
} catch (e) {
|
|
64
66
|
const error = toORPCError(e);
|
|
@@ -185,13 +187,13 @@ function openAPIPathToRouterPath(path) {
|
|
|
185
187
|
return standardizeHTTPPath(path).replace(/\{([^}]+)\}/g, ":$1");
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
190
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router.js
|
|
189
191
|
var METHOD_NAME_ALL = "ALL";
|
|
190
192
|
var MESSAGE_MATCHER_IS_ALREADY_BUILT = "Can not add a route since the matcher is already built.";
|
|
191
193
|
var UnsupportedPathError = class extends Error {
|
|
192
194
|
};
|
|
193
195
|
|
|
194
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
196
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/utils/url.js
|
|
195
197
|
var checkOptionalParameter = (path) => {
|
|
196
198
|
if (!path.match(/\:.+\?$/)) {
|
|
197
199
|
return null;
|
|
@@ -220,7 +222,7 @@ var checkOptionalParameter = (path) => {
|
|
|
220
222
|
return results.filter((v, i, a) => a.indexOf(v) === i);
|
|
221
223
|
};
|
|
222
224
|
|
|
223
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
225
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/node.js
|
|
224
226
|
var LABEL_REG_EXP_STR = "[^/]+";
|
|
225
227
|
var ONLY_WILDCARD_REG_EXP_STR = ".*";
|
|
226
228
|
var TAIL_WILDCARD_REG_EXP_STR = "(?:|/.*)";
|
|
@@ -325,7 +327,7 @@ var Node = class {
|
|
|
325
327
|
}
|
|
326
328
|
};
|
|
327
329
|
|
|
328
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
330
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/trie.js
|
|
329
331
|
var Trie = class {
|
|
330
332
|
#context = { varIndex: 0 };
|
|
331
333
|
#root = new Node();
|
|
@@ -381,7 +383,7 @@ var Trie = class {
|
|
|
381
383
|
}
|
|
382
384
|
};
|
|
383
385
|
|
|
384
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
386
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/reg-exp-router/router.js
|
|
385
387
|
var emptyParam = [];
|
|
386
388
|
var nullMatcher = [/^$/, [], /* @__PURE__ */ Object.create(null)];
|
|
387
389
|
var wildcardRegExpCache = /* @__PURE__ */ Object.create(null);
|
|
@@ -582,7 +584,7 @@ function createOpenAPIServerHandler() {
|
|
|
582
584
|
return createOpenAPIHandler(() => new RegExpRouter());
|
|
583
585
|
}
|
|
584
586
|
|
|
585
|
-
// ../../node_modules/.pnpm/hono@4.6.
|
|
587
|
+
// ../../node_modules/.pnpm/hono@4.6.13/node_modules/hono/dist/router/linear-router/router.js
|
|
586
588
|
var emptyParams = /* @__PURE__ */ Object.create(null);
|
|
587
589
|
var splitPathRe = /\/(:\w+(?:{(?:(?:{[\d,]+})|[^}])+})?)|\/[^\/\?]+|(\?)/g;
|
|
588
590
|
var splitByStarRe = /\*/;
|
package/dist/index.js
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
Format
|
|
23
23
|
} from "json-schema-typed/draft-2020-12";
|
|
24
24
|
|
|
25
|
-
// ../../node_modules/.pnpm/zod@3.
|
|
25
|
+
// ../../node_modules/.pnpm/zod@3.24.1/node_modules/zod/lib/index.mjs
|
|
26
26
|
var util;
|
|
27
27
|
(function(util2) {
|
|
28
28
|
util2.assertEqual = (val) => val;
|
|
@@ -173,6 +173,9 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
173
173
|
"not_finite"
|
|
174
174
|
]);
|
|
175
175
|
var ZodError = class _ZodError extends Error {
|
|
176
|
+
get errors() {
|
|
177
|
+
return this.issues;
|
|
178
|
+
}
|
|
176
179
|
constructor(issues) {
|
|
177
180
|
super();
|
|
178
181
|
this.issues = [];
|
|
@@ -191,9 +194,6 @@ var ZodError = class _ZodError extends Error {
|
|
|
191
194
|
this.name = "ZodError";
|
|
192
195
|
this.issues = issues;
|
|
193
196
|
}
|
|
194
|
-
get errors() {
|
|
195
|
-
return this.issues;
|
|
196
|
-
}
|
|
197
197
|
format(_mapper) {
|
|
198
198
|
const mapper = _mapper || function(issue) {
|
|
199
199
|
return issue.message;
|
|
@@ -400,8 +400,11 @@ function addIssueToContext(ctx, issueData) {
|
|
|
400
400
|
path: ctx.path,
|
|
401
401
|
errorMaps: [
|
|
402
402
|
ctx.common.contextualErrorMap,
|
|
403
|
+
// contextual error map is first priority
|
|
403
404
|
ctx.schemaErrorMap,
|
|
405
|
+
// then schema-bound map if available
|
|
404
406
|
overrideMap,
|
|
407
|
+
// then global override map
|
|
405
408
|
overrideMap === errorMap ? void 0 : errorMap
|
|
406
409
|
// then global default map
|
|
407
410
|
].filter((x) => !!x)
|
|
@@ -552,34 +555,6 @@ function processCreateParams(params) {
|
|
|
552
555
|
return { errorMap: customMap, description };
|
|
553
556
|
}
|
|
554
557
|
var ZodType = class {
|
|
555
|
-
constructor(def) {
|
|
556
|
-
this.spa = this.safeParseAsync;
|
|
557
|
-
this._def = def;
|
|
558
|
-
this.parse = this.parse.bind(this);
|
|
559
|
-
this.safeParse = this.safeParse.bind(this);
|
|
560
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
561
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
562
|
-
this.spa = this.spa.bind(this);
|
|
563
|
-
this.refine = this.refine.bind(this);
|
|
564
|
-
this.refinement = this.refinement.bind(this);
|
|
565
|
-
this.superRefine = this.superRefine.bind(this);
|
|
566
|
-
this.optional = this.optional.bind(this);
|
|
567
|
-
this.nullable = this.nullable.bind(this);
|
|
568
|
-
this.nullish = this.nullish.bind(this);
|
|
569
|
-
this.array = this.array.bind(this);
|
|
570
|
-
this.promise = this.promise.bind(this);
|
|
571
|
-
this.or = this.or.bind(this);
|
|
572
|
-
this.and = this.and.bind(this);
|
|
573
|
-
this.transform = this.transform.bind(this);
|
|
574
|
-
this.brand = this.brand.bind(this);
|
|
575
|
-
this.default = this.default.bind(this);
|
|
576
|
-
this.catch = this.catch.bind(this);
|
|
577
|
-
this.describe = this.describe.bind(this);
|
|
578
|
-
this.pipe = this.pipe.bind(this);
|
|
579
|
-
this.readonly = this.readonly.bind(this);
|
|
580
|
-
this.isNullable = this.isNullable.bind(this);
|
|
581
|
-
this.isOptional = this.isOptional.bind(this);
|
|
582
|
-
}
|
|
583
558
|
get description() {
|
|
584
559
|
return this._def.description;
|
|
585
560
|
}
|
|
@@ -643,6 +618,43 @@ var ZodType = class {
|
|
|
643
618
|
const result = this._parseSync({ data, path: ctx.path, parent: ctx });
|
|
644
619
|
return handleResult(ctx, result);
|
|
645
620
|
}
|
|
621
|
+
"~validate"(data) {
|
|
622
|
+
var _a, _b;
|
|
623
|
+
const ctx = {
|
|
624
|
+
common: {
|
|
625
|
+
issues: [],
|
|
626
|
+
async: !!this["~standard"].async
|
|
627
|
+
},
|
|
628
|
+
path: [],
|
|
629
|
+
schemaErrorMap: this._def.errorMap,
|
|
630
|
+
parent: null,
|
|
631
|
+
data,
|
|
632
|
+
parsedType: getParsedType(data)
|
|
633
|
+
};
|
|
634
|
+
if (!this["~standard"].async) {
|
|
635
|
+
try {
|
|
636
|
+
const result = this._parseSync({ data, path: [], parent: ctx });
|
|
637
|
+
return isValid(result) ? {
|
|
638
|
+
value: result.value
|
|
639
|
+
} : {
|
|
640
|
+
issues: ctx.common.issues
|
|
641
|
+
};
|
|
642
|
+
} catch (err) {
|
|
643
|
+
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")) {
|
|
644
|
+
this["~standard"].async = true;
|
|
645
|
+
}
|
|
646
|
+
ctx.common = {
|
|
647
|
+
issues: [],
|
|
648
|
+
async: true
|
|
649
|
+
};
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
return this._parseAsync({ data, path: [], parent: ctx }).then((result) => isValid(result) ? {
|
|
653
|
+
value: result.value
|
|
654
|
+
} : {
|
|
655
|
+
issues: ctx.common.issues
|
|
656
|
+
});
|
|
657
|
+
}
|
|
646
658
|
async parseAsync(data, params) {
|
|
647
659
|
const result = await this.safeParseAsync(data, params);
|
|
648
660
|
if (result.success)
|
|
@@ -720,6 +732,39 @@ var ZodType = class {
|
|
|
720
732
|
superRefine(refinement) {
|
|
721
733
|
return this._refinement(refinement);
|
|
722
734
|
}
|
|
735
|
+
constructor(def) {
|
|
736
|
+
this.spa = this.safeParseAsync;
|
|
737
|
+
this._def = def;
|
|
738
|
+
this.parse = this.parse.bind(this);
|
|
739
|
+
this.safeParse = this.safeParse.bind(this);
|
|
740
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
741
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
742
|
+
this.spa = this.spa.bind(this);
|
|
743
|
+
this.refine = this.refine.bind(this);
|
|
744
|
+
this.refinement = this.refinement.bind(this);
|
|
745
|
+
this.superRefine = this.superRefine.bind(this);
|
|
746
|
+
this.optional = this.optional.bind(this);
|
|
747
|
+
this.nullable = this.nullable.bind(this);
|
|
748
|
+
this.nullish = this.nullish.bind(this);
|
|
749
|
+
this.array = this.array.bind(this);
|
|
750
|
+
this.promise = this.promise.bind(this);
|
|
751
|
+
this.or = this.or.bind(this);
|
|
752
|
+
this.and = this.and.bind(this);
|
|
753
|
+
this.transform = this.transform.bind(this);
|
|
754
|
+
this.brand = this.brand.bind(this);
|
|
755
|
+
this.default = this.default.bind(this);
|
|
756
|
+
this.catch = this.catch.bind(this);
|
|
757
|
+
this.describe = this.describe.bind(this);
|
|
758
|
+
this.pipe = this.pipe.bind(this);
|
|
759
|
+
this.readonly = this.readonly.bind(this);
|
|
760
|
+
this.isNullable = this.isNullable.bind(this);
|
|
761
|
+
this.isOptional = this.isOptional.bind(this);
|
|
762
|
+
this["~standard"] = {
|
|
763
|
+
version: 1,
|
|
764
|
+
vendor: "zod",
|
|
765
|
+
validate: (data) => this["~validate"](data)
|
|
766
|
+
};
|
|
767
|
+
}
|
|
723
768
|
optional() {
|
|
724
769
|
return ZodOptional.create(this, this._def);
|
|
725
770
|
}
|
|
@@ -730,7 +775,7 @@ var ZodType = class {
|
|
|
730
775
|
return this.nullable().optional();
|
|
731
776
|
}
|
|
732
777
|
array() {
|
|
733
|
-
return ZodArray.create(this
|
|
778
|
+
return ZodArray.create(this);
|
|
734
779
|
}
|
|
735
780
|
promise() {
|
|
736
781
|
return ZodPromise.create(this, this._def);
|
|
@@ -796,16 +841,20 @@ var ZodType = class {
|
|
|
796
841
|
};
|
|
797
842
|
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
798
843
|
var cuid2Regex = /^[0-9a-z]+$/;
|
|
799
|
-
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}
|
|
844
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
800
845
|
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;
|
|
801
846
|
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
847
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
802
848
|
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)?)??$/;
|
|
803
849
|
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
804
850
|
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
805
851
|
var emojiRegex;
|
|
806
852
|
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])$/;
|
|
807
|
-
var
|
|
853
|
+
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])$/;
|
|
854
|
+
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]))$/;
|
|
855
|
+
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])$/;
|
|
808
856
|
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
857
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
809
858
|
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])))`;
|
|
810
859
|
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
811
860
|
function timeRegexSource(args) {
|
|
@@ -838,6 +887,33 @@ function isValidIP(ip, version) {
|
|
|
838
887
|
}
|
|
839
888
|
return false;
|
|
840
889
|
}
|
|
890
|
+
function isValidJWT(jwt, alg) {
|
|
891
|
+
if (!jwtRegex.test(jwt))
|
|
892
|
+
return false;
|
|
893
|
+
try {
|
|
894
|
+
const [header] = jwt.split(".");
|
|
895
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
896
|
+
const decoded = JSON.parse(atob(base64));
|
|
897
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
898
|
+
return false;
|
|
899
|
+
if (!decoded.typ || !decoded.alg)
|
|
900
|
+
return false;
|
|
901
|
+
if (alg && decoded.alg !== alg)
|
|
902
|
+
return false;
|
|
903
|
+
return true;
|
|
904
|
+
} catch (_a) {
|
|
905
|
+
return false;
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
function isValidCidr(ip, version) {
|
|
909
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
910
|
+
return true;
|
|
911
|
+
}
|
|
912
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
913
|
+
return true;
|
|
914
|
+
}
|
|
915
|
+
return false;
|
|
916
|
+
}
|
|
841
917
|
var ZodString = class _ZodString extends ZodType {
|
|
842
918
|
_parse(input) {
|
|
843
919
|
if (this._def.coerce) {
|
|
@@ -1094,6 +1170,26 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1094
1170
|
});
|
|
1095
1171
|
status.dirty();
|
|
1096
1172
|
}
|
|
1173
|
+
} else if (check.kind === "jwt") {
|
|
1174
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1175
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1176
|
+
addIssueToContext(ctx, {
|
|
1177
|
+
validation: "jwt",
|
|
1178
|
+
code: ZodIssueCode.invalid_string,
|
|
1179
|
+
message: check.message
|
|
1180
|
+
});
|
|
1181
|
+
status.dirty();
|
|
1182
|
+
}
|
|
1183
|
+
} else if (check.kind === "cidr") {
|
|
1184
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1185
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1186
|
+
addIssueToContext(ctx, {
|
|
1187
|
+
validation: "cidr",
|
|
1188
|
+
code: ZodIssueCode.invalid_string,
|
|
1189
|
+
message: check.message
|
|
1190
|
+
});
|
|
1191
|
+
status.dirty();
|
|
1192
|
+
}
|
|
1097
1193
|
} else if (check.kind === "base64") {
|
|
1098
1194
|
if (!base64Regex.test(input.data)) {
|
|
1099
1195
|
ctx = this._getOrReturnCtx(input, ctx);
|
|
@@ -1104,6 +1200,16 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1104
1200
|
});
|
|
1105
1201
|
status.dirty();
|
|
1106
1202
|
}
|
|
1203
|
+
} else if (check.kind === "base64url") {
|
|
1204
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1205
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1206
|
+
addIssueToContext(ctx, {
|
|
1207
|
+
validation: "base64url",
|
|
1208
|
+
code: ZodIssueCode.invalid_string,
|
|
1209
|
+
message: check.message
|
|
1210
|
+
});
|
|
1211
|
+
status.dirty();
|
|
1212
|
+
}
|
|
1107
1213
|
} else {
|
|
1108
1214
|
util.assertNever(check);
|
|
1109
1215
|
}
|
|
@@ -1150,9 +1256,21 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1150
1256
|
base64(message) {
|
|
1151
1257
|
return this._addCheck({ kind: "base64", ...errorUtil.errToObj(message) });
|
|
1152
1258
|
}
|
|
1259
|
+
base64url(message) {
|
|
1260
|
+
return this._addCheck({
|
|
1261
|
+
kind: "base64url",
|
|
1262
|
+
...errorUtil.errToObj(message)
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
jwt(options) {
|
|
1266
|
+
return this._addCheck({ kind: "jwt", ...errorUtil.errToObj(options) });
|
|
1267
|
+
}
|
|
1153
1268
|
ip(options) {
|
|
1154
1269
|
return this._addCheck({ kind: "ip", ...errorUtil.errToObj(options) });
|
|
1155
1270
|
}
|
|
1271
|
+
cidr(options) {
|
|
1272
|
+
return this._addCheck({ kind: "cidr", ...errorUtil.errToObj(options) });
|
|
1273
|
+
}
|
|
1156
1274
|
datetime(options) {
|
|
1157
1275
|
var _a, _b;
|
|
1158
1276
|
if (typeof options === "string") {
|
|
@@ -1243,8 +1361,7 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1243
1361
|
});
|
|
1244
1362
|
}
|
|
1245
1363
|
/**
|
|
1246
|
-
*
|
|
1247
|
-
* @see {@link ZodString.min}
|
|
1364
|
+
* Equivalent to `.min(1)`
|
|
1248
1365
|
*/
|
|
1249
1366
|
nonempty(message) {
|
|
1250
1367
|
return this.min(1, errorUtil.errToObj(message));
|
|
@@ -1306,9 +1423,15 @@ var ZodString = class _ZodString extends ZodType {
|
|
|
1306
1423
|
get isIP() {
|
|
1307
1424
|
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1308
1425
|
}
|
|
1426
|
+
get isCIDR() {
|
|
1427
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1428
|
+
}
|
|
1309
1429
|
get isBase64() {
|
|
1310
1430
|
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1311
1431
|
}
|
|
1432
|
+
get isBase64url() {
|
|
1433
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1434
|
+
}
|
|
1312
1435
|
get minLength() {
|
|
1313
1436
|
let min = null;
|
|
1314
1437
|
for (const ch of this._def.checks) {
|
|
@@ -1586,17 +1709,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1586
1709
|
}
|
|
1587
1710
|
_parse(input) {
|
|
1588
1711
|
if (this._def.coerce) {
|
|
1589
|
-
|
|
1712
|
+
try {
|
|
1713
|
+
input.data = BigInt(input.data);
|
|
1714
|
+
} catch (_a) {
|
|
1715
|
+
return this._getInvalidInput(input);
|
|
1716
|
+
}
|
|
1590
1717
|
}
|
|
1591
1718
|
const parsedType = this._getType(input);
|
|
1592
1719
|
if (parsedType !== ZodParsedType.bigint) {
|
|
1593
|
-
|
|
1594
|
-
addIssueToContext(ctx2, {
|
|
1595
|
-
code: ZodIssueCode.invalid_type,
|
|
1596
|
-
expected: ZodParsedType.bigint,
|
|
1597
|
-
received: ctx2.parsedType
|
|
1598
|
-
});
|
|
1599
|
-
return INVALID;
|
|
1720
|
+
return this._getInvalidInput(input);
|
|
1600
1721
|
}
|
|
1601
1722
|
let ctx = void 0;
|
|
1602
1723
|
const status = new ParseStatus();
|
|
@@ -1643,6 +1764,15 @@ var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
|
1643
1764
|
}
|
|
1644
1765
|
return { status: status.value, value: input.data };
|
|
1645
1766
|
}
|
|
1767
|
+
_getInvalidInput(input) {
|
|
1768
|
+
const ctx = this._getOrReturnCtx(input);
|
|
1769
|
+
addIssueToContext(ctx, {
|
|
1770
|
+
code: ZodIssueCode.invalid_type,
|
|
1771
|
+
expected: ZodParsedType.bigint,
|
|
1772
|
+
received: ctx.parsedType
|
|
1773
|
+
});
|
|
1774
|
+
return INVALID;
|
|
1775
|
+
}
|
|
1646
1776
|
gte(value, message) {
|
|
1647
1777
|
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1648
1778
|
}
|
|
@@ -3813,10 +3943,15 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
3813
3943
|
var UNSUPPORTED_JSON_SCHEMA = { not: {} };
|
|
3814
3944
|
var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
|
|
3815
3945
|
function zodToJsonSchema(schema, options) {
|
|
3946
|
+
if (schema["~standard"].vendor !== "zod") {
|
|
3947
|
+
console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
|
|
3948
|
+
return {};
|
|
3949
|
+
}
|
|
3950
|
+
const schema__ = schema;
|
|
3816
3951
|
if (!options?.isHandledCustomJSONSchema) {
|
|
3817
|
-
const customJSONSchema = getCustomJSONSchema(
|
|
3952
|
+
const customJSONSchema = getCustomJSONSchema(schema__._def, options);
|
|
3818
3953
|
if (customJSONSchema) {
|
|
3819
|
-
const json = zodToJsonSchema(
|
|
3954
|
+
const json = zodToJsonSchema(schema__, {
|
|
3820
3955
|
...options,
|
|
3821
3956
|
isHandledCustomJSONSchema: true
|
|
3822
3957
|
});
|
|
@@ -3827,13 +3962,13 @@ function zodToJsonSchema(schema, options) {
|
|
|
3827
3962
|
}
|
|
3828
3963
|
}
|
|
3829
3964
|
const childOptions = { ...options, isHandledCustomJSONSchema: false };
|
|
3830
|
-
const customType = getCustomZodType(
|
|
3965
|
+
const customType = getCustomZodType(schema__._def);
|
|
3831
3966
|
switch (customType) {
|
|
3832
3967
|
case "Blob": {
|
|
3833
3968
|
return { type: "string", contentMediaType: "*/*" };
|
|
3834
3969
|
}
|
|
3835
3970
|
case "File": {
|
|
3836
|
-
const mimeType = getCustomZodFileMimeType(
|
|
3971
|
+
const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
|
|
3837
3972
|
return { type: "string", contentMediaType: mimeType };
|
|
3838
3973
|
}
|
|
3839
3974
|
case "Invalid Date": {
|
|
@@ -3850,10 +3985,10 @@ function zodToJsonSchema(schema, options) {
|
|
|
3850
3985
|
}
|
|
3851
3986
|
}
|
|
3852
3987
|
const _expectedCustomType = customType;
|
|
3853
|
-
const typeName =
|
|
3988
|
+
const typeName = schema__._def.typeName;
|
|
3854
3989
|
switch (typeName) {
|
|
3855
3990
|
case ZodFirstPartyTypeKind.ZodString: {
|
|
3856
|
-
const schema_ =
|
|
3991
|
+
const schema_ = schema__;
|
|
3857
3992
|
const json = { type: "string" };
|
|
3858
3993
|
for (const check of schema_._def.checks) {
|
|
3859
3994
|
switch (check.kind) {
|
|
@@ -3921,6 +4056,12 @@ function zodToJsonSchema(schema, options) {
|
|
|
3921
4056
|
case "ip":
|
|
3922
4057
|
json.format = Format.IPv4;
|
|
3923
4058
|
break;
|
|
4059
|
+
case "jwt":
|
|
4060
|
+
json.pattern = "^[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]+\\.[A-Za-z0-9-_]*$";
|
|
4061
|
+
break;
|
|
4062
|
+
case "base64url":
|
|
4063
|
+
json.pattern = "^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$";
|
|
4064
|
+
break;
|
|
3924
4065
|
default: {
|
|
3925
4066
|
const _expect = check.kind;
|
|
3926
4067
|
}
|
|
@@ -3929,7 +4070,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
3929
4070
|
return json;
|
|
3930
4071
|
}
|
|
3931
4072
|
case ZodFirstPartyTypeKind.ZodNumber: {
|
|
3932
|
-
const schema_ =
|
|
4073
|
+
const schema_ = schema__;
|
|
3933
4074
|
const json = { type: "number" };
|
|
3934
4075
|
for (const check of schema_._def.checks) {
|
|
3935
4076
|
switch (check.kind) {
|
|
@@ -3974,23 +4115,23 @@ function zodToJsonSchema(schema, options) {
|
|
|
3974
4115
|
return UNDEFINED_JSON_SCHEMA;
|
|
3975
4116
|
}
|
|
3976
4117
|
case ZodFirstPartyTypeKind.ZodLiteral: {
|
|
3977
|
-
const schema_ =
|
|
4118
|
+
const schema_ = schema__;
|
|
3978
4119
|
return { const: schema_._def.value };
|
|
3979
4120
|
}
|
|
3980
4121
|
case ZodFirstPartyTypeKind.ZodEnum: {
|
|
3981
|
-
const schema_ =
|
|
4122
|
+
const schema_ = schema__;
|
|
3982
4123
|
return {
|
|
3983
4124
|
enum: schema_._def.values
|
|
3984
4125
|
};
|
|
3985
4126
|
}
|
|
3986
4127
|
case ZodFirstPartyTypeKind.ZodNativeEnum: {
|
|
3987
|
-
const schema_ =
|
|
4128
|
+
const schema_ = schema__;
|
|
3988
4129
|
return {
|
|
3989
4130
|
enum: Object.values(schema_._def.values)
|
|
3990
4131
|
};
|
|
3991
4132
|
}
|
|
3992
4133
|
case ZodFirstPartyTypeKind.ZodArray: {
|
|
3993
|
-
const schema_ =
|
|
4134
|
+
const schema_ = schema__;
|
|
3994
4135
|
const def = schema_._def;
|
|
3995
4136
|
const json = { type: "array" };
|
|
3996
4137
|
if (def.exactLength) {
|
|
@@ -4006,7 +4147,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4006
4147
|
return json;
|
|
4007
4148
|
}
|
|
4008
4149
|
case ZodFirstPartyTypeKind.ZodTuple: {
|
|
4009
|
-
const schema_ =
|
|
4150
|
+
const schema_ = schema__;
|
|
4010
4151
|
const prefixItems = [];
|
|
4011
4152
|
const json = { type: "array" };
|
|
4012
4153
|
for (const item of schema_._def.items) {
|
|
@@ -4024,7 +4165,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4024
4165
|
return json;
|
|
4025
4166
|
}
|
|
4026
4167
|
case ZodFirstPartyTypeKind.ZodObject: {
|
|
4027
|
-
const schema_ =
|
|
4168
|
+
const schema_ = schema__;
|
|
4028
4169
|
const json = { type: "object" };
|
|
4029
4170
|
const properties = {};
|
|
4030
4171
|
const required = [];
|
|
@@ -4060,7 +4201,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4060
4201
|
return json;
|
|
4061
4202
|
}
|
|
4062
4203
|
case ZodFirstPartyTypeKind.ZodRecord: {
|
|
4063
|
-
const schema_ =
|
|
4204
|
+
const schema_ = schema__;
|
|
4064
4205
|
const json = { type: "object" };
|
|
4065
4206
|
json.additionalProperties = zodToJsonSchema(
|
|
4066
4207
|
schema_._def.valueType,
|
|
@@ -4069,14 +4210,14 @@ function zodToJsonSchema(schema, options) {
|
|
|
4069
4210
|
return json;
|
|
4070
4211
|
}
|
|
4071
4212
|
case ZodFirstPartyTypeKind.ZodSet: {
|
|
4072
|
-
const schema_ =
|
|
4213
|
+
const schema_ = schema__;
|
|
4073
4214
|
return {
|
|
4074
4215
|
type: "array",
|
|
4075
4216
|
items: zodToJsonSchema(schema_._def.valueType, childOptions)
|
|
4076
4217
|
};
|
|
4077
4218
|
}
|
|
4078
4219
|
case ZodFirstPartyTypeKind.ZodMap: {
|
|
4079
|
-
const schema_ =
|
|
4220
|
+
const schema_ = schema__;
|
|
4080
4221
|
return {
|
|
4081
4222
|
type: "array",
|
|
4082
4223
|
items: {
|
|
@@ -4092,7 +4233,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4092
4233
|
}
|
|
4093
4234
|
case ZodFirstPartyTypeKind.ZodUnion:
|
|
4094
4235
|
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
|
|
4095
|
-
const schema_ =
|
|
4236
|
+
const schema_ = schema__;
|
|
4096
4237
|
const anyOf = [];
|
|
4097
4238
|
for (const s of schema_._def.options) {
|
|
4098
4239
|
anyOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4100,7 +4241,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4100
4241
|
return { anyOf };
|
|
4101
4242
|
}
|
|
4102
4243
|
case ZodFirstPartyTypeKind.ZodIntersection: {
|
|
4103
|
-
const schema_ =
|
|
4244
|
+
const schema_ = schema__;
|
|
4104
4245
|
const allOf = [];
|
|
4105
4246
|
for (const s of [schema_._def.left, schema_._def.right]) {
|
|
4106
4247
|
allOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4108,7 +4249,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4108
4249
|
return { allOf };
|
|
4109
4250
|
}
|
|
4110
4251
|
case ZodFirstPartyTypeKind.ZodLazy: {
|
|
4111
|
-
const schema_ =
|
|
4252
|
+
const schema_ = schema__;
|
|
4112
4253
|
const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
|
|
4113
4254
|
const lazyDepth = childOptions?.lazyDepth ?? 0;
|
|
4114
4255
|
if (lazyDepth > maxLazyDepth) {
|
|
@@ -4125,44 +4266,44 @@ function zodToJsonSchema(schema, options) {
|
|
|
4125
4266
|
return {};
|
|
4126
4267
|
}
|
|
4127
4268
|
case ZodFirstPartyTypeKind.ZodOptional: {
|
|
4128
|
-
const schema_ =
|
|
4269
|
+
const schema_ = schema__;
|
|
4129
4270
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4130
4271
|
return {
|
|
4131
4272
|
anyOf: [UNDEFINED_JSON_SCHEMA, inner]
|
|
4132
4273
|
};
|
|
4133
4274
|
}
|
|
4134
4275
|
case ZodFirstPartyTypeKind.ZodReadonly: {
|
|
4135
|
-
const schema_ =
|
|
4276
|
+
const schema_ = schema__;
|
|
4136
4277
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4137
4278
|
}
|
|
4138
4279
|
case ZodFirstPartyTypeKind.ZodDefault: {
|
|
4139
|
-
const schema_ =
|
|
4280
|
+
const schema_ = schema__;
|
|
4140
4281
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4141
4282
|
}
|
|
4142
4283
|
case ZodFirstPartyTypeKind.ZodEffects: {
|
|
4143
|
-
const schema_ =
|
|
4284
|
+
const schema_ = schema__;
|
|
4144
4285
|
if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
|
|
4145
4286
|
return {};
|
|
4146
4287
|
}
|
|
4147
4288
|
return zodToJsonSchema(schema_._def.schema, childOptions);
|
|
4148
4289
|
}
|
|
4149
4290
|
case ZodFirstPartyTypeKind.ZodCatch: {
|
|
4150
|
-
const schema_ =
|
|
4291
|
+
const schema_ = schema__;
|
|
4151
4292
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4152
4293
|
}
|
|
4153
4294
|
case ZodFirstPartyTypeKind.ZodBranded: {
|
|
4154
|
-
const schema_ =
|
|
4295
|
+
const schema_ = schema__;
|
|
4155
4296
|
return zodToJsonSchema(schema_._def.type, childOptions);
|
|
4156
4297
|
}
|
|
4157
4298
|
case ZodFirstPartyTypeKind.ZodPipeline: {
|
|
4158
|
-
const schema_ =
|
|
4299
|
+
const schema_ = schema__;
|
|
4159
4300
|
return zodToJsonSchema(
|
|
4160
4301
|
childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
|
|
4161
4302
|
childOptions
|
|
4162
4303
|
);
|
|
4163
4304
|
}
|
|
4164
4305
|
case ZodFirstPartyTypeKind.ZodNullable: {
|
|
4165
|
-
const schema_ =
|
|
4306
|
+
const schema_ = schema__;
|
|
4166
4307
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4167
4308
|
return {
|
|
4168
4309
|
anyOf: [{ type: "null" }, inner]
|
|
@@ -4371,7 +4512,9 @@ async function generateOpenAPI(opts, options) {
|
|
|
4371
4512
|
};
|
|
4372
4513
|
}
|
|
4373
4514
|
return {
|
|
4374
|
-
required: Boolean(
|
|
4515
|
+
required: Boolean(
|
|
4516
|
+
internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
|
|
4517
|
+
),
|
|
4375
4518
|
content
|
|
4376
4519
|
};
|
|
4377
4520
|
})();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
|
1
2
|
import { type JSONSchema } from 'json-schema-typed/draft-2020-12';
|
|
2
|
-
import { type ZodTypeAny } from 'zod';
|
|
3
3
|
export declare const NON_LOGIC_KEYWORDS: ("$anchor" | "$comment" | "$defs" | "$dynamicAnchor" | "$dynamicRef" | "$id" | "$schema" | "$vocabulary" | "contentEncoding" | "contentMediaType" | "default" | "definitions" | "deprecated" | "description" | "examples" | "format" | "readOnly" | "title" | "writeOnly")[];
|
|
4
4
|
export declare const UNSUPPORTED_JSON_SCHEMA: {
|
|
5
5
|
not: {};
|
|
@@ -35,7 +35,7 @@ export interface ZodToJsonSchemaOptions {
|
|
|
35
35
|
*/
|
|
36
36
|
isHandledCustomJSONSchema?: boolean;
|
|
37
37
|
}
|
|
38
|
-
export declare function zodToJsonSchema(schema:
|
|
38
|
+
export declare function zodToJsonSchema(schema: StandardSchemaV1, options?: ZodToJsonSchemaOptions): Exclude<JSONSchema, boolean>;
|
|
39
39
|
export declare function extractJSONSchema(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): {
|
|
40
40
|
schema: JSONSchema | undefined;
|
|
41
41
|
matches: JSONSchema[];
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orpc/openapi",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.16.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -34,19 +34,20 @@
|
|
|
34
34
|
"dist"
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@standard-schema/spec": "1.0.0-beta.4",
|
|
37
38
|
"escape-string-regexp": "^5.0.0",
|
|
38
39
|
"json-schema-typed": "^8.0.1",
|
|
39
40
|
"openapi3-ts": "^4.4.0",
|
|
40
|
-
"@orpc/contract": "0.
|
|
41
|
-
"@orpc/
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/zod": "0.
|
|
41
|
+
"@orpc/contract": "0.16.0",
|
|
42
|
+
"@orpc/transformer": "0.16.0",
|
|
43
|
+
"@orpc/server": "0.16.0",
|
|
44
|
+
"@orpc/shared": "0.16.0",
|
|
45
|
+
"@orpc/zod": "0.16.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@readme/openapi-parser": "^2.6.0",
|
|
48
49
|
"hono": "^4.6.12",
|
|
49
|
-
"zod": "^3.
|
|
50
|
+
"zod": "^3.24.1"
|
|
50
51
|
},
|
|
51
52
|
"scripts": {
|
|
52
53
|
"build": "tsup --clean --sourcemap --entry.index=src/index.ts --entry.fetch=src/fetch/index.ts --format=esm --onSuccess='tsc -b --noCheck'",
|