@orpc/openapi 0.0.0-next.4e27480 → 0.0.0-next.4f63ec1
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-LPBZEW4B.js +165 -0
- package/dist/chunk-UU2TTVB2.js +32 -0
- package/dist/chunk-XGHV4TH3.js +13 -0
- package/dist/fetch.js +5 -30
- package/dist/hono.js +5 -30
- package/dist/index.js +196 -45
- package/dist/next.js +5 -30
- package/dist/node.js +18 -34
- package/dist/src/adapters/fetch/index.d.ts +0 -8
- package/dist/src/adapters/fetch/openapi-handler.d.ts +8 -29
- package/dist/src/adapters/node/index.d.ts +0 -3
- package/dist/src/adapters/node/openapi-handler.d.ts +8 -8
- package/dist/src/adapters/standard/index.d.ts +4 -0
- package/dist/src/adapters/standard/openapi-codec.d.ts +16 -0
- package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
- package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
- package/dist/src/index.d.ts +5 -1
- package/dist/src/openapi-generator.d.ts +4 -4
- package/dist/src/openapi-input-structure-parser.d.ts +2 -2
- package/dist/src/openapi-operation-extender.d.ts +7 -0
- package/dist/src/openapi-output-structure-parser.d.ts +2 -2
- package/dist/src/schema-converter.d.ts +2 -2
- package/dist/src/utils.d.ts +2 -16
- package/dist/standard.js +10 -0
- package/package.json +14 -12
- package/dist/chunk-GEDPF5HA.js +0 -25
- package/dist/chunk-UG6W4GSA.js +0 -653
- package/dist/chunk-V4HFPIEN.js +0 -107
- package/dist/src/adapters/fetch/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/types.d.ts +0 -2
- package/dist/src/json-serializer.d.ts +0 -5
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import {
|
|
2
|
+
standardizeHTTPPath
|
|
3
|
+
} from "./chunk-XGHV4TH3.js";
|
|
4
|
+
|
|
5
|
+
// src/adapters/standard/openapi-codec.ts
|
|
6
|
+
import { OpenAPISerializer } from "@orpc/client/openapi";
|
|
7
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
8
|
+
import { isObject } from "@orpc/shared";
|
|
9
|
+
var OpenAPICodec = class {
|
|
10
|
+
serializer;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.serializer = options?.serializer ?? new OpenAPISerializer();
|
|
13
|
+
}
|
|
14
|
+
async decode(request, params, procedure) {
|
|
15
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", procedure["~orpc"].route.inputStructure);
|
|
16
|
+
if (inputStructure === "compact") {
|
|
17
|
+
const data = request.method === "GET" ? this.serializer.deserialize(request.url.searchParams) : this.serializer.deserialize(await request.body());
|
|
18
|
+
if (data === void 0) {
|
|
19
|
+
return params;
|
|
20
|
+
}
|
|
21
|
+
if (isObject(data)) {
|
|
22
|
+
return {
|
|
23
|
+
...params,
|
|
24
|
+
...data
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
const deserializeSearchParams = () => {
|
|
30
|
+
return this.serializer.deserialize(request.url.searchParams);
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
params,
|
|
34
|
+
get query() {
|
|
35
|
+
const value = deserializeSearchParams();
|
|
36
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
37
|
+
return value;
|
|
38
|
+
},
|
|
39
|
+
set query(value) {
|
|
40
|
+
Object.defineProperty(this, "query", { value, writable: true });
|
|
41
|
+
},
|
|
42
|
+
headers: request.headers,
|
|
43
|
+
body: this.serializer.deserialize(await request.body())
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
encode(output, procedure) {
|
|
47
|
+
const successStatus = fallbackContractConfig("defaultSuccessStatus", procedure["~orpc"].route.successStatus);
|
|
48
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", procedure["~orpc"].route.outputStructure);
|
|
49
|
+
if (outputStructure === "compact") {
|
|
50
|
+
return {
|
|
51
|
+
status: successStatus,
|
|
52
|
+
headers: {},
|
|
53
|
+
body: this.serializer.serialize(output)
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (!isObject(output)) {
|
|
57
|
+
throw new Error(
|
|
58
|
+
'Invalid output structure for "detailed" output. Expected format: { body: any, headers?: Record<string, string | string[] | undefined> }'
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
status: successStatus,
|
|
63
|
+
headers: output.headers ?? {},
|
|
64
|
+
body: this.serializer.serialize(output.body)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
encodeError(error) {
|
|
68
|
+
return {
|
|
69
|
+
status: error.status,
|
|
70
|
+
headers: {},
|
|
71
|
+
body: this.serializer.serialize(error.toJSON())
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/adapters/standard/openapi-matcher.ts
|
|
77
|
+
import { fallbackContractConfig as fallbackContractConfig2 } from "@orpc/contract";
|
|
78
|
+
import { convertPathToHttpPath, createContractedProcedure, eachContractProcedure, getLazyRouterPrefix, getRouterChild, isProcedure, unlazy } from "@orpc/server";
|
|
79
|
+
import { addRoute, createRouter, findRoute } from "rou3";
|
|
80
|
+
var OpenAPIMatcher = class {
|
|
81
|
+
tree = createRouter();
|
|
82
|
+
ignoreUndefinedMethod;
|
|
83
|
+
constructor(options) {
|
|
84
|
+
this.ignoreUndefinedMethod = options?.ignoreUndefinedMethod ?? false;
|
|
85
|
+
}
|
|
86
|
+
pendingRouters = [];
|
|
87
|
+
init(router, path = []) {
|
|
88
|
+
const laziedOptions = eachContractProcedure({
|
|
89
|
+
router,
|
|
90
|
+
path
|
|
91
|
+
}, ({ path: path2, contract }) => {
|
|
92
|
+
if (!contract["~orpc"].route.method && this.ignoreUndefinedMethod) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const method = fallbackContractConfig2("defaultMethod", contract["~orpc"].route.method);
|
|
96
|
+
const httpPath = contract["~orpc"].route.path ? toRou3Pattern(contract["~orpc"].route.path) : convertPathToHttpPath(path2);
|
|
97
|
+
if (isProcedure(contract)) {
|
|
98
|
+
addRoute(this.tree, method, httpPath, {
|
|
99
|
+
path: path2,
|
|
100
|
+
contract,
|
|
101
|
+
procedure: contract,
|
|
102
|
+
// this mean dev not used contract-first so we can used contract as procedure directly
|
|
103
|
+
router
|
|
104
|
+
});
|
|
105
|
+
} else {
|
|
106
|
+
addRoute(this.tree, method, httpPath, {
|
|
107
|
+
path: path2,
|
|
108
|
+
contract,
|
|
109
|
+
procedure: void 0,
|
|
110
|
+
router
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
this.pendingRouters.push(...laziedOptions.map((option) => ({
|
|
115
|
+
...option,
|
|
116
|
+
httpPathPrefix: convertPathToHttpPath(option.path),
|
|
117
|
+
laziedPrefix: getLazyRouterPrefix(option.lazied)
|
|
118
|
+
})));
|
|
119
|
+
}
|
|
120
|
+
async match(method, pathname) {
|
|
121
|
+
if (this.pendingRouters.length) {
|
|
122
|
+
const newPendingRouters = [];
|
|
123
|
+
for (const pendingRouter of this.pendingRouters) {
|
|
124
|
+
if (!pendingRouter.laziedPrefix || pathname.startsWith(pendingRouter.laziedPrefix) || pathname.startsWith(pendingRouter.httpPathPrefix)) {
|
|
125
|
+
const { default: router } = await unlazy(pendingRouter.lazied);
|
|
126
|
+
this.init(router, pendingRouter.path);
|
|
127
|
+
} else {
|
|
128
|
+
newPendingRouters.push(pendingRouter);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
this.pendingRouters = newPendingRouters;
|
|
132
|
+
}
|
|
133
|
+
const match = findRoute(this.tree, method, pathname);
|
|
134
|
+
if (!match) {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
if (!match.data.procedure) {
|
|
138
|
+
const { default: maybeProcedure } = await unlazy(getRouterChild(match.data.router, ...match.data.path));
|
|
139
|
+
if (!isProcedure(maybeProcedure)) {
|
|
140
|
+
throw new Error(`
|
|
141
|
+
[Contract-First] Missing or invalid implementation for procedure at path: ${convertPathToHttpPath(match.data.path)}.
|
|
142
|
+
Ensure that the procedure is correctly defined and matches the expected contract.
|
|
143
|
+
`);
|
|
144
|
+
}
|
|
145
|
+
match.data.procedure = createContractedProcedure(match.data.contract, maybeProcedure);
|
|
146
|
+
}
|
|
147
|
+
return {
|
|
148
|
+
path: match.data.path,
|
|
149
|
+
procedure: match.data.procedure,
|
|
150
|
+
params: match.params ? decodeParams(match.params) : void 0
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
function toRou3Pattern(path) {
|
|
155
|
+
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "**:$1").replace(/\{([^}]+)\}/g, ":$1");
|
|
156
|
+
}
|
|
157
|
+
function decodeParams(params) {
|
|
158
|
+
return Object.fromEntries(Object.entries(params).map(([key, value]) => [key, decodeURIComponent(value)]));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export {
|
|
162
|
+
OpenAPICodec,
|
|
163
|
+
OpenAPIMatcher
|
|
164
|
+
};
|
|
165
|
+
//# sourceMappingURL=chunk-LPBZEW4B.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher
|
|
4
|
+
} from "./chunk-LPBZEW4B.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/fetch/openapi-handler.ts
|
|
7
|
+
import { toFetchResponse, toStandardRequest } from "@orpc/server-standard-fetch";
|
|
8
|
+
import { StandardHandler } from "@orpc/server/standard";
|
|
9
|
+
var OpenAPIHandler = class {
|
|
10
|
+
standardHandler;
|
|
11
|
+
constructor(router, options) {
|
|
12
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher(options);
|
|
13
|
+
const codec = options?.codec ?? new OpenAPICodec(options);
|
|
14
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
15
|
+
}
|
|
16
|
+
async handle(request, ...rest) {
|
|
17
|
+
const standardRequest = toStandardRequest(request);
|
|
18
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
19
|
+
if (!result.matched) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
matched: true,
|
|
24
|
+
response: toFetchResponse(result.response)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
OpenAPIHandler
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=chunk-UU2TTVB2.js.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/utils.ts
|
|
2
|
+
function standardizeHTTPPath(path) {
|
|
3
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
4
|
+
}
|
|
5
|
+
function toOpenAPI31RoutePattern(path) {
|
|
6
|
+
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
standardizeHTTPPath,
|
|
11
|
+
toOpenAPI31RoutePattern
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=chunk-XGHV4TH3.js.map
|
package/dist/fetch.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
CompositeSchemaCoercer,
|
|
7
|
-
InputStructureCompact,
|
|
8
|
-
InputStructureDetailed,
|
|
9
|
-
OpenAPIHandler,
|
|
10
|
-
OpenAPIPayloadCodec,
|
|
11
|
-
OpenAPIProcedureMatcher,
|
|
12
|
-
deserialize,
|
|
13
|
-
escapeSegment,
|
|
14
|
-
parsePath,
|
|
15
|
-
serialize,
|
|
16
|
-
stringifyPath
|
|
17
|
-
} from "./chunk-UG6W4GSA.js";
|
|
18
|
-
import "./chunk-V4HFPIEN.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-UU2TTVB2.js";
|
|
4
|
+
import "./chunk-LPBZEW4B.js";
|
|
5
|
+
import "./chunk-XGHV4TH3.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=fetch.js.map
|
package/dist/hono.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
CompositeSchemaCoercer,
|
|
7
|
-
InputStructureCompact,
|
|
8
|
-
InputStructureDetailed,
|
|
9
|
-
OpenAPIHandler,
|
|
10
|
-
OpenAPIPayloadCodec,
|
|
11
|
-
OpenAPIProcedureMatcher,
|
|
12
|
-
deserialize,
|
|
13
|
-
escapeSegment,
|
|
14
|
-
parsePath,
|
|
15
|
-
serialize,
|
|
16
|
-
stringifyPath
|
|
17
|
-
} from "./chunk-UG6W4GSA.js";
|
|
18
|
-
import "./chunk-V4HFPIEN.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-UU2TTVB2.js";
|
|
4
|
+
import "./chunk-LPBZEW4B.js";
|
|
5
|
+
import "./chunk-XGHV4TH3.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=hono.js.map
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,53 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
standardizeHTTPPath,
|
|
3
|
+
toOpenAPI31RoutePattern
|
|
4
|
+
} from "./chunk-XGHV4TH3.js";
|
|
5
|
+
|
|
6
|
+
// src/openapi-operation-extender.ts
|
|
7
|
+
import { isProcedure } from "@orpc/server";
|
|
8
|
+
var OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
9
|
+
function setOperationExtender(o, extend) {
|
|
10
|
+
return new Proxy(o, {
|
|
11
|
+
get(target, prop, receiver) {
|
|
12
|
+
if (prop === OPERATION_EXTENDER_SYMBOL) {
|
|
13
|
+
return extend;
|
|
14
|
+
}
|
|
15
|
+
return Reflect.get(target, prop, receiver);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function getOperationExtender(o) {
|
|
20
|
+
return o[OPERATION_EXTENDER_SYMBOL];
|
|
21
|
+
}
|
|
22
|
+
function extendOperation(operation, procedure) {
|
|
23
|
+
const operationExtenders = [];
|
|
24
|
+
for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
|
|
25
|
+
const maybeExtender = getOperationExtender(errorItem);
|
|
26
|
+
if (maybeExtender) {
|
|
27
|
+
operationExtenders.push(maybeExtender);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (isProcedure(procedure)) {
|
|
31
|
+
for (const middleware of procedure["~orpc"].middlewares) {
|
|
32
|
+
const maybeExtender = getOperationExtender(middleware);
|
|
33
|
+
if (maybeExtender) {
|
|
34
|
+
operationExtenders.push(maybeExtender);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
let currentOperation = operation;
|
|
39
|
+
for (const extender of operationExtenders) {
|
|
40
|
+
if (typeof extender === "function") {
|
|
41
|
+
currentOperation = extender(currentOperation, procedure);
|
|
42
|
+
} else {
|
|
43
|
+
currentOperation = {
|
|
44
|
+
...currentOperation,
|
|
45
|
+
...extender
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return currentOperation;
|
|
50
|
+
}
|
|
7
51
|
|
|
8
52
|
// src/openapi.ts
|
|
9
53
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
@@ -36,7 +80,10 @@ var OpenAPIContentBuilder = class {
|
|
|
36
80
|
};
|
|
37
81
|
|
|
38
82
|
// src/openapi-generator.ts
|
|
39
|
-
import {
|
|
83
|
+
import { fallbackORPCErrorStatus } from "@orpc/client";
|
|
84
|
+
import { OpenAPIJsonSerializer } from "@orpc/client/openapi";
|
|
85
|
+
import { fallbackContractConfig as fallbackContractConfig2, getEventIteratorSchemaDetails } from "@orpc/contract";
|
|
86
|
+
import { eachAllContractProcedure } from "@orpc/server";
|
|
40
87
|
import { group } from "@orpc/shared";
|
|
41
88
|
|
|
42
89
|
// src/openapi-error.ts
|
|
@@ -52,7 +99,7 @@ var OpenAPIInputStructureParser = class {
|
|
|
52
99
|
this.pathParser = pathParser;
|
|
53
100
|
}
|
|
54
101
|
parse(contract, structure) {
|
|
55
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
102
|
+
const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
|
|
56
103
|
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
57
104
|
const httpPath = contract["~orpc"].route?.path;
|
|
58
105
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
@@ -145,7 +192,7 @@ var OpenAPIOutputStructureParser = class {
|
|
|
145
192
|
this.schemaUtils = schemaUtils;
|
|
146
193
|
}
|
|
147
194
|
parse(contract, structure) {
|
|
148
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
195
|
+
const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
|
|
149
196
|
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
150
197
|
return {
|
|
151
198
|
headersSchema: void 0,
|
|
@@ -184,14 +231,14 @@ var OpenAPIOutputStructureParser = class {
|
|
|
184
231
|
};
|
|
185
232
|
|
|
186
233
|
// src/openapi-parameters-builder.ts
|
|
187
|
-
import { get,
|
|
234
|
+
import { get, isObject, omit } from "@orpc/shared";
|
|
188
235
|
var OpenAPIParametersBuilder = class {
|
|
189
236
|
build(paramIn, jsonSchema, options) {
|
|
190
237
|
const parameters = [];
|
|
191
238
|
for (const name in jsonSchema.properties) {
|
|
192
239
|
const schema = jsonSchema.properties[name];
|
|
193
240
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
194
|
-
return
|
|
241
|
+
return isObject(example) && name in example;
|
|
195
242
|
}).map((example) => {
|
|
196
243
|
return example[name];
|
|
197
244
|
});
|
|
@@ -252,7 +299,7 @@ var CompositeSchemaConverter = class {
|
|
|
252
299
|
};
|
|
253
300
|
|
|
254
301
|
// src/schema-utils.ts
|
|
255
|
-
import {
|
|
302
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
256
303
|
|
|
257
304
|
// src/schema.ts
|
|
258
305
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
@@ -314,7 +361,7 @@ var SchemaUtils = class {
|
|
|
314
361
|
}, {});
|
|
315
362
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
316
363
|
matched.examples = schema.examples?.map((example) => {
|
|
317
|
-
if (!
|
|
364
|
+
if (!isObject2(example)) {
|
|
318
365
|
return example;
|
|
319
366
|
}
|
|
320
367
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -330,7 +377,7 @@ var SchemaUtils = class {
|
|
|
330
377
|
}, {});
|
|
331
378
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
332
379
|
rest.examples = schema.examples?.map((example) => {
|
|
333
|
-
if (!
|
|
380
|
+
if (!isObject2(example)) {
|
|
334
381
|
return example;
|
|
335
382
|
}
|
|
336
383
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -390,7 +437,7 @@ var OpenAPIGenerator = class {
|
|
|
390
437
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
391
438
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
392
439
|
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
393
|
-
this.jsonSerializer = options?.jsonSerializer ?? new
|
|
440
|
+
this.jsonSerializer = options?.jsonSerializer ?? new OpenAPIJsonSerializer();
|
|
394
441
|
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
395
442
|
this.pathParser = new OpenAPIPathParser();
|
|
396
443
|
this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
|
|
@@ -406,38 +453,134 @@ var OpenAPIGenerator = class {
|
|
|
406
453
|
openapi: "3.1.1"
|
|
407
454
|
});
|
|
408
455
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
409
|
-
await
|
|
456
|
+
await eachAllContractProcedure({
|
|
457
|
+
path: [],
|
|
458
|
+
router
|
|
459
|
+
}, ({ contract, path }) => {
|
|
410
460
|
try {
|
|
411
461
|
const def = contract["~orpc"];
|
|
412
462
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
413
463
|
return;
|
|
414
464
|
}
|
|
415
465
|
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
|
416
|
-
const httpPath = def.route?.path ?
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
466
|
+
const httpPath = def.route?.path ? toOpenAPI31RoutePattern(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
467
|
+
const { parameters, requestBody } = (() => {
|
|
468
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.inputSchema);
|
|
469
|
+
if (eventIteratorSchemaDetails) {
|
|
470
|
+
const requestBody3 = {
|
|
471
|
+
required: true,
|
|
472
|
+
content: {
|
|
473
|
+
"text/event-stream": {
|
|
474
|
+
schema: {
|
|
475
|
+
oneOf: [
|
|
476
|
+
{
|
|
477
|
+
type: "object",
|
|
478
|
+
properties: {
|
|
479
|
+
event: { type: "string", const: "message" },
|
|
480
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
|
481
|
+
id: { type: "string" },
|
|
482
|
+
retry: { type: "number" }
|
|
483
|
+
},
|
|
484
|
+
required: ["event", "data"]
|
|
485
|
+
},
|
|
486
|
+
{
|
|
487
|
+
type: "object",
|
|
488
|
+
properties: {
|
|
489
|
+
event: { type: "string", const: "done" },
|
|
490
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
|
491
|
+
id: { type: "string" },
|
|
492
|
+
retry: { type: "number" }
|
|
493
|
+
},
|
|
494
|
+
required: ["event", "data"]
|
|
495
|
+
},
|
|
496
|
+
{
|
|
497
|
+
type: "object",
|
|
498
|
+
properties: {
|
|
499
|
+
event: { type: "string", const: "error" },
|
|
500
|
+
data: {},
|
|
501
|
+
id: { type: "string" },
|
|
502
|
+
retry: { type: "number" }
|
|
503
|
+
},
|
|
504
|
+
required: ["event", "data"]
|
|
505
|
+
}
|
|
506
|
+
]
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
return { requestBody: requestBody3, parameters: [] };
|
|
512
|
+
}
|
|
513
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
514
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
515
|
+
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
516
|
+
required: true
|
|
517
|
+
}) : [];
|
|
518
|
+
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
|
519
|
+
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
|
520
|
+
const parameters2 = [...params, ...query, ...headers];
|
|
521
|
+
const requestBody2 = bodySchema !== void 0 ? {
|
|
522
|
+
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
523
|
+
content: this.contentBuilder.build(bodySchema)
|
|
524
|
+
} : void 0;
|
|
525
|
+
return { parameters: parameters2, requestBody: requestBody2 };
|
|
526
|
+
})();
|
|
527
|
+
const { responses } = (() => {
|
|
528
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.outputSchema);
|
|
529
|
+
if (eventIteratorSchemaDetails) {
|
|
530
|
+
const responses3 = {};
|
|
531
|
+
responses3[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
532
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
533
|
+
content: {
|
|
534
|
+
"text/event-stream": {
|
|
535
|
+
schema: {
|
|
536
|
+
oneOf: [
|
|
537
|
+
{
|
|
538
|
+
type: "object",
|
|
539
|
+
properties: {
|
|
540
|
+
event: { type: "string", const: "message" },
|
|
541
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, { strategy: "input" }),
|
|
542
|
+
id: { type: "string" },
|
|
543
|
+
retry: { type: "number" }
|
|
544
|
+
},
|
|
545
|
+
required: ["event", "data"]
|
|
546
|
+
},
|
|
547
|
+
{
|
|
548
|
+
type: "object",
|
|
549
|
+
properties: {
|
|
550
|
+
event: { type: "string", const: "done" },
|
|
551
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, { strategy: "input" }),
|
|
552
|
+
id: { type: "string" },
|
|
553
|
+
retry: { type: "number" }
|
|
554
|
+
},
|
|
555
|
+
required: ["event", "data"]
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
type: "object",
|
|
559
|
+
properties: {
|
|
560
|
+
event: { type: "string", const: "error" },
|
|
561
|
+
data: {},
|
|
562
|
+
id: { type: "string" },
|
|
563
|
+
retry: { type: "number" }
|
|
564
|
+
},
|
|
565
|
+
required: ["event", "data"]
|
|
566
|
+
}
|
|
567
|
+
]
|
|
568
|
+
}
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
return { responses: responses3 };
|
|
573
|
+
}
|
|
574
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
575
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
576
|
+
const responses2 = {};
|
|
577
|
+
responses2[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
578
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
579
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
580
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
581
|
+
};
|
|
582
|
+
return { responses: responses2 };
|
|
583
|
+
})();
|
|
441
584
|
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
442
585
|
...config,
|
|
443
586
|
code,
|
|
@@ -508,8 +651,9 @@ var OpenAPIGenerator = class {
|
|
|
508
651
|
requestBody,
|
|
509
652
|
responses
|
|
510
653
|
};
|
|
654
|
+
const extendedOperation = extendOperation(operation, contract);
|
|
511
655
|
builder.addPath(httpPath, {
|
|
512
|
-
[method.toLocaleLowerCase()]:
|
|
656
|
+
[method.toLocaleLowerCase()]: extendedOperation
|
|
513
657
|
});
|
|
514
658
|
} catch (e) {
|
|
515
659
|
if (e instanceof OpenAPIError) {
|
|
@@ -531,11 +675,15 @@ var OpenAPIGenerator = class {
|
|
|
531
675
|
return this.jsonSerializer.serialize(builder.getSpec());
|
|
532
676
|
}
|
|
533
677
|
};
|
|
678
|
+
|
|
679
|
+
// src/index.ts
|
|
680
|
+
var oo = {
|
|
681
|
+
spec: setOperationExtender
|
|
682
|
+
};
|
|
534
683
|
export {
|
|
535
684
|
CompositeSchemaConverter,
|
|
536
685
|
JSONSchema,
|
|
537
686
|
Format as JSONSchemaFormat,
|
|
538
|
-
JSONSerializer,
|
|
539
687
|
NON_LOGIC_KEYWORDS,
|
|
540
688
|
OpenAPIContentBuilder,
|
|
541
689
|
OpenAPIGenerator,
|
|
@@ -543,8 +691,11 @@ export {
|
|
|
543
691
|
OpenAPIPathParser,
|
|
544
692
|
OpenApiBuilder,
|
|
545
693
|
SchemaUtils,
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
694
|
+
extendOperation,
|
|
695
|
+
getOperationExtender,
|
|
696
|
+
oo,
|
|
697
|
+
setOperationExtender,
|
|
698
|
+
standardizeHTTPPath,
|
|
699
|
+
toOpenAPI31RoutePattern
|
|
549
700
|
};
|
|
550
701
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
CHANGED
|
@@ -1,34 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import
|
|
6
|
-
CompositeSchemaCoercer,
|
|
7
|
-
InputStructureCompact,
|
|
8
|
-
InputStructureDetailed,
|
|
9
|
-
OpenAPIHandler,
|
|
10
|
-
OpenAPIPayloadCodec,
|
|
11
|
-
OpenAPIProcedureMatcher,
|
|
12
|
-
deserialize,
|
|
13
|
-
escapeSegment,
|
|
14
|
-
parsePath,
|
|
15
|
-
serialize,
|
|
16
|
-
stringifyPath
|
|
17
|
-
} from "./chunk-UG6W4GSA.js";
|
|
18
|
-
import "./chunk-V4HFPIEN.js";
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-UU2TTVB2.js";
|
|
4
|
+
import "./chunk-LPBZEW4B.js";
|
|
5
|
+
import "./chunk-XGHV4TH3.js";
|
|
19
6
|
export {
|
|
20
|
-
|
|
21
|
-
InputStructureCompact,
|
|
22
|
-
InputStructureDetailed,
|
|
23
|
-
OpenAPIHandler,
|
|
24
|
-
OpenAPIPayloadCodec,
|
|
25
|
-
OpenAPIProcedureMatcher,
|
|
26
|
-
OpenAPIServerHandler,
|
|
27
|
-
OpenAPIServerlessHandler,
|
|
28
|
-
deserialize,
|
|
29
|
-
escapeSegment,
|
|
30
|
-
parsePath,
|
|
31
|
-
serialize,
|
|
32
|
-
stringifyPath
|
|
7
|
+
OpenAPIHandler
|
|
33
8
|
};
|
|
34
9
|
//# sourceMappingURL=next.js.map
|