@orpc/openapi 0.0.0-next.bc9d3dd → 0.0.0-next.bec5773

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