@orpc/openapi 0.15.0 → 0.17.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/{chunk-KZIT2WCV.js → chunk-CMRY2Z4J.js} +12 -7
- package/dist/fetch.js +22 -33
- package/dist/index.js +50 -42
- package/dist/src/fetch/base-handler.d.ts +3 -5
- package/dist/src/generator.d.ts +2 -2
- package/dist/src/utils.d.ts +5 -4
- package/dist/src/zod-to-json-schema.d.ts +2 -2
- package/package.json +7 -6
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// src/utils.ts
|
|
2
2
|
import { isContractProcedure } from "@orpc/contract";
|
|
3
|
-
import { isLazy, isProcedure
|
|
3
|
+
import { flatLazy, getRouterContract, isLazy, isProcedure } from "@orpc/server";
|
|
4
4
|
function eachContractProcedureLeaf(options, callback, result = [], isCurrentRouterContract = false) {
|
|
5
|
-
|
|
5
|
+
const hiddenContract = getRouterContract(options.router);
|
|
6
|
+
if (!isCurrentRouterContract && hiddenContract) {
|
|
6
7
|
return eachContractProcedureLeaf(
|
|
7
8
|
{
|
|
8
9
|
path: options.path,
|
|
9
|
-
router:
|
|
10
|
+
router: hiddenContract
|
|
10
11
|
},
|
|
11
12
|
callback,
|
|
12
13
|
result,
|
|
@@ -15,12 +16,12 @@ function eachContractProcedureLeaf(options, callback, result = [], isCurrentRout
|
|
|
15
16
|
}
|
|
16
17
|
if (isLazy(options.router)) {
|
|
17
18
|
result.push({
|
|
18
|
-
lazy: options.router,
|
|
19
|
+
lazy: flatLazy(options.router),
|
|
19
20
|
path: options.path
|
|
20
21
|
});
|
|
21
22
|
} else if (isProcedure(options.router)) {
|
|
22
23
|
callback({
|
|
23
|
-
contract: options.router.
|
|
24
|
+
contract: options.router["~orpc"].contract,
|
|
24
25
|
path: options.path
|
|
25
26
|
});
|
|
26
27
|
} else if (isContractProcedure(options.router)) {
|
|
@@ -42,8 +43,12 @@ function eachContractProcedureLeaf(options, callback, result = [], isCurrentRout
|
|
|
42
43
|
}
|
|
43
44
|
return result;
|
|
44
45
|
}
|
|
46
|
+
function standardizeHTTPPath(path) {
|
|
47
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
48
|
+
}
|
|
45
49
|
|
|
46
50
|
export {
|
|
47
|
-
eachContractProcedureLeaf
|
|
51
|
+
eachContractProcedureLeaf,
|
|
52
|
+
standardizeHTTPPath
|
|
48
53
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
54
|
+
//# sourceMappingURL=chunk-CMRY2Z4J.js.map
|
package/dist/fetch.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
|
-
eachContractProcedureLeaf
|
|
3
|
-
|
|
2
|
+
eachContractProcedureLeaf,
|
|
3
|
+
standardizeHTTPPath
|
|
4
|
+
} from "./chunk-CMRY2Z4J.js";
|
|
4
5
|
|
|
5
6
|
// src/fetch/base-handler.ts
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { executeWithHooks, isPlainObject, mapValues, trim, value } from "@orpc/shared";
|
|
7
|
+
import { createProcedureClient, getLazyRouterPrefix, getRouterChild, isProcedure, LAZY_LOADER_SYMBOL, ORPCError, unlazy } from "@orpc/server";
|
|
8
|
+
import { executeWithHooks, isPlainObject, mapValues, ORPC_PROTOCOL_HEADER, ORPC_PROTOCOL_VALUE, trim, value } from "@orpc/shared";
|
|
9
9
|
import { OpenAPIDeserializer, OpenAPISerializer, zodCoerce } from "@orpc/transformer";
|
|
10
10
|
function createOpenAPIHandler(createHonoRouter) {
|
|
11
11
|
const resolveRouter = createResolveRouter(createHonoRouter);
|
|
12
12
|
return async (options) => {
|
|
13
|
-
if (options.request.headers.get(
|
|
13
|
+
if (options.request.headers.get(ORPC_PROTOCOL_HEADER)?.includes(ORPC_PROTOCOL_VALUE)) {
|
|
14
14
|
return void 0;
|
|
15
15
|
}
|
|
16
16
|
const context = await value(options.context);
|
|
@@ -25,22 +25,15 @@ function createOpenAPIHandler(createHonoRouter) {
|
|
|
25
25
|
if (!match) {
|
|
26
26
|
throw new ORPCError({ code: "NOT_FOUND", message: "Not found" });
|
|
27
27
|
}
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
throw new ORPCError({
|
|
32
|
-
code: "NOT_FOUND",
|
|
33
|
-
message: "Not found"
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
const params = procedure.zz$p.contract.zz$cp.InputSchema ? zodCoerce(
|
|
37
|
-
procedure.zz$p.contract.zz$cp.InputSchema,
|
|
28
|
+
const { path, procedure } = match;
|
|
29
|
+
const params = procedure["~orpc"].contract["~orpc"].InputSchema ? zodCoerce(
|
|
30
|
+
procedure["~orpc"].contract["~orpc"].InputSchema,
|
|
38
31
|
match.params,
|
|
39
32
|
{ bracketNotation: true }
|
|
40
33
|
) : match.params;
|
|
41
34
|
const input = await deserializeInput(options.request, procedure);
|
|
42
35
|
const mergedInput = mergeParamsAndInput(params, input);
|
|
43
|
-
const caller =
|
|
36
|
+
const caller = createProcedureClient({
|
|
44
37
|
context,
|
|
45
38
|
procedure,
|
|
46
39
|
path
|
|
@@ -88,8 +81,8 @@ var pendingCache = /* @__PURE__ */ new Map();
|
|
|
88
81
|
function createResolveRouter(createHonoRouter) {
|
|
89
82
|
const addRoutes = (routing, pending, options) => {
|
|
90
83
|
const lazies = eachContractProcedureLeaf(options, ({ path, contract }) => {
|
|
91
|
-
const method = contract.
|
|
92
|
-
const httpPath = contract.
|
|
84
|
+
const method = contract["~orpc"].route?.method ?? "POST";
|
|
85
|
+
const httpPath = contract["~orpc"].route?.path ? openAPIPathToRouterPath(contract["~orpc"].route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
93
86
|
routing.add(method, httpPath, path);
|
|
94
87
|
});
|
|
95
88
|
pending.ref.push(...lazies);
|
|
@@ -114,7 +107,8 @@ function createResolveRouter(createHonoRouter) {
|
|
|
114
107
|
})();
|
|
115
108
|
const newPending = [];
|
|
116
109
|
for (const item of pending.ref) {
|
|
117
|
-
|
|
110
|
+
const lazyPrefix = getLazyRouterPrefix(item.lazy);
|
|
111
|
+
if (lazyPrefix && !pathname.startsWith(lazyPrefix) && !pathname.startsWith(`/${item.path.map(encodeURIComponent).join("/")}`)) {
|
|
118
112
|
newPending.push(item);
|
|
119
113
|
continue;
|
|
120
114
|
}
|
|
@@ -134,20 +128,16 @@ function createResolveRouter(createHonoRouter) {
|
|
|
134
128
|
match[1],
|
|
135
129
|
(v) => params_[v]
|
|
136
130
|
) : match[1];
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
current = void 0;
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
current = current[segment];
|
|
131
|
+
const { default: maybeProcedure } = await unlazy(getRouterChild(router, ...path));
|
|
132
|
+
if (!isProcedure(maybeProcedure)) {
|
|
133
|
+
return void 0;
|
|
144
134
|
}
|
|
145
|
-
return
|
|
135
|
+
return {
|
|
146
136
|
path,
|
|
147
|
-
procedure:
|
|
137
|
+
procedure: maybeProcedure,
|
|
148
138
|
params: { ...params }
|
|
149
139
|
// params from hono not a normal object, so we need spread here
|
|
150
|
-
}
|
|
140
|
+
};
|
|
151
141
|
};
|
|
152
142
|
}
|
|
153
143
|
function mergeParamsAndInput(coercedParams, input) {
|
|
@@ -164,7 +154,7 @@ function mergeParamsAndInput(coercedParams, input) {
|
|
|
164
154
|
}
|
|
165
155
|
async function deserializeInput(request, procedure) {
|
|
166
156
|
const deserializer = new OpenAPIDeserializer({
|
|
167
|
-
schema: procedure.
|
|
157
|
+
schema: procedure["~orpc"].contract["~orpc"].InputSchema
|
|
168
158
|
});
|
|
169
159
|
try {
|
|
170
160
|
return await deserializer.deserialize(request);
|
|
@@ -702,7 +692,6 @@ export {
|
|
|
702
692
|
createOpenAPIHandler,
|
|
703
693
|
createOpenAPIServerHandler,
|
|
704
694
|
createOpenAPIServerlessHandler,
|
|
705
|
-
createResolveRouter
|
|
706
|
-
openAPIPathToRouterPath
|
|
695
|
+
createResolveRouter
|
|
707
696
|
};
|
|
708
697
|
//# sourceMappingURL=fetch.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
|
-
eachContractProcedureLeaf
|
|
3
|
-
|
|
2
|
+
eachContractProcedureLeaf,
|
|
3
|
+
standardizeHTTPPath
|
|
4
|
+
} from "./chunk-CMRY2Z4J.js";
|
|
4
5
|
|
|
5
6
|
// src/generator.ts
|
|
6
7
|
import { isContractProcedure } from "@orpc/contract";
|
|
7
|
-
import {
|
|
8
|
+
import { unlazy } from "@orpc/server";
|
|
8
9
|
import { findDeepMatches, isPlainObject, omit } from "@orpc/shared";
|
|
9
10
|
import { preSerialize } from "@orpc/transformer";
|
|
10
11
|
import {
|
|
@@ -3943,10 +3944,15 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
3943
3944
|
var UNSUPPORTED_JSON_SCHEMA = { not: {} };
|
|
3944
3945
|
var UNDEFINED_JSON_SCHEMA = { const: "undefined" };
|
|
3945
3946
|
function zodToJsonSchema(schema, options) {
|
|
3947
|
+
if (schema["~standard"].vendor !== "zod") {
|
|
3948
|
+
console.warn(`Generate JSON schema not support ${schema["~standard"].vendor} yet`);
|
|
3949
|
+
return {};
|
|
3950
|
+
}
|
|
3951
|
+
const schema__ = schema;
|
|
3946
3952
|
if (!options?.isHandledCustomJSONSchema) {
|
|
3947
|
-
const customJSONSchema = getCustomJSONSchema(
|
|
3953
|
+
const customJSONSchema = getCustomJSONSchema(schema__._def, options);
|
|
3948
3954
|
if (customJSONSchema) {
|
|
3949
|
-
const json = zodToJsonSchema(
|
|
3955
|
+
const json = zodToJsonSchema(schema__, {
|
|
3950
3956
|
...options,
|
|
3951
3957
|
isHandledCustomJSONSchema: true
|
|
3952
3958
|
});
|
|
@@ -3957,13 +3963,13 @@ function zodToJsonSchema(schema, options) {
|
|
|
3957
3963
|
}
|
|
3958
3964
|
}
|
|
3959
3965
|
const childOptions = { ...options, isHandledCustomJSONSchema: false };
|
|
3960
|
-
const customType = getCustomZodType(
|
|
3966
|
+
const customType = getCustomZodType(schema__._def);
|
|
3961
3967
|
switch (customType) {
|
|
3962
3968
|
case "Blob": {
|
|
3963
3969
|
return { type: "string", contentMediaType: "*/*" };
|
|
3964
3970
|
}
|
|
3965
3971
|
case "File": {
|
|
3966
|
-
const mimeType = getCustomZodFileMimeType(
|
|
3972
|
+
const mimeType = getCustomZodFileMimeType(schema__._def) ?? "*/*";
|
|
3967
3973
|
return { type: "string", contentMediaType: mimeType };
|
|
3968
3974
|
}
|
|
3969
3975
|
case "Invalid Date": {
|
|
@@ -3980,10 +3986,10 @@ function zodToJsonSchema(schema, options) {
|
|
|
3980
3986
|
}
|
|
3981
3987
|
}
|
|
3982
3988
|
const _expectedCustomType = customType;
|
|
3983
|
-
const typeName =
|
|
3989
|
+
const typeName = schema__._def.typeName;
|
|
3984
3990
|
switch (typeName) {
|
|
3985
3991
|
case ZodFirstPartyTypeKind.ZodString: {
|
|
3986
|
-
const schema_ =
|
|
3992
|
+
const schema_ = schema__;
|
|
3987
3993
|
const json = { type: "string" };
|
|
3988
3994
|
for (const check of schema_._def.checks) {
|
|
3989
3995
|
switch (check.kind) {
|
|
@@ -4065,7 +4071,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4065
4071
|
return json;
|
|
4066
4072
|
}
|
|
4067
4073
|
case ZodFirstPartyTypeKind.ZodNumber: {
|
|
4068
|
-
const schema_ =
|
|
4074
|
+
const schema_ = schema__;
|
|
4069
4075
|
const json = { type: "number" };
|
|
4070
4076
|
for (const check of schema_._def.checks) {
|
|
4071
4077
|
switch (check.kind) {
|
|
@@ -4110,23 +4116,23 @@ function zodToJsonSchema(schema, options) {
|
|
|
4110
4116
|
return UNDEFINED_JSON_SCHEMA;
|
|
4111
4117
|
}
|
|
4112
4118
|
case ZodFirstPartyTypeKind.ZodLiteral: {
|
|
4113
|
-
const schema_ =
|
|
4119
|
+
const schema_ = schema__;
|
|
4114
4120
|
return { const: schema_._def.value };
|
|
4115
4121
|
}
|
|
4116
4122
|
case ZodFirstPartyTypeKind.ZodEnum: {
|
|
4117
|
-
const schema_ =
|
|
4123
|
+
const schema_ = schema__;
|
|
4118
4124
|
return {
|
|
4119
4125
|
enum: schema_._def.values
|
|
4120
4126
|
};
|
|
4121
4127
|
}
|
|
4122
4128
|
case ZodFirstPartyTypeKind.ZodNativeEnum: {
|
|
4123
|
-
const schema_ =
|
|
4129
|
+
const schema_ = schema__;
|
|
4124
4130
|
return {
|
|
4125
4131
|
enum: Object.values(schema_._def.values)
|
|
4126
4132
|
};
|
|
4127
4133
|
}
|
|
4128
4134
|
case ZodFirstPartyTypeKind.ZodArray: {
|
|
4129
|
-
const schema_ =
|
|
4135
|
+
const schema_ = schema__;
|
|
4130
4136
|
const def = schema_._def;
|
|
4131
4137
|
const json = { type: "array" };
|
|
4132
4138
|
if (def.exactLength) {
|
|
@@ -4142,7 +4148,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4142
4148
|
return json;
|
|
4143
4149
|
}
|
|
4144
4150
|
case ZodFirstPartyTypeKind.ZodTuple: {
|
|
4145
|
-
const schema_ =
|
|
4151
|
+
const schema_ = schema__;
|
|
4146
4152
|
const prefixItems = [];
|
|
4147
4153
|
const json = { type: "array" };
|
|
4148
4154
|
for (const item of schema_._def.items) {
|
|
@@ -4160,7 +4166,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4160
4166
|
return json;
|
|
4161
4167
|
}
|
|
4162
4168
|
case ZodFirstPartyTypeKind.ZodObject: {
|
|
4163
|
-
const schema_ =
|
|
4169
|
+
const schema_ = schema__;
|
|
4164
4170
|
const json = { type: "object" };
|
|
4165
4171
|
const properties = {};
|
|
4166
4172
|
const required = [];
|
|
@@ -4196,7 +4202,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4196
4202
|
return json;
|
|
4197
4203
|
}
|
|
4198
4204
|
case ZodFirstPartyTypeKind.ZodRecord: {
|
|
4199
|
-
const schema_ =
|
|
4205
|
+
const schema_ = schema__;
|
|
4200
4206
|
const json = { type: "object" };
|
|
4201
4207
|
json.additionalProperties = zodToJsonSchema(
|
|
4202
4208
|
schema_._def.valueType,
|
|
@@ -4205,14 +4211,14 @@ function zodToJsonSchema(schema, options) {
|
|
|
4205
4211
|
return json;
|
|
4206
4212
|
}
|
|
4207
4213
|
case ZodFirstPartyTypeKind.ZodSet: {
|
|
4208
|
-
const schema_ =
|
|
4214
|
+
const schema_ = schema__;
|
|
4209
4215
|
return {
|
|
4210
4216
|
type: "array",
|
|
4211
4217
|
items: zodToJsonSchema(schema_._def.valueType, childOptions)
|
|
4212
4218
|
};
|
|
4213
4219
|
}
|
|
4214
4220
|
case ZodFirstPartyTypeKind.ZodMap: {
|
|
4215
|
-
const schema_ =
|
|
4221
|
+
const schema_ = schema__;
|
|
4216
4222
|
return {
|
|
4217
4223
|
type: "array",
|
|
4218
4224
|
items: {
|
|
@@ -4228,7 +4234,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4228
4234
|
}
|
|
4229
4235
|
case ZodFirstPartyTypeKind.ZodUnion:
|
|
4230
4236
|
case ZodFirstPartyTypeKind.ZodDiscriminatedUnion: {
|
|
4231
|
-
const schema_ =
|
|
4237
|
+
const schema_ = schema__;
|
|
4232
4238
|
const anyOf = [];
|
|
4233
4239
|
for (const s of schema_._def.options) {
|
|
4234
4240
|
anyOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4236,7 +4242,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4236
4242
|
return { anyOf };
|
|
4237
4243
|
}
|
|
4238
4244
|
case ZodFirstPartyTypeKind.ZodIntersection: {
|
|
4239
|
-
const schema_ =
|
|
4245
|
+
const schema_ = schema__;
|
|
4240
4246
|
const allOf = [];
|
|
4241
4247
|
for (const s of [schema_._def.left, schema_._def.right]) {
|
|
4242
4248
|
allOf.push(zodToJsonSchema(s, childOptions));
|
|
@@ -4244,7 +4250,7 @@ function zodToJsonSchema(schema, options) {
|
|
|
4244
4250
|
return { allOf };
|
|
4245
4251
|
}
|
|
4246
4252
|
case ZodFirstPartyTypeKind.ZodLazy: {
|
|
4247
|
-
const schema_ =
|
|
4253
|
+
const schema_ = schema__;
|
|
4248
4254
|
const maxLazyDepth = childOptions?.maxLazyDepth ?? 5;
|
|
4249
4255
|
const lazyDepth = childOptions?.lazyDepth ?? 0;
|
|
4250
4256
|
if (lazyDepth > maxLazyDepth) {
|
|
@@ -4261,44 +4267,44 @@ function zodToJsonSchema(schema, options) {
|
|
|
4261
4267
|
return {};
|
|
4262
4268
|
}
|
|
4263
4269
|
case ZodFirstPartyTypeKind.ZodOptional: {
|
|
4264
|
-
const schema_ =
|
|
4270
|
+
const schema_ = schema__;
|
|
4265
4271
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4266
4272
|
return {
|
|
4267
4273
|
anyOf: [UNDEFINED_JSON_SCHEMA, inner]
|
|
4268
4274
|
};
|
|
4269
4275
|
}
|
|
4270
4276
|
case ZodFirstPartyTypeKind.ZodReadonly: {
|
|
4271
|
-
const schema_ =
|
|
4277
|
+
const schema_ = schema__;
|
|
4272
4278
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4273
4279
|
}
|
|
4274
4280
|
case ZodFirstPartyTypeKind.ZodDefault: {
|
|
4275
|
-
const schema_ =
|
|
4281
|
+
const schema_ = schema__;
|
|
4276
4282
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4277
4283
|
}
|
|
4278
4284
|
case ZodFirstPartyTypeKind.ZodEffects: {
|
|
4279
|
-
const schema_ =
|
|
4285
|
+
const schema_ = schema__;
|
|
4280
4286
|
if (schema_._def.effect.type === "transform" && childOptions?.mode === "output") {
|
|
4281
4287
|
return {};
|
|
4282
4288
|
}
|
|
4283
4289
|
return zodToJsonSchema(schema_._def.schema, childOptions);
|
|
4284
4290
|
}
|
|
4285
4291
|
case ZodFirstPartyTypeKind.ZodCatch: {
|
|
4286
|
-
const schema_ =
|
|
4292
|
+
const schema_ = schema__;
|
|
4287
4293
|
return zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4288
4294
|
}
|
|
4289
4295
|
case ZodFirstPartyTypeKind.ZodBranded: {
|
|
4290
|
-
const schema_ =
|
|
4296
|
+
const schema_ = schema__;
|
|
4291
4297
|
return zodToJsonSchema(schema_._def.type, childOptions);
|
|
4292
4298
|
}
|
|
4293
4299
|
case ZodFirstPartyTypeKind.ZodPipeline: {
|
|
4294
|
-
const schema_ =
|
|
4300
|
+
const schema_ = schema__;
|
|
4295
4301
|
return zodToJsonSchema(
|
|
4296
4302
|
childOptions?.mode === "output" ? schema_._def.out : schema_._def.in,
|
|
4297
4303
|
childOptions
|
|
4298
4304
|
);
|
|
4299
4305
|
}
|
|
4300
4306
|
case ZodFirstPartyTypeKind.ZodNullable: {
|
|
4301
|
-
const schema_ =
|
|
4307
|
+
const schema_ = schema__;
|
|
4302
4308
|
const inner = zodToJsonSchema(schema_._def.innerType, childOptions);
|
|
4303
4309
|
return {
|
|
4304
4310
|
anyOf: [{ type: "null" }, inner]
|
|
@@ -4367,12 +4373,12 @@ async function generateOpenAPI(opts, options) {
|
|
|
4367
4373
|
if (!isContractProcedure(contract)) {
|
|
4368
4374
|
return;
|
|
4369
4375
|
}
|
|
4370
|
-
const internal = contract
|
|
4371
|
-
if (ignoreUndefinedPathProcedures && internal.path === void 0) {
|
|
4376
|
+
const internal = contract["~orpc"];
|
|
4377
|
+
if (ignoreUndefinedPathProcedures && internal.route?.path === void 0) {
|
|
4372
4378
|
return;
|
|
4373
4379
|
}
|
|
4374
|
-
const httpPath = internal.path
|
|
4375
|
-
const method = internal.method ?? "POST";
|
|
4380
|
+
const httpPath = internal.route?.path ? standardizeHTTPPath(internal.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
4381
|
+
const method = internal.route?.method ?? "POST";
|
|
4376
4382
|
let inputSchema = internal.InputSchema ? zodToJsonSchema(internal.InputSchema, { mode: "input" }) : {};
|
|
4377
4383
|
const outputSchema = internal.OutputSchema ? zodToJsonSchema(internal.OutputSchema, { mode: "output" }) : {};
|
|
4378
4384
|
const params = (() => {
|
|
@@ -4507,7 +4513,9 @@ async function generateOpenAPI(opts, options) {
|
|
|
4507
4513
|
};
|
|
4508
4514
|
}
|
|
4509
4515
|
return {
|
|
4510
|
-
required: Boolean(
|
|
4516
|
+
required: Boolean(
|
|
4517
|
+
internal.InputSchema && "isOptional" in internal.InputSchema && typeof internal.InputSchema.isOptional === "function" ? internal.InputSchema.isOptional() : false
|
|
4518
|
+
),
|
|
4511
4519
|
content
|
|
4512
4520
|
};
|
|
4513
4521
|
})();
|
|
@@ -4532,8 +4540,8 @@ async function generateOpenAPI(opts, options) {
|
|
|
4532
4540
|
content
|
|
4533
4541
|
};
|
|
4534
4542
|
})();
|
|
4535
|
-
if (throwOnMissingTagDefinition && internal.tags) {
|
|
4536
|
-
const missingTag = internal.tags.find((tag) => !rootTags.includes(tag));
|
|
4543
|
+
if (throwOnMissingTagDefinition && internal.route?.tags) {
|
|
4544
|
+
const missingTag = internal.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
4537
4545
|
if (missingTag !== void 0) {
|
|
4538
4546
|
throw new Error(
|
|
4539
4547
|
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object. [${path.join(".")}]`
|
|
@@ -4541,10 +4549,10 @@ async function generateOpenAPI(opts, options) {
|
|
|
4541
4549
|
}
|
|
4542
4550
|
}
|
|
4543
4551
|
const operation = {
|
|
4544
|
-
summary: internal.summary,
|
|
4545
|
-
description: internal.description,
|
|
4546
|
-
deprecated: internal.deprecated,
|
|
4547
|
-
tags: internal.tags,
|
|
4552
|
+
summary: internal.route?.summary,
|
|
4553
|
+
description: internal.route?.description,
|
|
4554
|
+
deprecated: internal.route?.deprecated,
|
|
4555
|
+
tags: internal.route?.tags ? [...internal.route.tags] : void 0,
|
|
4548
4556
|
operationId: path.join("."),
|
|
4549
4557
|
parameters: parameters.length ? parameters : void 0,
|
|
4550
4558
|
requestBody,
|
|
@@ -4557,7 +4565,7 @@ async function generateOpenAPI(opts, options) {
|
|
|
4557
4565
|
});
|
|
4558
4566
|
});
|
|
4559
4567
|
for (const lazy of lazies) {
|
|
4560
|
-
const router =
|
|
4568
|
+
const { default: router } = await unlazy(lazy.lazy);
|
|
4561
4569
|
pending.push({
|
|
4562
4570
|
path: lazy.path,
|
|
4563
4571
|
router
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ANY_LAZY_PROCEDURE, ANY_PROCEDURE, Router } from '@orpc/server';
|
|
1
|
+
import type { ANY_PROCEDURE, ANY_ROUTER } from '@orpc/server';
|
|
3
2
|
import type { FetchHandler } from '@orpc/server/fetch';
|
|
4
3
|
import type { Router as HonoRouter } from 'hono/router';
|
|
5
|
-
export type ResolveRouter = (router:
|
|
4
|
+
export type ResolveRouter = (router: ANY_ROUTER, method: string, pathname: string) => Promise<{
|
|
6
5
|
path: string[];
|
|
7
|
-
procedure: ANY_PROCEDURE
|
|
6
|
+
procedure: ANY_PROCEDURE;
|
|
8
7
|
params: Record<string, string>;
|
|
9
8
|
} | undefined>;
|
|
10
9
|
type Routing = HonoRouter<string[]>;
|
|
11
10
|
export declare function createOpenAPIHandler(createHonoRouter: () => Routing): FetchHandler;
|
|
12
11
|
export declare function createResolveRouter(createHonoRouter: () => Routing): ResolveRouter;
|
|
13
|
-
export declare function openAPIPathToRouterPath(path: HTTPPath): string;
|
|
14
12
|
export {};
|
|
15
13
|
//# sourceMappingURL=base-handler.d.ts.map
|
package/dist/src/generator.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ContractRouter } from '@orpc/contract';
|
|
2
|
-
import { type
|
|
2
|
+
import { type ANY_ROUTER } from '@orpc/server';
|
|
3
3
|
import { type OpenAPIObject } from 'openapi3-ts/oas31';
|
|
4
4
|
export interface GenerateOpenAPIOptions {
|
|
5
5
|
/**
|
|
@@ -19,6 +19,6 @@ export interface GenerateOpenAPIOptions {
|
|
|
19
19
|
ignoreUndefinedPathProcedures?: boolean;
|
|
20
20
|
}
|
|
21
21
|
export declare function generateOpenAPI(opts: {
|
|
22
|
-
router: ContractRouter |
|
|
22
|
+
router: ContractRouter | ANY_ROUTER;
|
|
23
23
|
} & Omit<OpenAPIObject, 'openapi'>, options?: GenerateOpenAPIOptions): Promise<OpenAPIObject>;
|
|
24
24
|
//# sourceMappingURL=generator.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { ContractRouter, HTTPPath, WELL_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
|
+
import type { ANY_PROCEDURE, ANY_ROUTER, Lazy } from '@orpc/server';
|
|
3
3
|
export interface EachLeafOptions {
|
|
4
|
-
router:
|
|
4
|
+
router: ContractRouter | ANY_ROUTER;
|
|
5
5
|
path: string[];
|
|
6
6
|
}
|
|
7
7
|
export interface EachLeafCallbackOptions {
|
|
@@ -9,8 +9,9 @@ export interface EachLeafCallbackOptions {
|
|
|
9
9
|
path: string[];
|
|
10
10
|
}
|
|
11
11
|
export interface EachContractLeafResultItem {
|
|
12
|
-
lazy:
|
|
12
|
+
lazy: Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER>>;
|
|
13
13
|
path: string[];
|
|
14
14
|
}
|
|
15
15
|
export declare function eachContractProcedureLeaf(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
|
|
16
|
+
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
16
17
|
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -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.17.0",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -34,14 +34,15 @@
|
|
|
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/
|
|
41
|
-
"@orpc/
|
|
42
|
-
"@orpc/
|
|
43
|
-
"@orpc/
|
|
44
|
-
"@orpc/
|
|
41
|
+
"@orpc/shared": "0.17.0",
|
|
42
|
+
"@orpc/server": "0.17.0",
|
|
43
|
+
"@orpc/transformer": "0.17.0",
|
|
44
|
+
"@orpc/zod": "0.17.0",
|
|
45
|
+
"@orpc/contract": "0.17.0"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
47
48
|
"@readme/openapi-parser": "^2.6.0",
|