@orpc/openapi 0.0.0-next.da8ae32 → 0.0.0-next.da92bc0

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.
Files changed (62) hide show
  1. package/README.md +99 -0
  2. package/dist/adapters/aws-lambda/index.d.mts +17 -0
  3. package/dist/adapters/aws-lambda/index.d.ts +17 -0
  4. package/dist/adapters/aws-lambda/index.mjs +18 -0
  5. package/dist/adapters/fetch/index.d.mts +17 -0
  6. package/dist/adapters/fetch/index.d.ts +17 -0
  7. package/dist/adapters/fetch/index.mjs +18 -0
  8. package/dist/adapters/node/index.d.mts +17 -0
  9. package/dist/adapters/node/index.d.ts +17 -0
  10. package/dist/adapters/node/index.mjs +18 -0
  11. package/dist/adapters/standard/index.d.mts +35 -0
  12. package/dist/adapters/standard/index.d.ts +35 -0
  13. package/dist/adapters/standard/index.mjs +9 -0
  14. package/dist/index.d.mts +110 -0
  15. package/dist/index.d.ts +110 -0
  16. package/dist/index.mjs +41 -0
  17. package/dist/plugins/index.d.mts +69 -0
  18. package/dist/plugins/index.d.ts +69 -0
  19. package/dist/plugins/index.mjs +108 -0
  20. package/dist/shared/openapi.-sXpEIAO.mjs +179 -0
  21. package/dist/shared/openapi.8DHd5bRK.d.mts +101 -0
  22. package/dist/shared/openapi.8DHd5bRK.d.ts +101 -0
  23. package/dist/shared/openapi.BWrlhfev.d.mts +12 -0
  24. package/dist/shared/openapi.BWrlhfev.d.ts +12 -0
  25. package/dist/shared/openapi.DrrBsJ0w.mjs +738 -0
  26. package/package.json +31 -38
  27. package/dist/chunk-DRV7KYES.js +0 -420
  28. package/dist/chunk-HC5PVG4R.js +0 -52
  29. package/dist/chunk-NHYWV7BW.js +0 -32
  30. package/dist/fetch.js +0 -9
  31. package/dist/hono.js +0 -9
  32. package/dist/index.js +0 -602
  33. package/dist/next.js +0 -9
  34. package/dist/node.js +0 -30
  35. package/dist/src/adapters/fetch/index.d.ts +0 -2
  36. package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -11
  37. package/dist/src/adapters/hono/index.d.ts +0 -2
  38. package/dist/src/adapters/next/index.d.ts +0 -2
  39. package/dist/src/adapters/node/index.d.ts +0 -2
  40. package/dist/src/adapters/node/openapi-handler.d.ts +0 -11
  41. package/dist/src/adapters/standard/bracket-notation.d.ts +0 -84
  42. package/dist/src/adapters/standard/index.d.ts +0 -6
  43. package/dist/src/adapters/standard/openapi-codec.d.ts +0 -15
  44. package/dist/src/adapters/standard/openapi-handler.d.ts +0 -7
  45. package/dist/src/adapters/standard/openapi-matcher.d.ts +0 -20
  46. package/dist/src/adapters/standard/openapi-serializer.d.ts +0 -11
  47. package/dist/src/index.d.ts +0 -17
  48. package/dist/src/json-serializer.d.ts +0 -5
  49. package/dist/src/openapi-content-builder.d.ts +0 -10
  50. package/dist/src/openapi-error.d.ts +0 -3
  51. package/dist/src/openapi-generator.d.ts +0 -67
  52. package/dist/src/openapi-input-structure-parser.d.ts +0 -22
  53. package/dist/src/openapi-operation-extender.d.ts +0 -7
  54. package/dist/src/openapi-output-structure-parser.d.ts +0 -18
  55. package/dist/src/openapi-parameters-builder.d.ts +0 -12
  56. package/dist/src/openapi-path-parser.d.ts +0 -8
  57. package/dist/src/openapi.d.ts +0 -3
  58. package/dist/src/schema-converter.d.ts +0 -16
  59. package/dist/src/schema-utils.d.ts +0 -11
  60. package/dist/src/schema.d.ts +0 -12
  61. package/dist/src/utils.d.ts +0 -3
  62. package/dist/standard.js +0 -14
