@orpc/openapi 0.0.0-next.f22c7ec → 0.0.0-next.f356b86

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