@orpc/openapi 0.0.0-next.f56d2b3 → 0.0.0-next.fd0ca3d

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