package/dist/index.js DELETED
@@ -1,602 +0,0 @@
1
- import {
2
- JSONSerializer,
3
- standardizeHTTPPath
4
- } from "./chunk-HC5PVG4R.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
- }
51
-
52
- // src/openapi.ts
53
- import { OpenApiBuilder } from "openapi3-ts/oas31";
54
-
55
- // src/openapi-content-builder.ts
56
- import { findDeepMatches } from "@orpc/shared";
57
- var OpenAPIContentBuilder = class {
58
- constructor(schemaUtils) {
59
- this.schemaUtils = schemaUtils;
60
- }
61
- build(jsonSchema, options) {
62
- const isFileSchema = this.schemaUtils.isFileSchema.bind(this.schemaUtils);
63
- const [matches, schema] = this.schemaUtils.filterSchemaBranches(jsonSchema, isFileSchema);
64
- const files = matches;
65
- const content = {};
66
- for (const file of files) {
67
- content[file.contentMediaType] = {
68
- schema: file
69
- };
70
- }
71
- const isStillHasFileSchema = findDeepMatches(isFileSchema, schema).values.length > 0;
72
- if (schema !== void 0) {
73
- content[isStillHasFileSchema ? "multipart/form-data" : "application/json"] = {
74
- schema,
75
- ...options
76
- };
77
- }
78
- return content;
79
- }
80
- };
81
-
82
- // src/openapi-generator.ts
83
- import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus } from "@orpc/contract";
84
- import { eachAllContractProcedure } from "@orpc/server";
85
- import { group } from "@orpc/shared";
86
-
87
- // src/openapi-error.ts
88
- var OpenAPIError = class extends Error {
89
- };
90
-
91
- // src/openapi-input-structure-parser.ts
92
- import { fallbackContractConfig } from "@orpc/contract";
93
- var OpenAPIInputStructureParser = class {
94
- constructor(schemaConverter, schemaUtils, pathParser) {
95
- this.schemaConverter = schemaConverter;
96
- this.schemaUtils = schemaUtils;
97
- this.pathParser = pathParser;
98
- }
99
- parse(contract, structure) {
100
- const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
101
- const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
102
- const httpPath = contract["~orpc"].route?.path;
103
- if (this.schemaUtils.isAnySchema(inputSchema)) {
104
- return {
105
- paramsSchema: void 0,
106
- querySchema: void 0,
107
- headersSchema: void 0,
108
- bodySchema: void 0
109
- };
110
- }
111
- if (structure === "detailed") {
112
- return this.parseDetailedSchema(inputSchema);
113
- } else {
114
- return this.parseCompactSchema(inputSchema, method, httpPath);
115
- }
116
- }
117
- parseDetailedSchema(inputSchema) {
118
- if (!this.schemaUtils.isObjectSchema(inputSchema)) {
119
- throw new OpenAPIError(`When input structure is 'detailed', input schema must be an object.`);
120
- }
121
- if (inputSchema.properties && Object.keys(inputSchema.properties).some((key) => !["params", "query", "headers", "body"].includes(key))) {
122
- throw new OpenAPIError(`When input structure is 'detailed', input schema must be only can contain 'params', 'query', 'headers' and 'body' properties.`);
123
- }
124
- let paramsSchema = inputSchema.properties?.params;
125
- let querySchema = inputSchema.properties?.query;
126
- let headersSchema = inputSchema.properties?.headers;
127
- const bodySchema = inputSchema.properties?.body;
128
- if (paramsSchema !== void 0 && this.schemaUtils.isAnySchema(paramsSchema)) {
129
- paramsSchema = void 0;
130
- }
131
- if (paramsSchema !== void 0 && !this.schemaUtils.isObjectSchema(paramsSchema)) {
132
- throw new OpenAPIError(`When input structure is 'detailed', params schema in input schema must be an object.`);
133
- }
134
- if (querySchema !== void 0 && this.schemaUtils.isAnySchema(querySchema)) {
135
- querySchema = void 0;
136
- }
137
- if (querySchema !== void 0 && !this.schemaUtils.isObjectSchema(querySchema)) {
138
- throw new OpenAPIError(`When input structure is 'detailed', query schema in input schema must be an object.`);
139
- }
140
- if (headersSchema !== void 0 && this.schemaUtils.isAnySchema(headersSchema)) {
141
- headersSchema = void 0;
142
- }
143
- if (headersSchema !== void 0 && !this.schemaUtils.isObjectSchema(headersSchema)) {
144
- throw new OpenAPIError(`When input structure is 'detailed', headers schema in input schema must be an object.`);
145
- }
146
- return { paramsSchema, querySchema, headersSchema, bodySchema };
147
- }
148
- parseCompactSchema(inputSchema, method, httpPath) {
149
- const dynamic = httpPath ? this.pathParser.parseDynamicParams(httpPath) : [];
150
- if (dynamic.length === 0) {
151
- if (method === "GET") {
152
- let querySchema = inputSchema;
153
- if (querySchema !== void 0 && this.schemaUtils.isAnySchema(querySchema)) {
154
- querySchema = void 0;
155
- }
156
- if (querySchema !== void 0 && !this.schemaUtils.isObjectSchema(querySchema)) {
157
- throw new OpenAPIError(`When input structure is 'compact' and method is 'GET', input schema must be an object.`);
158
- }
159
- return {
160
- paramsSchema: void 0,
161
- querySchema,
162
- headersSchema: void 0,
163
- bodySchema: void 0
164
- };
165
- }
166
- return {
167
- paramsSchema: void 0,
168
- querySchema: void 0,
169
- headersSchema: void 0,
170
- bodySchema: inputSchema
171
- };
172
- }
173
- if (!this.schemaUtils.isObjectSchema(inputSchema)) {
174
- throw new OpenAPIError(`When input structure is 'compact' and path has dynamic parameters, input schema must be an object.`);
175
- }
176
- const [params, rest] = this.schemaUtils.separateObjectSchema(inputSchema, dynamic.map((v) => v.name));
177
- return {
178
- paramsSchema: params,
179
- querySchema: method === "GET" ? rest : void 0,
180
- headersSchema: void 0,
181
- bodySchema: method !== "GET" ? rest : void 0
182
- };
183
- }
184
- };
185
-
186
- // src/openapi-output-structure-parser.ts
187
- var OpenAPIOutputStructureParser = class {
188
- constructor(schemaConverter, schemaUtils) {
189
- this.schemaConverter = schemaConverter;
190
- this.schemaUtils = schemaUtils;
191
- }
192
- parse(contract, structure) {
193
- const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
194
- if (this.schemaUtils.isAnySchema(outputSchema)) {
195
- return {
196
- headersSchema: void 0,
197
- bodySchema: void 0
198
- };
199
- }
200
- if (structure === "detailed") {
201
- return this.parseDetailedSchema(outputSchema);
202
- } else {
203
- return this.parseCompactSchema(outputSchema);
204
- }
205
- }
206
- parseDetailedSchema(outputSchema) {
207
- if (!this.schemaUtils.isObjectSchema(outputSchema)) {
208
- throw new OpenAPIError(`When output structure is 'detailed', output schema must be an object.`);
209
- }
210
- if (outputSchema.properties && Object.keys(outputSchema.properties).some((key) => !["headers", "body"].includes(key))) {
211
- throw new OpenAPIError(`When output structure is 'detailed', output schema must be only can contain 'headers' and 'body' properties.`);
212
- }
213
- let headersSchema = outputSchema.properties?.headers;
214
- const bodySchema = outputSchema.properties?.body;
215
- if (headersSchema !== void 0 && this.schemaUtils.isAnySchema(headersSchema)) {
216
- headersSchema = void 0;
217
- }
218
- if (headersSchema !== void 0 && !this.schemaUtils.isObjectSchema(headersSchema)) {
219
- throw new OpenAPIError(`When output structure is 'detailed', headers schema in output schema must be an object.`);
220
- }
221
- return { headersSchema, bodySchema };
222
- }
223
- parseCompactSchema(outputSchema) {
224
- return {
225
- headersSchema: void 0,
226
- bodySchema: outputSchema
227
- };
228
- }
229
- };
230
-
231
- // src/openapi-parameters-builder.ts
232
- import { get, isObject, omit } from "@orpc/shared";
233
- var OpenAPIParametersBuilder = class {
234
- build(paramIn, jsonSchema, options) {
235
- const parameters = [];
236
- for (const name in jsonSchema.properties) {
237
- const schema = jsonSchema.properties[name];
238
- const paramExamples = jsonSchema.examples?.filter((example) => {
239
- return isObject(example) && name in example;
240
- }).map((example) => {
241
- return example[name];
242
- });
243
- const paramSchema = {
244
- examples: paramExamples?.length ? paramExamples : void 0,
245
- ...schema === true ? {} : schema === false ? { not: {} } : schema
246
- };
247
- const paramExample = get(options?.example, [name]);
248
- parameters.push({
249
- name,
250
- in: paramIn,
251
- required: typeof options?.required === "boolean" ? options.required : jsonSchema.required?.includes(name) ?? false,
252
- schema: paramSchema,
253
- example: paramExample,
254
- style: options?.style
255
- });
256
- }
257
- return parameters;
258
- }
259
- buildHeadersObject(jsonSchema, options) {
260
- const parameters = this.build("header", jsonSchema, options);
261
- const headersObject = {};
262
- for (const param of parameters) {
263
- headersObject[param.name] = omit(param, ["name", "in"]);
264
- }
265
- return headersObject;
266
- }
267
- };
268
-
269
- // src/openapi-path-parser.ts
270
- var OpenAPIPathParser = class {
271
- parseDynamicParams(path) {
272
- const raws = path.match(/\{([^}]+)\}/g) ?? [];
273
- return raws.map((raw) => {
274
- const name = raw.slice(1, -1).split(":")[0];
275
- return { name, raw };
276
- });
277
- }
278
- };
279
-
280
- // src/schema-converter.ts
281
- var CompositeSchemaConverter = class {
282
- converters;
283
- constructor(converters) {
284
- this.converters = converters;
285
- }
286
- condition() {
287
- return true;
288
- }
289
- convert(schema, options) {
290
- for (const converter of this.converters) {
291
- if (converter.condition(schema, options)) {
292
- return converter.convert(schema, options);
293
- }
294
- }
295
- return {};
296
- }
297
- };
298
-
299
- // src/schema-utils.ts
300
- import { isObject as isObject2 } from "@orpc/shared";
301
-
302
- // src/schema.ts
303
- import * as JSONSchema from "json-schema-typed/draft-2020-12";
304
- import { Format } from "json-schema-typed/draft-2020-12";
305
- var NON_LOGIC_KEYWORDS = [
306
- // Core Documentation Keywords
307
- "$anchor",
308
- "$comment",
309
- "$defs",
310
- "$id",
311
- "title",
312
- "description",
313
- // Value Keywords
314
- "default",
315
- "deprecated",
316
- "examples",
317
- // Metadata Keywords
318
- "$schema",
319
- "definitions",
320
- // Legacy, but still used
321
- "readOnly",
322
- "writeOnly",
323
- // Display and UI Hints
324
- "contentMediaType",
325
- "contentEncoding",
326
- "format",
327
- // Custom Extensions
328
- "$vocabulary",
329
- "$dynamicAnchor",
330
- "$dynamicRef"
331
- ];
332
-
333
- // src/schema-utils.ts
334
- var SchemaUtils = class {
335
- isFileSchema(schema) {
336
- return typeof schema === "object" && schema.type === "string" && typeof schema.contentMediaType === "string";
337
- }
338
- isObjectSchema(schema) {
339
- return typeof schema === "object" && schema.type === "object";
340
- }
341
- isAnySchema(schema) {
342
- return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
343
- }
344
- isUndefinableSchema(schema) {
345
- const [matches] = this.filterSchemaBranches(schema, (schema2) => {
346
- if (typeof schema2 === "boolean") {
347
- return schema2;
348
- }
349
- return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
350
- });
351
- return matches.length > 0;
352
- }
353
- separateObjectSchema(schema, separatedProperties) {
354
- const matched = { ...schema };
355
- const rest = { ...schema };
356
- matched.properties = Object.entries(schema.properties ?? {}).filter(([key]) => separatedProperties.includes(key)).reduce((acc, [key, value]) => {
357
- acc[key] = value;
358
- return acc;
359
- }, {});
360
- matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
361
- matched.examples = schema.examples?.map((example) => {
362
- if (!isObject2(example)) {
363
- return example;
364
- }
365
- return Object.entries(example).reduce((acc, [key, value]) => {
366
- if (separatedProperties.includes(key)) {
367
- acc[key] = value;
368
- }
369
- return acc;
370
- }, {});
371
- });
372
- rest.properties = Object.entries(schema.properties ?? {}).filter(([key]) => !separatedProperties.includes(key)).reduce((acc, [key, value]) => {
373
- acc[key] = value;
374
- return acc;
375
- }, {});
376
- rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
377
- rest.examples = schema.examples?.map((example) => {
378
- if (!isObject2(example)) {
379
- return example;
380
- }
381
- return Object.entries(example).reduce((acc, [key, value]) => {
382
- if (!separatedProperties.includes(key)) {
383
- acc[key] = value;
384
- }
385
- return acc;
386
- }, {});
387
- });
388
- return [matched, rest];
389
- }
390
- filterSchemaBranches(schema, check, matches = []) {
391
- if (check(schema)) {
392
- matches.push(schema);
393
- return [matches, void 0];
394
- }
395
- if (typeof schema === "boolean") {
396
- return [matches, schema];
397
- }
398
- if (schema.anyOf && Object.keys(schema).every(
399
- (k) => k === "anyOf" || NON_LOGIC_KEYWORDS.includes(k)
400
- )) {
401
- const anyOf = schema.anyOf.map((s) => this.filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
402
- if (anyOf.length === 1 && typeof anyOf[0] === "object") {
403
- return [matches, { ...schema, anyOf: void 0, ...anyOf[0] }];
404
- }
405
- return [matches, { ...schema, anyOf }];
406
- }
407
- if (schema.oneOf && Object.keys(schema).every(
408
- (k) => k === "oneOf" || NON_LOGIC_KEYWORDS.includes(k)
409
- )) {
410
- const oneOf = schema.oneOf.map((s) => this.filterSchemaBranches(s, check, matches)[1]).filter((v) => !!v);
411
- if (oneOf.length === 1 && typeof oneOf[0] === "object") {
412
- return [matches, { ...schema, oneOf: void 0, ...oneOf[0] }];
413
- }
414
- return [matches, { ...schema, oneOf }];
415
- }
416
- return [matches, schema];
417
- }
418
- };
419
-
420
- // src/openapi-generator.ts
421
- var OpenAPIGenerator = class {
422
- contentBuilder;
423
- parametersBuilder;
424
- schemaConverter;
425
- schemaUtils;
426
- jsonSerializer;
427
- pathParser;
428
- inputStructureParser;
429
- outputStructureParser;
430
- errorHandlerStrategy;
431
- ignoreUndefinedPathProcedures;
432
- considerMissingTagDefinitionAsError;
433
- strictErrorResponses;
434
- constructor(options) {
435
- this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
436
- this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
437
- this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
438
- this.jsonSerializer = options?.jsonSerializer ?? new JSONSerializer();
439
- this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
440
- this.pathParser = new OpenAPIPathParser();
441
- this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
442
- this.outputStructureParser = options?.outputStructureParser ?? new OpenAPIOutputStructureParser(this.schemaConverter, this.schemaUtils);
443
- this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
444
- this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
445
- this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
446
- this.strictErrorResponses = options?.strictErrorResponses ?? true;
447
- }
448
- async generate(router, doc) {
449
- const builder = new OpenApiBuilder({
450
- ...doc,
451
- openapi: "3.1.1"
452
- });
453
- const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
454
- await eachAllContractProcedure({
455
- path: [],
456
- router
457
- }, ({ contract, path }) => {
458
- try {
459
- const def = contract["~orpc"];
460
- if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
461
- return;
462
- }
463
- const method = fallbackContractConfig2("defaultMethod", def.route?.method);
464
- const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
465
- const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
466
- const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
467
- const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
468
- const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
469
- const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
470
- required: true
471
- }) : [];
472
- const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
473
- const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
474
- const parameters = [...params, ...query, ...headers];
475
- const requestBody = bodySchema !== void 0 ? {
476
- required: this.schemaUtils.isUndefinableSchema(bodySchema),
477
- content: this.contentBuilder.build(bodySchema)
478
- } : void 0;
479
- const responses = {};
480
- responses[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
481
- description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
482
- content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
483
- headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
484
- };
485
- const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
486
- ...config,
487
- code,
488
- status: fallbackORPCErrorStatus(code, config?.status)
489
- })), (error) => error.status);
490
- for (const status in errors) {
491
- const configs = errors[status];
492
- if (!configs || configs.length === 0) {
493
- continue;
494
- }
495
- const schemas = configs.map(({ data, code, message }) => {
496
- const json = {
497
- type: "object",
498
- properties: {
499
- defined: { const: true },
500
- code: { const: code },
501
- status: { const: Number(status) },
502
- message: { type: "string", default: message },
503
- data: {}
504
- },
505
- required: ["defined", "code", "status", "message"]
506
- };
507
- if (data) {
508
- const dataJson = this.schemaConverter.convert(data, { strategy: "output" });
509
- json.properties.data = dataJson;
510
- if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
511
- json.required.push("data");
512
- }
513
- }
514
- return json;
515
- });
516
- if (this.strictErrorResponses) {
517
- schemas.push({
518
- type: "object",
519
- properties: {
520
- defined: { const: false },
521
- code: { type: "string" },
522
- status: { type: "number" },
523
- message: { type: "string" },
524
- data: {}
525
- },
526
- required: ["defined", "code", "status", "message"]
527
- });
528
- }
529
- const contentSchema = schemas.length === 1 ? schemas[0] : {
530
- oneOf: schemas
531
- };
532
- responses[status] = {
533
- description: status,
534
- content: this.contentBuilder.build(contentSchema)
535
- };
536
- }
537
- if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
538
- const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
539
- if (missingTag !== void 0) {
540
- throw new OpenAPIError(
541
- `Tag "${missingTag}" is missing definition. Please define it in OpenAPI root tags object`
542
- );
543
- }
544
- }
545
- const operation = {
546
- summary: def.route?.summary,
547
- description: def.route?.description,
548
- deprecated: def.route?.deprecated,
549
- tags: def.route?.tags ? [...def.route.tags] : void 0,
550
- operationId: path.join("."),
551
- parameters: parameters.length ? parameters : void 0,
552
- requestBody,
553
- responses
554
- };
555
- const extendedOperation = extendOperation(operation, contract);
556
- builder.addPath(httpPath, {
557
- [method.toLocaleLowerCase()]: extendedOperation
558
- });
559
- } catch (e) {
560
- if (e instanceof OpenAPIError) {
561
- const error = new OpenAPIError(`
562
- Generate OpenAPI Error: ${e.message}
563
- Happened at path: ${path.join(".")}
564
- `, { cause: e });
565
- if (this.errorHandlerStrategy === "throw") {
566
- throw error;
567
- }
568
- if (this.errorHandlerStrategy === "log") {
569
- console.error(error);
570
- }
571
- } else {
572
- throw e;
573
- }
574
- }
575
- });
576
- return this.jsonSerializer.serialize(builder.getSpec());
577
- }
578
- };
579
-
580
- // src/index.ts
581
- var oo = {
582
- spec: setOperationExtender
583
- };
584
- export {
585
- CompositeSchemaConverter,
586
- JSONSchema,
587
- Format as JSONSchemaFormat,
588
- JSONSerializer,
589
- NON_LOGIC_KEYWORDS,
590
- OpenAPIContentBuilder,
591
- OpenAPIGenerator,
592
- OpenAPIParametersBuilder,
593
- OpenAPIPathParser,
594
- OpenApiBuilder,
595
- SchemaUtils,
596
- extendOperation,
597
- getOperationExtender,
598
- oo,
599
- setOperationExtender,
600
- standardizeHTTPPath
601
- };
602
- //# sourceMappingURL=index.js.map
package/dist/next.js DELETED
@@ -1,9 +0,0 @@
1
- import {
2
- OpenAPIHandler
3
- } from "./chunk-NHYWV7BW.js";
4
- import "./chunk-DRV7KYES.js";
5
- import "./chunk-HC5PVG4R.js";
6
- export {
7
- OpenAPIHandler
8
- };
9
- //# sourceMappingURL=next.js.map
package/dist/node.js DELETED
@@ -1,30 +0,0 @@
1
- import {
2
- OpenAPICodec,
3
- OpenAPIMatcher
4
- } from "./chunk-DRV7KYES.js";
5
- import "./chunk-HC5PVG4R.js";
6
-
7
- // src/adapters/node/openapi-handler.ts
8
- import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
9
- import { StandardHandler } from "@orpc/server/standard";
10
- var OpenAPIHandler = class {
11
- standardHandler;
12
- constructor(router, options) {
13
- const matcher = options?.matcher ?? new OpenAPIMatcher(options);
14
- const codec = options?.codec ?? new OpenAPICodec(options);
15
- this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
16
- }
17
- async handle(req, res, ...rest) {
18
- const standardRequest = nodeHttpToStandardRequest(req, res);
19
- const result = await this.standardHandler.handle(standardRequest, ...rest);
20
- if (!result.matched) {
21
- return { matched: false };
22
- }
23
- await nodeHttpResponseSendStandardResponse(res, result.response);
24
- return { matched: true };
25
- }
26
- };
27
- export {
28
- OpenAPIHandler
29
- };
30
- //# sourceMappingURL=node.js.map
@@ -1,2 +0,0 @@
1
- export * from './openapi-handler';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { Context, Router } from '@orpc/server';
2
- import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
3
- import type { StandardHandleOptions } from '@orpc/server/standard';
4
- import type { MaybeOptionalOptions } from '@orpc/shared';
5
- import type { OpenAPIHandlerOptions } from '../standard';
6
- export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
7
- private readonly standardHandler;
8
- constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
- handle(request: Request, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<FetchHandleResult>;
10
- }
11
- //# sourceMappingURL=openapi-handler.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from '../fetch';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from '../fetch';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,2 +0,0 @@
1
- export * from './openapi-handler';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1,11 +0,0 @@
1
- import type { Context, Router } from '@orpc/server';
2
- import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
3
- import type { StandardHandleOptions } from '@orpc/server/standard';
4
- import type { MaybeOptionalOptions } from '@orpc/shared';
5
- import type { OpenAPIHandlerOptions } from '../standard';
6
- export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
7
- private readonly standardHandler;
8
- constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
9
- handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: MaybeOptionalOptions<StandardHandleOptions<T>>): Promise<NodeHttpHandleResult>;
10
- }
11
- //# sourceMappingURL=openapi-handler.d.ts.map