@orpc/openapi 0.22.0 → 0.24.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-YXHH6XHB.js +642 -0
- package/dist/fetch.js +17 -565
- package/dist/index.js +229 -101
- package/dist/node.js +46 -0
- package/dist/src/{fetch → adapters/fetch}/index.d.ts +2 -2
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +6 -0
- package/dist/src/{fetch/input-builder-full.d.ts → adapters/fetch/input-structure-detailed.d.ts} +3 -3
- package/dist/src/{fetch → adapters/fetch}/openapi-handler.d.ts +11 -8
- package/dist/src/{fetch → adapters/fetch}/openapi-payload-codec.d.ts +2 -2
- package/dist/src/adapters/node/index.d.ts +5 -0
- package/dist/src/adapters/node/openapi-handler-server.d.ts +7 -0
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +7 -0
- package/dist/src/adapters/node/openapi-handler.d.ts +12 -0
- package/dist/src/adapters/node/types.d.ts +2 -0
- package/dist/src/openapi-error.d.ts +3 -0
- package/dist/src/openapi-generator.d.ts +15 -6
- package/dist/src/openapi-input-structure-parser.d.ts +22 -0
- package/dist/src/openapi-output-structure-parser.d.ts +18 -0
- package/dist/src/openapi-parameters-builder.d.ts +3 -0
- package/package.json +12 -6
- package/dist/src/fetch/input-builder-simple.d.ts +0 -6
- /package/dist/src/{fetch → adapters/fetch}/bracket-notation.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/openapi-handler-server.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/openapi-handler-serverless.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/openapi-procedure-matcher.d.ts +0 -0
- /package/dist/src/{fetch → adapters/fetch}/schema-coercer.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -35,8 +35,151 @@ var OpenAPIContentBuilder = class {
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
+
// src/openapi-error.ts
|
|
39
|
+
var OpenAPIError = class extends Error {
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// src/openapi-input-structure-parser.ts
|
|
43
|
+
var OpenAPIInputStructureParser = class {
|
|
44
|
+
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
45
|
+
this.schemaConverter = schemaConverter;
|
|
46
|
+
this.schemaUtils = schemaUtils;
|
|
47
|
+
this.pathParser = pathParser;
|
|
48
|
+
}
|
|
49
|
+
parse(contract, structure) {
|
|
50
|
+
const inputSchema = this.schemaConverter.convert(contract["~orpc"].InputSchema, { strategy: "input" });
|
|
51
|
+
const method = contract["~orpc"].route?.method ?? "POST";
|
|
52
|
+
const httpPath = contract["~orpc"].route?.path;
|
|
53
|
+
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
54
|
+
return {
|
|
55
|
+
paramsSchema: void 0,
|
|
56
|
+
querySchema: void 0,
|
|
57
|
+
headersSchema: void 0,
|
|
58
|
+
bodySchema: void 0
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
if (structure === "detailed") {
|
|
62
|
+
return this.parseDetailedSchema(inputSchema);
|
|
63
|
+
} else {
|
|
64
|
+
return this.parseCompactSchema(inputSchema, method, httpPath);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
parseDetailedSchema(inputSchema) {
|
|
68
|
+
if (!this.schemaUtils.isObjectSchema(inputSchema)) {
|
|
69
|
+
throw new OpenAPIError(`When input structure is 'detailed', input schema must be an object.`);
|
|
70
|
+
}
|
|
71
|
+
if (inputSchema.properties && Object.keys(inputSchema.properties).some((key) => !["params", "query", "headers", "body"].includes(key))) {
|
|
72
|
+
throw new OpenAPIError(`When input structure is 'detailed', input schema must be only can contain 'params', 'query', 'headers' and 'body' properties.`);
|
|
73
|
+
}
|
|
74
|
+
let paramsSchema = inputSchema.properties?.params;
|
|
75
|
+
let querySchema = inputSchema.properties?.query;
|
|
76
|
+
let headersSchema = inputSchema.properties?.headers;
|
|
77
|
+
const bodySchema = inputSchema.properties?.body;
|
|
78
|
+
if (paramsSchema !== void 0 && this.schemaUtils.isAnySchema(paramsSchema)) {
|
|
79
|
+
paramsSchema = void 0;
|
|
80
|
+
}
|
|
81
|
+
if (paramsSchema !== void 0 && !this.schemaUtils.isObjectSchema(paramsSchema)) {
|
|
82
|
+
throw new OpenAPIError(`When input structure is 'detailed', params schema in input schema must be an object.`);
|
|
83
|
+
}
|
|
84
|
+
if (querySchema !== void 0 && this.schemaUtils.isAnySchema(querySchema)) {
|
|
85
|
+
querySchema = void 0;
|
|
86
|
+
}
|
|
87
|
+
if (querySchema !== void 0 && !this.schemaUtils.isObjectSchema(querySchema)) {
|
|
88
|
+
throw new OpenAPIError(`When input structure is 'detailed', query schema in input schema must be an object.`);
|
|
89
|
+
}
|
|
90
|
+
if (headersSchema !== void 0 && this.schemaUtils.isAnySchema(headersSchema)) {
|
|
91
|
+
headersSchema = void 0;
|
|
92
|
+
}
|
|
93
|
+
if (headersSchema !== void 0 && !this.schemaUtils.isObjectSchema(headersSchema)) {
|
|
94
|
+
throw new OpenAPIError(`When input structure is 'detailed', headers schema in input schema must be an object.`);
|
|
95
|
+
}
|
|
96
|
+
return { paramsSchema, querySchema, headersSchema, bodySchema };
|
|
97
|
+
}
|
|
98
|
+
parseCompactSchema(inputSchema, method, httpPath) {
|
|
99
|
+
const dynamic = httpPath ? this.pathParser.parseDynamicParams(httpPath) : [];
|
|
100
|
+
if (dynamic.length === 0) {
|
|
101
|
+
if (method === "GET") {
|
|
102
|
+
let querySchema = inputSchema;
|
|
103
|
+
if (querySchema !== void 0 && this.schemaUtils.isAnySchema(querySchema)) {
|
|
104
|
+
querySchema = void 0;
|
|
105
|
+
}
|
|
106
|
+
if (querySchema !== void 0 && !this.schemaUtils.isObjectSchema(querySchema)) {
|
|
107
|
+
throw new OpenAPIError(`When input structure is 'compact' and method is 'GET', input schema must be an object.`);
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
paramsSchema: void 0,
|
|
111
|
+
querySchema,
|
|
112
|
+
headersSchema: void 0,
|
|
113
|
+
bodySchema: void 0
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
return {
|
|
117
|
+
paramsSchema: void 0,
|
|
118
|
+
querySchema: void 0,
|
|
119
|
+
headersSchema: void 0,
|
|
120
|
+
bodySchema: inputSchema
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
if (!this.schemaUtils.isObjectSchema(inputSchema)) {
|
|
124
|
+
throw new OpenAPIError(`When input structure is 'compact' and path has dynamic parameters, input schema must be an object.`);
|
|
125
|
+
}
|
|
126
|
+
const [params, rest] = this.schemaUtils.separateObjectSchema(inputSchema, dynamic.map((v) => v.name));
|
|
127
|
+
return {
|
|
128
|
+
paramsSchema: params,
|
|
129
|
+
querySchema: method === "GET" ? rest : void 0,
|
|
130
|
+
headersSchema: void 0,
|
|
131
|
+
bodySchema: method !== "GET" ? rest : void 0
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
// src/openapi-output-structure-parser.ts
|
|
137
|
+
var OpenAPIOutputStructureParser = class {
|
|
138
|
+
constructor(schemaConverter, schemaUtils) {
|
|
139
|
+
this.schemaConverter = schemaConverter;
|
|
140
|
+
this.schemaUtils = schemaUtils;
|
|
141
|
+
}
|
|
142
|
+
parse(contract, structure) {
|
|
143
|
+
const outputSchema = this.schemaConverter.convert(contract["~orpc"].OutputSchema, { strategy: "output" });
|
|
144
|
+
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
145
|
+
return {
|
|
146
|
+
headersSchema: void 0,
|
|
147
|
+
bodySchema: void 0
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
if (structure === "detailed") {
|
|
151
|
+
return this.parseDetailedSchema(outputSchema);
|
|
152
|
+
} else {
|
|
153
|
+
return this.parseCompactSchema(outputSchema);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
parseDetailedSchema(outputSchema) {
|
|
157
|
+
if (!this.schemaUtils.isObjectSchema(outputSchema)) {
|
|
158
|
+
throw new OpenAPIError(`When output structure is 'detailed', output schema must be an object.`);
|
|
159
|
+
}
|
|
160
|
+
if (outputSchema.properties && Object.keys(outputSchema.properties).some((key) => !["headers", "body"].includes(key))) {
|
|
161
|
+
throw new OpenAPIError(`When output structure is 'detailed', output schema must be only can contain 'headers' and 'body' properties.`);
|
|
162
|
+
}
|
|
163
|
+
let headersSchema = outputSchema.properties?.headers;
|
|
164
|
+
const bodySchema = outputSchema.properties?.body;
|
|
165
|
+
if (headersSchema !== void 0 && this.schemaUtils.isAnySchema(headersSchema)) {
|
|
166
|
+
headersSchema = void 0;
|
|
167
|
+
}
|
|
168
|
+
if (headersSchema !== void 0 && !this.schemaUtils.isObjectSchema(headersSchema)) {
|
|
169
|
+
throw new OpenAPIError(`When output structure is 'detailed', headers schema in output schema must be an object.`);
|
|
170
|
+
}
|
|
171
|
+
return { headersSchema, bodySchema };
|
|
172
|
+
}
|
|
173
|
+
parseCompactSchema(outputSchema) {
|
|
174
|
+
return {
|
|
175
|
+
headersSchema: void 0,
|
|
176
|
+
bodySchema: outputSchema
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
38
181
|
// src/openapi-parameters-builder.ts
|
|
39
|
-
import { get, isPlainObject } from "@orpc/shared";
|
|
182
|
+
import { get, isPlainObject, omit } from "@orpc/shared";
|
|
40
183
|
var OpenAPIParametersBuilder = class {
|
|
41
184
|
build(paramIn, jsonSchema, options) {
|
|
42
185
|
const parameters = [];
|
|
@@ -63,6 +206,14 @@ var OpenAPIParametersBuilder = class {
|
|
|
63
206
|
}
|
|
64
207
|
return parameters;
|
|
65
208
|
}
|
|
209
|
+
buildHeadersObject(jsonSchema, options) {
|
|
210
|
+
const parameters = this.build("header", jsonSchema, options);
|
|
211
|
+
const headersObject = {};
|
|
212
|
+
for (const param of parameters) {
|
|
213
|
+
headersObject[param.name] = omit(param, ["name", "in"]);
|
|
214
|
+
}
|
|
215
|
+
return headersObject;
|
|
216
|
+
}
|
|
66
217
|
};
|
|
67
218
|
|
|
68
219
|
// src/openapi-path-parser.ts
|
|
@@ -218,21 +369,30 @@ var SchemaUtils = class {
|
|
|
218
369
|
|
|
219
370
|
// src/openapi-generator.ts
|
|
220
371
|
var OpenAPIGenerator = class {
|
|
372
|
+
contentBuilder;
|
|
373
|
+
parametersBuilder;
|
|
374
|
+
schemaConverter;
|
|
375
|
+
schemaUtils;
|
|
376
|
+
jsonSerializer;
|
|
377
|
+
pathParser;
|
|
378
|
+
inputStructureParser;
|
|
379
|
+
outputStructureParser;
|
|
380
|
+
errorHandlerStrategy;
|
|
381
|
+
ignoreUndefinedPathProcedures;
|
|
382
|
+
considerMissingTagDefinitionAsError;
|
|
221
383
|
constructor(options) {
|
|
222
|
-
this.options = options;
|
|
223
384
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
224
385
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
225
386
|
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
226
387
|
this.jsonSerializer = options?.jsonSerializer ?? new JSONSerializer();
|
|
227
388
|
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
228
389
|
this.pathParser = new OpenAPIPathParser();
|
|
390
|
+
this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
|
|
391
|
+
this.outputStructureParser = options?.outputStructureParser ?? new OpenAPIOutputStructureParser(this.schemaConverter, this.schemaUtils);
|
|
392
|
+
this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
|
|
393
|
+
this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
394
|
+
this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
|
|
229
395
|
}
|
|
230
|
-
contentBuilder;
|
|
231
|
-
parametersBuilder;
|
|
232
|
-
schemaConverter;
|
|
233
|
-
schemaUtils;
|
|
234
|
-
jsonSerializer;
|
|
235
|
-
pathParser;
|
|
236
396
|
async generate(router, doc) {
|
|
237
397
|
const builder = new OpenApiBuilder({
|
|
238
398
|
...doc,
|
|
@@ -240,108 +400,76 @@ var OpenAPIGenerator = class {
|
|
|
240
400
|
});
|
|
241
401
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
242
402
|
await forEachAllContractProcedure(router, ({ contract, path }) => {
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
const method = def.route?.method ?? "POST";
|
|
248
|
-
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
249
|
-
let inputSchema = this.schemaConverter.convert(def.InputSchema, { strategy: "input" });
|
|
250
|
-
const outputSchema = this.schemaConverter.convert(def.OutputSchema, { strategy: "output" });
|
|
251
|
-
const params = (() => {
|
|
252
|
-
const dynamic = this.pathParser.parseDynamicParams(httpPath);
|
|
253
|
-
if (!dynamic.length) {
|
|
254
|
-
return void 0;
|
|
255
|
-
}
|
|
256
|
-
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
257
|
-
return void 0;
|
|
403
|
+
try {
|
|
404
|
+
const def = contract["~orpc"];
|
|
405
|
+
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
406
|
+
return;
|
|
258
407
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
);
|
|
265
|
-
return void 0;
|
|
266
|
-
}
|
|
267
|
-
const [matched, rest] = this.schemaUtils.separateObjectSchema(inputSchema, dynamic.map((v) => v.name));
|
|
268
|
-
inputSchema = rest;
|
|
269
|
-
return this.parametersBuilder.build("path", matched, {
|
|
270
|
-
example: def.inputExample,
|
|
408
|
+
const method = def.route?.method ?? "POST";
|
|
409
|
+
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
410
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, def.route?.inputStructure ?? "compact");
|
|
411
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, def.route?.outputStructure ?? "compact");
|
|
412
|
+
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
271
413
|
required: true
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
this.
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
return void 0;
|
|
414
|
+
}) : [];
|
|
415
|
+
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
|
416
|
+
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
|
417
|
+
const parameters = [...params, ...query, ...headers];
|
|
418
|
+
const requestBody = bodySchema !== void 0 ? {
|
|
419
|
+
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
420
|
+
content: this.contentBuilder.build(bodySchema)
|
|
421
|
+
} : void 0;
|
|
422
|
+
const successResponse = {
|
|
423
|
+
description: "OK",
|
|
424
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema, {
|
|
425
|
+
example: def.outputExample
|
|
426
|
+
}) : void 0,
|
|
427
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
|
|
428
|
+
example: def.outputExample
|
|
429
|
+
}) : void 0
|
|
430
|
+
};
|
|
431
|
+
if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
|
|
432
|
+
const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
433
|
+
if (missingTag !== void 0) {
|
|
434
|
+
throw new OpenAPIError(
|
|
435
|
+
`Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object`
|
|
436
|
+
);
|
|
437
|
+
}
|
|
297
438
|
}
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
439
|
+
const operation = {
|
|
440
|
+
summary: def.route?.summary,
|
|
441
|
+
description: def.route?.description,
|
|
442
|
+
deprecated: def.route?.deprecated,
|
|
443
|
+
tags: def.route?.tags ? [...def.route.tags] : void 0,
|
|
444
|
+
operationId: path.join("."),
|
|
445
|
+
parameters: parameters.length ? parameters : void 0,
|
|
446
|
+
requestBody,
|
|
447
|
+
responses: {
|
|
448
|
+
[def.route?.successStatus ?? 200]: successResponse
|
|
449
|
+
}
|
|
303
450
|
};
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
)
|
|
318
|
-
|
|
451
|
+
builder.addPath(httpPath, {
|
|
452
|
+
[method.toLocaleLowerCase()]: operation
|
|
453
|
+
});
|
|
454
|
+
} catch (e) {
|
|
455
|
+
if (e instanceof OpenAPIError) {
|
|
456
|
+
const error = new OpenAPIError(`
|
|
457
|
+
Generate OpenAPI Error: ${e.message}
|
|
458
|
+
Happened at path: ${path.join(".")}
|
|
459
|
+
`, { cause: e });
|
|
460
|
+
if (this.errorHandlerStrategy === "throw") {
|
|
461
|
+
throw error;
|
|
462
|
+
}
|
|
463
|
+
if (this.errorHandlerStrategy === "log") {
|
|
464
|
+
console.error(error);
|
|
465
|
+
}
|
|
466
|
+
} else {
|
|
467
|
+
throw e;
|
|
319
468
|
}
|
|
320
469
|
}
|
|
321
|
-
const operation = {
|
|
322
|
-
summary: def.route?.summary,
|
|
323
|
-
description: def.route?.description,
|
|
324
|
-
deprecated: def.route?.deprecated,
|
|
325
|
-
tags: def.route?.tags ? [...def.route.tags] : void 0,
|
|
326
|
-
operationId: path.join("."),
|
|
327
|
-
parameters: parameters.length ? parameters : void 0,
|
|
328
|
-
requestBody,
|
|
329
|
-
responses: {
|
|
330
|
-
[def.route?.successStatus ?? 200]: successResponse
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
builder.addPath(httpPath, {
|
|
334
|
-
[method.toLocaleLowerCase()]: operation
|
|
335
|
-
});
|
|
336
470
|
});
|
|
337
471
|
return this.jsonSerializer.serialize(builder.getSpec());
|
|
338
472
|
}
|
|
339
|
-
handleError(error) {
|
|
340
|
-
if (this.options?.throwOnError) {
|
|
341
|
-
throw error;
|
|
342
|
-
}
|
|
343
|
-
console.error(error);
|
|
344
|
-
}
|
|
345
473
|
};
|
|
346
474
|
export {
|
|
347
475
|
CompositeSchemaConverter,
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPIHandler
|
|
3
|
+
} from "./chunk-YXHH6XHB.js";
|
|
4
|
+
import "./chunk-KNYXLM77.js";
|
|
5
|
+
|
|
6
|
+
// src/adapters/node/openapi-handler.ts
|
|
7
|
+
import { createRequest, sendResponse } from "@mjackson/node-fetch-server";
|
|
8
|
+
import { ORPC_HANDLER_HEADER } from "@orpc/shared";
|
|
9
|
+
var OpenAPIHandler2 = class {
|
|
10
|
+
openapiFetchHandler;
|
|
11
|
+
constructor(hono, router, options) {
|
|
12
|
+
this.openapiFetchHandler = new OpenAPIHandler(hono, router, options);
|
|
13
|
+
}
|
|
14
|
+
condition(request) {
|
|
15
|
+
return request.headers[ORPC_HANDLER_HEADER] === void 0;
|
|
16
|
+
}
|
|
17
|
+
async handle(req, res, ...[options]) {
|
|
18
|
+
const request = createRequest(req, res, options);
|
|
19
|
+
const castedOptions = options ?? {};
|
|
20
|
+
const response = await this.openapiFetchHandler.fetch(request, castedOptions);
|
|
21
|
+
await options?.beforeSend?.(response, castedOptions.context);
|
|
22
|
+
return await sendResponse(res, response);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// src/adapters/node/openapi-handler-server.ts
|
|
27
|
+
import { TrieRouter } from "hono/router/trie-router";
|
|
28
|
+
var OpenAPIServerHandler = class extends OpenAPIHandler2 {
|
|
29
|
+
constructor(router, options) {
|
|
30
|
+
super(new TrieRouter(), router, options);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// src/adapters/node/openapi-handler-serverless.ts
|
|
35
|
+
import { LinearRouter } from "hono/router/linear-router";
|
|
36
|
+
var OpenAPIServerlessHandler = class extends OpenAPIHandler2 {
|
|
37
|
+
constructor(router, options) {
|
|
38
|
+
super(new LinearRouter(), router, options);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
OpenAPIHandler2 as OpenAPIHandler,
|
|
43
|
+
OpenAPIServerHandler,
|
|
44
|
+
OpenAPIServerlessHandler
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export * from './bracket-notation';
|
|
2
|
-
export * from './input-
|
|
3
|
-
export * from './input-
|
|
2
|
+
export * from './input-structure-compact';
|
|
3
|
+
export * from './input-structure-detailed';
|
|
4
4
|
export * from './openapi-handler';
|
|
5
5
|
export * from './openapi-handler-server';
|
|
6
6
|
export * from './openapi-handler-serverless';
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Params } from 'hono/router';
|
|
2
|
+
export declare class InputStructureCompact {
|
|
3
|
+
build(params: Params, payload: unknown): unknown;
|
|
4
|
+
}
|
|
5
|
+
export type PublicInputStructureCompact = Pick<InputStructureCompact, keyof InputStructureCompact>;
|
|
6
|
+
//# sourceMappingURL=input-structure-compact.d.ts.map
|
package/dist/src/{fetch/input-builder-full.d.ts → adapters/fetch/input-structure-detailed.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Params } from 'hono/router';
|
|
2
|
-
export declare class
|
|
2
|
+
export declare class InputStructureDetailed {
|
|
3
3
|
build(params: Params, query: unknown, headers: unknown, body: unknown): {
|
|
4
4
|
params: Params;
|
|
5
5
|
query: unknown;
|
|
@@ -7,5 +7,5 @@ export declare class InputBuilderFull {
|
|
|
7
7
|
body: unknown;
|
|
8
8
|
};
|
|
9
9
|
}
|
|
10
|
-
export type
|
|
11
|
-
//# sourceMappingURL=input-
|
|
10
|
+
export type PublicInputStructureDetailed = Pick<InputStructureDetailed, keyof InputStructureDetailed>;
|
|
11
|
+
//# sourceMappingURL=input-structure-detailed.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import type { Context, Router, WithSignal } from '@orpc/server';
|
|
1
2
|
import type { ConditionalFetchHandler, FetchOptions } from '@orpc/server/fetch';
|
|
2
|
-
import type {
|
|
3
|
-
import { type Context, type Router, type WithSignal } from '@orpc/server';
|
|
3
|
+
import type { PublicInputStructureCompact } from './input-structure-compact';
|
|
4
4
|
import { type Hooks } from '@orpc/shared';
|
|
5
|
-
import { type PublicJSONSerializer } from '
|
|
6
|
-
import { type
|
|
5
|
+
import { type PublicJSONSerializer } from '../../json-serializer';
|
|
6
|
+
import { type PublicInputStructureDetailed } from './input-structure-detailed';
|
|
7
7
|
import { type PublicOpenAPIPayloadCodec } from './openapi-payload-codec';
|
|
8
8
|
import { type Hono, type PublicOpenAPIProcedureMatcher } from './openapi-procedure-matcher';
|
|
9
9
|
import { type SchemaCoercer } from './schema-coercer';
|
|
@@ -11,20 +11,23 @@ export type OpenAPIHandlerOptions<T extends Context> = Hooks<Request, Response,
|
|
|
11
11
|
jsonSerializer?: PublicJSONSerializer;
|
|
12
12
|
procedureMatcher?: PublicOpenAPIProcedureMatcher;
|
|
13
13
|
payloadCodec?: PublicOpenAPIPayloadCodec;
|
|
14
|
-
inputBuilderSimple?:
|
|
15
|
-
inputBuilderFull?:
|
|
14
|
+
inputBuilderSimple?: PublicInputStructureCompact;
|
|
15
|
+
inputBuilderFull?: PublicInputStructureDetailed;
|
|
16
16
|
schemaCoercers?: SchemaCoercer[];
|
|
17
17
|
};
|
|
18
18
|
export declare class OpenAPIHandler<T extends Context> implements ConditionalFetchHandler<T> {
|
|
19
19
|
private readonly options?;
|
|
20
20
|
private readonly procedureMatcher;
|
|
21
21
|
private readonly payloadCodec;
|
|
22
|
-
private readonly
|
|
23
|
-
private readonly
|
|
22
|
+
private readonly inputStructureCompact;
|
|
23
|
+
private readonly inputStructureDetailed;
|
|
24
24
|
private readonly compositeSchemaCoercer;
|
|
25
25
|
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>> | undefined);
|
|
26
26
|
condition(request: Request): boolean;
|
|
27
27
|
fetch(request: Request, ...[options]: [options: FetchOptions<T>] | (undefined extends T ? [] : never)): Promise<Response>;
|
|
28
|
+
private decodeInput;
|
|
29
|
+
private encodeOutput;
|
|
30
|
+
private assertDetailedOutput;
|
|
28
31
|
private convertToORPCError;
|
|
29
32
|
}
|
|
30
33
|
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import type { PublicJSONSerializer } from '
|
|
1
|
+
import type { PublicJSONSerializer } from '../../json-serializer';
|
|
2
2
|
export declare class OpenAPIPayloadCodec {
|
|
3
3
|
private readonly jsonSerializer;
|
|
4
4
|
constructor(jsonSerializer: PublicJSONSerializer);
|
|
5
|
-
encode(payload: unknown, accept
|
|
5
|
+
encode(payload: unknown, accept: string | undefined): {
|
|
6
6
|
body: FormData | Blob | string | undefined;
|
|
7
7
|
headers?: Headers;
|
|
8
8
|
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
3
|
+
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
+
export declare class OpenAPIServerHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=openapi-handler-server.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
3
|
+
import { OpenAPIHandler } from './openapi-handler';
|
|
4
|
+
export declare class OpenAPIServerlessHandler<T extends Context> extends OpenAPIHandler<T> {
|
|
5
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=openapi-handler-serverless.d.ts.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { ConditionalRequestHandler, RequestOptions } from '@orpc/server/node';
|
|
3
|
+
import type { IncomingMessage, ServerResponse } from 'node:http';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../fetch/openapi-handler';
|
|
5
|
+
import type { Hono } from '../fetch/openapi-procedure-matcher';
|
|
6
|
+
export declare class OpenAPIHandler<T extends Context> implements ConditionalRequestHandler<T> {
|
|
7
|
+
private readonly openapiFetchHandler;
|
|
8
|
+
constructor(hono: Hono, router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
9
|
+
condition(request: IncomingMessage): boolean;
|
|
10
|
+
handle(req: IncomingMessage, res: ServerResponse, ...[options]: [options: RequestOptions<T>] | (undefined extends T ? [] : never)): Promise<void>;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { ContractRouter } from '@orpc/contract';
|
|
2
2
|
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
|
+
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
4
|
+
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
3
5
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
4
6
|
import type { SchemaConverter } from './schema-converter';
|
|
5
7
|
import { type PublicJSONSerializer } from './json-serializer';
|
|
@@ -7,6 +9,7 @@ import { type OpenAPI } from './openapi';
|
|
|
7
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
8
10
|
import { type PublicOpenAPIParametersBuilder } from './openapi-parameters-builder';
|
|
9
11
|
import { type PublicSchemaUtils } from './schema-utils';
|
|
12
|
+
type ErrorHandlerStrategy = 'throw' | 'log' | 'ignore';
|
|
10
13
|
export interface OpenAPIGeneratorOptions {
|
|
11
14
|
contentBuilder?: PublicOpenAPIContentBuilder;
|
|
12
15
|
parametersBuilder?: PublicOpenAPIParametersBuilder;
|
|
@@ -14,6 +17,8 @@ export interface OpenAPIGeneratorOptions {
|
|
|
14
17
|
schemaUtils?: PublicSchemaUtils;
|
|
15
18
|
jsonSerializer?: PublicJSONSerializer;
|
|
16
19
|
pathParser?: PublicOpenAPIPathParser;
|
|
20
|
+
inputStructureParser?: PublicOpenAPIInputStructureParser;
|
|
21
|
+
outputStructureParser?: PublicOpenAPIOutputStructureParser;
|
|
17
22
|
/**
|
|
18
23
|
* Throw error when you missing define tag definition on OpenAPI root tags
|
|
19
24
|
*
|
|
@@ -30,22 +35,26 @@ export interface OpenAPIGeneratorOptions {
|
|
|
30
35
|
*/
|
|
31
36
|
ignoreUndefinedPathProcedures?: boolean;
|
|
32
37
|
/**
|
|
33
|
-
*
|
|
38
|
+
* What to do when we found an error with our router
|
|
34
39
|
*
|
|
35
|
-
* @default
|
|
40
|
+
* @default 'throw'
|
|
36
41
|
*/
|
|
37
|
-
|
|
42
|
+
errorHandlerStrategy?: ErrorHandlerStrategy;
|
|
38
43
|
}
|
|
39
44
|
export declare class OpenAPIGenerator {
|
|
40
|
-
private readonly options?;
|
|
41
45
|
private readonly contentBuilder;
|
|
42
46
|
private readonly parametersBuilder;
|
|
43
47
|
private readonly schemaConverter;
|
|
44
48
|
private readonly schemaUtils;
|
|
45
49
|
private readonly jsonSerializer;
|
|
46
50
|
private readonly pathParser;
|
|
47
|
-
|
|
51
|
+
private readonly inputStructureParser;
|
|
52
|
+
private readonly outputStructureParser;
|
|
53
|
+
private readonly errorHandlerStrategy;
|
|
54
|
+
private readonly ignoreUndefinedPathProcedures;
|
|
55
|
+
private readonly considerMissingTagDefinitionAsError;
|
|
56
|
+
constructor(options?: OpenAPIGeneratorOptions);
|
|
48
57
|
generate(router: ContractRouter | ANY_ROUTER, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
49
|
-
private handleError;
|
|
50
58
|
}
|
|
59
|
+
export {};
|
|
51
60
|
//# sourceMappingURL=openapi-generator.d.ts.map
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
|
+
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
3
|
+
import type { JSONSchema, ObjectSchema } from './schema';
|
|
4
|
+
import type { SchemaConverter } from './schema-converter';
|
|
5
|
+
import type { PublicSchemaUtils } from './schema-utils';
|
|
6
|
+
export interface OpenAPIInputStructureParseResult {
|
|
7
|
+
paramsSchema: ObjectSchema | undefined;
|
|
8
|
+
querySchema: ObjectSchema | undefined;
|
|
9
|
+
headersSchema: ObjectSchema | undefined;
|
|
10
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
|
11
|
+
}
|
|
12
|
+
export declare class OpenAPIInputStructureParser {
|
|
13
|
+
private readonly schemaConverter;
|
|
14
|
+
private readonly schemaUtils;
|
|
15
|
+
private readonly pathParser;
|
|
16
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
|
|
17
|
+
parse(contract: ANY_CONTRACT_PROCEDURE, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
|
|
18
|
+
private parseDetailedSchema;
|
|
19
|
+
private parseCompactSchema;
|
|
20
|
+
}
|
|
21
|
+
export type PublicOpenAPIInputStructureParser = Pick<OpenAPIInputStructureParser, keyof OpenAPIInputStructureParser>;
|
|
22
|
+
//# sourceMappingURL=openapi-input-structure-parser.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ANY_CONTRACT_PROCEDURE } from '@orpc/contract';
|
|
2
|
+
import type { JSONSchema, ObjectSchema } from './schema';
|
|
3
|
+
import type { SchemaConverter } from './schema-converter';
|
|
4
|
+
import type { PublicSchemaUtils } from './schema-utils';
|
|
5
|
+
export interface OpenAPIOutputStructureParseResult {
|
|
6
|
+
headersSchema: ObjectSchema | undefined;
|
|
7
|
+
bodySchema: JSONSchema.JSONSchema | undefined;
|
|
8
|
+
}
|
|
9
|
+
export declare class OpenAPIOutputStructureParser {
|
|
10
|
+
private readonly schemaConverter;
|
|
11
|
+
private readonly schemaUtils;
|
|
12
|
+
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
|
|
13
|
+
parse(contract: ANY_CONTRACT_PROCEDURE, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
|
|
14
|
+
private parseDetailedSchema;
|
|
15
|
+
private parseCompactSchema;
|
|
16
|
+
}
|
|
17
|
+
export type PublicOpenAPIOutputStructureParser = Pick<OpenAPIOutputStructureParser, keyof OpenAPIOutputStructureParser>;
|
|
18
|
+
//# sourceMappingURL=openapi-output-structure-parser.d.ts.map
|