@orpc/openapi 2.0.0-beta.49 → 2.0.0-beta.50

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/dist/adapters/aws-lambda/index.d.ts +3 -15
  2. package/dist/adapters/aws-lambda/index.js +1 -1
  3. package/dist/adapters/aws-lambda/openapi-handler.d.ts +8 -9
  4. package/dist/adapters/aws-lambda/openapi-handler.js +19 -17
  5. package/dist/adapters/fastify/index.d.ts +2 -1
  6. package/dist/adapters/fastify/index.js +1 -1
  7. package/dist/adapters/fastify/openapi-handler.d.ts +8 -9
  8. package/dist/adapters/fastify/openapi-handler.js +16 -14
  9. package/dist/adapters/fetch/index.d.ts +3 -2
  10. package/dist/adapters/fetch/index.js +2 -2
  11. package/dist/adapters/fetch/openapi-handler.d.ts +8 -9
  12. package/dist/adapters/fetch/openapi-handler.js +16 -14
  13. package/dist/adapters/fetch/openapi-link.d.ts +9 -10
  14. package/dist/adapters/fetch/openapi-link.js +21 -19
  15. package/dist/adapters/node/index.d.ts +2 -1
  16. package/dist/adapters/node/index.js +1 -1
  17. package/dist/adapters/node/openapi-handler.d.ts +8 -9
  18. package/dist/adapters/node/openapi-handler.js +16 -14
  19. package/dist/adapters/standard/index.d.ts +4 -3
  20. package/dist/adapters/standard/index.js +3 -3
  21. package/dist/adapters/standard/openapi-handler-codec.d.ts +56 -57
  22. package/dist/adapters/standard/openapi-handler-codec.js +143 -205
  23. package/dist/adapters/standard/openapi-link-codec.d.ts +55 -59
  24. package/dist/adapters/standard/openapi-link-codec.js +262 -377
  25. package/dist/adapters/standard/openapi-matcher.d.ts +26 -26
  26. package/dist/adapters/standard/openapi-matcher.js +78 -108
  27. package/dist/adapters/standard/utils.js +28 -44
  28. package/dist/bracket-notation.d.ts +22 -22
  29. package/dist/bracket-notation.js +123 -173
  30. package/dist/client-factory.d.ts +12 -12
  31. package/dist/client-factory.js +13 -11
  32. package/dist/constants.d.ts +1 -4
  33. package/dist/constants.js +5 -4
  34. package/dist/extensions/route.d.ts +36 -36
  35. package/dist/extensions/route.js +7 -6
  36. package/dist/helpers/form-data.d.ts +1 -1
  37. package/dist/helpers/form-data.js +74 -86
  38. package/dist/helpers/index.d.ts +2 -1
  39. package/dist/helpers/index.js +1 -1
  40. package/dist/index.d.ts +15 -13
  41. package/dist/index.js +11 -11
  42. package/dist/meta.d.ts +298 -298
  43. package/dist/meta.js +54 -72
  44. package/dist/openapi-generator-components.d.ts +2 -31
  45. package/dist/openapi-generator-components.js +200 -248
  46. package/dist/openapi-generator-operation.d.ts +12 -33
  47. package/dist/openapi-generator-operation.js +369 -437
  48. package/dist/openapi-generator.d.ts +75 -80
  49. package/dist/openapi-generator.js +114 -142
  50. package/dist/openapi-json-serializer.d.ts +65 -65
  51. package/dist/openapi-json-serializer.js +218 -257
  52. package/dist/openapi-serializer.d.ts +31 -32
  53. package/dist/openapi-serializer.js +68 -92
  54. package/dist/plugins/index.d.ts +2 -1
  55. package/dist/plugins/index.js +1 -1
  56. package/dist/plugins/openapi-reference.d.ts +99 -102
  57. package/dist/plugins/openapi-reference.js +109 -132
  58. package/dist/router-utils.d.ts +7 -10
  59. package/dist/router-utils.js +30 -34
  60. package/dist/types.d.ts +8 -12
  61. package/dist/utils.d.ts +5 -10
  62. package/dist/utils.js +39 -42
  63. package/package.json +12 -12
  64. package/dist/adapters/standard/utils.d.ts +0 -4
  65. package/dist/types.js +0 -1
@@ -1,85 +1,77 @@
1
- import { getTracer, matchesHttpPath, mergeHttpPath, stringifyJSON, toArray, value, } from '@orpc/shared';
1
+ import { getTracer, matchesHttpPath, mergeHttpPath, stringifyJSON, toArray, value } from "@orpc/shared";
2
+ // src/plugins/openapi-reference.ts
2
3
  /**
3
- * Serves API reference documentation powered by Scalar or Swagger UI,
4
- * and exposes the OpenAPI specification as JSON.
5
- *
6
- * @remarks
7
- * **Note**: By default, the API reference UI is served from `/` and the OpenAPI specification from `/spec.json`.
8
- *
9
- * @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
10
- */
11
- export class OpenAPIReferenceHandlerPlugin {
12
- name = '~openapi-reference';
13
- spec;
14
- allow;
15
- specPath;
16
- provider;
17
- providerConfig;
18
- providerScriptUrl;
19
- providerCssUrl;
20
- docsPath;
21
- docsTitle;
22
- docsHead;
23
- constructor(options) {
24
- this.spec = options.spec;
25
- this.allow = options.allow;
26
- this.specPath = options.specPath ?? '/spec.json';
27
- this.provider = options.provider ?? 'scalar';
28
- this.providerConfig = options.providerConfig;
29
- this.providerScriptUrl = options.providerScriptUrl;
30
- this.providerCssUrl = options.providerCssUrl;
31
- this.docsTitle = options.docsTitle;
32
- this.docsPath = options.docsPath ?? '/';
33
- this.docsHead = options.docsHead ?? '';
34
- }
35
- init(options) {
36
- return {
37
- ...options,
38
- routingInterceptors: [
39
- // Run after user-provided routing interceptors so they can capture the ui/spec responses
40
- ...toArray(options.routingInterceptors),
41
- async ({ next, ...routingInterceptorOptions }) => {
42
- const result = await next();
43
- if (result.matched || routingInterceptorOptions.request.method !== 'GET') {
44
- return result;
45
- }
46
- const isSpecPath = matchesHttpPath(routingInterceptorOptions.request.url, routingInterceptorOptions.prefix
47
- ? mergeHttpPath(routingInterceptorOptions.prefix, this.specPath)
48
- : this.specPath);
49
- const isDocsPath = matchesHttpPath(routingInterceptorOptions.request.url, routingInterceptorOptions.prefix
50
- ? mergeHttpPath(routingInterceptorOptions.prefix, this.docsPath)
51
- : this.docsPath);
52
- if (!isSpecPath && !isDocsPath) {
53
- return result;
54
- }
55
- if ((await value(this.allow, routingInterceptorOptions)) === false) {
56
- return result;
57
- }
58
- const span = getTracer()?.getActiveSpan();
59
- const spec = await value(this.spec, routingInterceptorOptions);
60
- if (isSpecPath) {
61
- span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (openapi spec)`);
62
- const specFile = new File([stringifyJSON(spec)], `${spec.info.title}.json`, {
63
- type: 'application/json',
64
- });
65
- return { matched: true, response: { status: 200, headers: {}, body: specFile } };
66
- }
67
- span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (${this.provider} ui)`);
68
- const docsTitle = (await value(this.docsTitle, routingInterceptorOptions)) ?? spec.info.title;
69
- const docsHead = await value(this.docsHead, routingInterceptorOptions);
70
- let html;
71
- if (this.provider === 'swagger') {
72
- const scriptUrl = this.providerScriptUrl ?? 'https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js';
73
- const cssUrl = this.providerCssUrl ?? 'https://unpkg.com/swagger-ui-dist/swagger-ui.css';
74
- const config = {
75
- dom_id: '#app',
76
- spec,
77
- deepLinking: true,
78
- presets: ['SwaggerUIBundle.presets.apis'],
79
- plugins: ['SwaggerUIBundle.plugins.DownloadUrl'],
80
- ...this.providerConfig,
81
- };
82
- html = `
4
+ * Serves API reference documentation powered by Scalar or Swagger UI,
5
+ * and exposes the OpenAPI specification as JSON.
6
+ *
7
+ * @remarks
8
+ * **Note**: By default, the API reference UI is served from `/` and the OpenAPI specification from `/spec.json`.
9
+ *
10
+ * @see {@link https://orpc.dev/docs/plugins/openapi-reference | OpenAPI Reference Plugin (Swagger/Scalar)}
11
+ */
12
+ var OpenAPIReferenceHandlerPlugin = class {
13
+ name = "~openapi-reference";
14
+ spec;
15
+ allow;
16
+ specPath;
17
+ provider;
18
+ providerConfig;
19
+ providerScriptUrl;
20
+ providerCssUrl;
21
+ docsPath;
22
+ docsTitle;
23
+ docsHead;
24
+ constructor(options) {
25
+ this.spec = options.spec;
26
+ this.allow = options.allow;
27
+ this.specPath = options.specPath ?? "/spec.json";
28
+ this.provider = options.provider ?? "scalar";
29
+ this.providerConfig = options.providerConfig;
30
+ this.providerScriptUrl = options.providerScriptUrl;
31
+ this.providerCssUrl = options.providerCssUrl;
32
+ this.docsTitle = options.docsTitle;
33
+ this.docsPath = options.docsPath ?? "/";
34
+ this.docsHead = options.docsHead ?? "";
35
+ }
36
+ init(options) {
37
+ return {
38
+ ...options,
39
+ routingInterceptors: [...toArray(options.routingInterceptors), async ({ next, ...routingInterceptorOptions }) => {
40
+ const result = await next();
41
+ if (result.matched || routingInterceptorOptions.request.method !== "GET") return result;
42
+ const isSpecPath = matchesHttpPath(routingInterceptorOptions.request.url, routingInterceptorOptions.prefix ? mergeHttpPath(routingInterceptorOptions.prefix, this.specPath) : this.specPath);
43
+ const isDocsPath = matchesHttpPath(routingInterceptorOptions.request.url, routingInterceptorOptions.prefix ? mergeHttpPath(routingInterceptorOptions.prefix, this.docsPath) : this.docsPath);
44
+ if (!isSpecPath && !isDocsPath) return result;
45
+ if (await value(this.allow, routingInterceptorOptions) === false) return result;
46
+ const span = getTracer()?.getActiveSpan();
47
+ const spec = await value(this.spec, routingInterceptorOptions);
48
+ if (isSpecPath) {
49
+ span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (openapi spec)`);
50
+ return {
51
+ matched: true,
52
+ response: {
53
+ status: 200,
54
+ headers: {},
55
+ body: new File([stringifyJSON(spec)], `${spec.info.title}.json`, { type: "application/json" })
56
+ }
57
+ };
58
+ }
59
+ span?.updateName(`${routingInterceptorOptions.request.method} ${routingInterceptorOptions.request.url} (${this.provider} ui)`);
60
+ const docsTitle = await value(this.docsTitle, routingInterceptorOptions) ?? spec.info.title;
61
+ const docsHead = await value(this.docsHead, routingInterceptorOptions);
62
+ let html;
63
+ if (this.provider === "swagger") {
64
+ const scriptUrl = this.providerScriptUrl ?? "https://unpkg.com/swagger-ui-dist/swagger-ui-bundle.js";
65
+ const cssUrl = this.providerCssUrl ?? "https://unpkg.com/swagger-ui-dist/swagger-ui.css";
66
+ const config = {
67
+ dom_id: "#app",
68
+ spec,
69
+ deepLinking: true,
70
+ presets: ["SwaggerUIBundle.presets.apis"],
71
+ plugins: ["SwaggerUIBundle.plugins.DownloadUrl"],
72
+ ...this.providerConfig
73
+ };
74
+ html = `
83
75
  <!doctype html>
84
76
  <html>
85
77
  <head>
@@ -92,10 +84,10 @@ export class OpenAPIReferenceHandlerPlugin {
92
84
  <body>
93
85
  <div id="app"></div>
94
86
 
95
- <script src="${escapeHtmlEntities(scriptUrl)}"></script>
87
+ <script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
96
88
 
97
89
  <!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
98
- <!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the </script> tag prematurely. -->
90
+ <!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
99
91
  <!-- IMPORTANT: resolve presets/plugins global paths at runtime, never unquote them in the JSON, which also holds the spec. -->
100
92
  <script>
101
93
  const swaggerConfig = ${escapeJsonForHtml(config)}
@@ -107,81 +99,66 @@ export class OpenAPIReferenceHandlerPlugin {
107
99
 
108
100
  window.ui = SwaggerUIBundle(swaggerConfig)
109
101
  }
110
- </script>
102
+ <\/script>
111
103
  </body>
112
104
  </html>
113
105
  `;
114
- }
115
- else {
116
- const scriptUrl = this.providerScriptUrl ?? 'https://cdn.jsdelivr.net/npm/@scalar/api-reference';
117
- const cssUrl = this.providerCssUrl;
118
- const config = {
119
- content: stringifyJSON(spec),
120
- ...this.providerConfig,
121
- };
122
- html = `
106
+ } else {
107
+ const scriptUrl = this.providerScriptUrl ?? "https://cdn.jsdelivr.net/npm/@scalar/api-reference";
108
+ const cssUrl = this.providerCssUrl;
109
+ const config = {
110
+ content: stringifyJSON(spec),
111
+ ...this.providerConfig
112
+ };
113
+ html = `
123
114
  <!doctype html>
124
115
  <html>
125
116
  <head>
126
117
  <meta charset="utf-8" />
127
118
  <meta name="viewport" content="width=device-width, initial-scale=1" />
128
119
  <title>${escapeHtmlEntities(docsTitle)}</title>
129
- ${cssUrl ? `<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />` : ''}
120
+ ${cssUrl ? `<link rel="stylesheet" type="text/css" href="${escapeHtmlEntities(cssUrl)}" />` : ""}
130
121
  ${docsHead}
131
122
  </head>
132
123
  <body>
133
124
  <div id="app"></div>
134
125
 
135
- <script src="${escapeHtmlEntities(scriptUrl)}"></script>
126
+ <script src="${escapeHtmlEntities(scriptUrl)}"><\/script>
136
127
 
137
128
  <!-- IMPORTANT: assign to a variable first to prevent ), ( in values breaking the call expression. -->
138
- <!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the </script> tag prematurely. -->
129
+ <!-- IMPORTANT: escapeJsonForHtml ensures <, > cannot terminate the <\/script> tag prematurely. -->
139
130
  <script>
140
131
  const scalarConfig = ${escapeJsonForHtml(config)}
141
132
 
142
133
  Scalar.createApiReference('#app', scalarConfig)
143
- </script>
134
+ <\/script>
144
135
  </body>
145
136
  </html>
146
137
  `;
147
- }
148
- const htmlBlob = new Blob([html], {
149
- type: 'text/html',
150
- });
151
- return {
152
- matched: true,
153
- response: {
154
- status: 200,
155
- headers: {
156
- 'content-disposition': [], // disable auto-gen header
157
- },
158
- body: htmlBlob,
159
- },
160
- };
161
- },
162
- ],
163
- };
164
- }
165
- }
138
+ }
139
+ return {
140
+ matched: true,
141
+ response: {
142
+ status: 200,
143
+ headers: { "content-disposition": [] },
144
+ body: new Blob([html], { type: "text/html" })
145
+ }
146
+ };
147
+ }]
148
+ };
149
+ }
150
+ };
166
151
  /** Escapes a string for safe embedding in an HTML attribute value. */
167
152
  function escapeHtmlEntities(s) {
168
- return s
169
- .replace(/&/g, '&amp;')
170
- .replace(/"/g, '&quot;')
171
- .replace(/</g, '&lt;')
172
- .replace(/>/g, '&gt;');
153
+ return s.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
173
154
  }
174
155
  /**
175
- * Serialises a value to JSON safe for HTML embedding (attribute or <script>).
176
- * Uses Unicode escapes instead of HTML entities so JSON.parse reconstructs
177
- * the original values without corruption. Cannot be merged with `esc` —
178
- * HTML entities inside <script> are not decoded by the JS engine.
179
- */
156
+ * Serialises a value to JSON safe for HTML embedding (attribute or <script>).
157
+ * Uses Unicode escapes instead of HTML entities so JSON.parse reconstructs
158
+ * the original values without corruption. Cannot be merged with `esc` —
159
+ * HTML entities inside <script> are not decoded by the JS engine.
160
+ */
180
161
  function escapeJsonForHtml(obj) {
181
- return stringifyJSON(obj)
182
- .replace(/&/g, '\\u0026')
183
- .replace(/'/g, '\\u0027')
184
- .replace(/</g, '\\u003C')
185
- .replace(/>/g, '\\u003E')
186
- .replace(/\//g, '\\u002F');
162
+ return stringifyJSON(obj).replace(/&/g, "\\u0026").replace(/'/g, "\\u0027").replace(/</g, "\\u003C").replace(/>/g, "\\u003E").replace(/\//g, "\\u002F");
187
163
  }
164
+ export { OpenAPIReferenceHandlerPlugin };
@@ -1,13 +1,10 @@
1
- import type { RouterContract } from '@orpc/contract';
2
- import { ProcedureContract } from '@orpc/contract';
3
- export type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : {
4
- [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never;
5
- };
1
+ import { ProcedureContract, RouterContract } from "@orpc/contract";
2
+ export type PopulatedContractRouterOpenAPIPaths<T extends RouterContract> = T extends ProcedureContract<infer UInputSchema, infer UOutputSchema, infer UErrors> ? ProcedureContract<UInputSchema, UOutputSchema, UErrors> : { [K in keyof T]: T[K] extends RouterContract ? PopulatedContractRouterOpenAPIPaths<T[K]> : never; };
6
3
  export interface PopulateRouterContractOpenAPIPathsOptions {
7
- /**
8
- * Base path segments.
9
- */
10
- path?: string[] | undefined;
4
+ /**
5
+ * Base path segments.
6
+ */
7
+ path?: string[] | undefined;
11
8
  }
12
9
  /**
13
10
  * Automatically populates missing openapi.path using router structure.
@@ -17,4 +14,4 @@ export interface PopulateRouterContractOpenAPIPathsOptions {
17
14
  *
18
15
  * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
19
16
  */
20
- export declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
17
+ export declare function populateRouterContractOpenAPIPaths<T extends RouterContract>(router: T, options?: PopulateRouterContractOpenAPIPathsOptions): PopulatedContractRouterOpenAPIPaths<T>;
@@ -1,36 +1,32 @@
1
- import { ProcedureContract, resolveMetaPlugins } from '@orpc/contract';
2
- import { isNonPrimitive, pathToHttpPath, toArray } from '@orpc/shared';
3
- import { getOpenAPIMeta, openapi } from './meta.js';
1
+ import { getOpenAPIMeta, openapi } from "./meta.js";
2
+ import { isNonPrimitive, pathToHttpPath, toArray } from "@orpc/shared";
3
+ import { ProcedureContract, resolveMetaPlugins } from "@orpc/contract";
4
+ // src/router-utils.ts
4
5
  /**
5
- * Automatically populates missing openapi.path using router structure.
6
- *
7
- * Builds paths by joining router keys with `/`.
8
- * Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
9
- *
10
- * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
11
- */
12
- export function populateRouterContractOpenAPIPaths(router, options = {}) {
13
- const path = toArray(options.path);
14
- if (router instanceof ProcedureContract) {
15
- if (getOpenAPIMeta(router)?.path !== undefined) {
16
- return router;
17
- }
18
- const [meta, metaPlugins] = resolveMetaPlugins(router['~orpc'].meta, router['~orpc'].metaPlugins, [openapi({ path: pathToHttpPath(path) })]);
19
- return new ProcedureContract({
20
- ...router['~orpc'],
21
- meta,
22
- metaPlugins,
23
- });
24
- }
25
- if (!isNonPrimitive(router)) {
26
- return router;
27
- }
28
- const populated = {};
29
- for (const key of Object.keys(router)) {
30
- populated[key] = populateRouterContractOpenAPIPaths(router[key], {
31
- ...options,
32
- path: [...path, key],
33
- });
34
- }
35
- return populated;
6
+ * Automatically populates missing openapi.path using router structure.
7
+ *
8
+ * Builds paths by joining router keys with `/`.
9
+ * Useful when you want to ensure all contracts define openapi.path, such as for NestJS integration requirements.
10
+ *
11
+ * @see {@link https://orpc.dev/docs/integrations/nest | Implement oRPC contract with NestJS}
12
+ */
13
+ function populateRouterContractOpenAPIPaths(router, options = {}) {
14
+ const path = toArray(options.path);
15
+ if (router instanceof ProcedureContract) {
16
+ if (getOpenAPIMeta(router)?.path !== void 0) return router;
17
+ const [meta, metaPlugins] = resolveMetaPlugins(router["~orpc"].meta, router["~orpc"].metaPlugins, [openapi({ path: pathToHttpPath(path) })]);
18
+ return new ProcedureContract({
19
+ ...router["~orpc"],
20
+ meta,
21
+ metaPlugins
22
+ });
23
+ }
24
+ if (!isNonPrimitive(router)) return router;
25
+ const populated = {};
26
+ for (const key of Object.keys(router)) populated[key] = populateRouterContractOpenAPIPaths(router[key], {
27
+ ...options,
28
+ path: [...path, key]
29
+ });
30
+ return populated;
36
31
  }
32
+ export { populateRouterContractOpenAPIPaths };
package/dist/types.d.ts CHANGED
@@ -1,9 +1,8 @@
1
- import type * as OpenAPIV3_0 from '@openapi-spec/types/v3.0';
2
- import type * as OpenAPIV3_1 from '@openapi-spec/types/v3.1';
3
- import type * as OpenAPIV3_2 from '@openapi-spec/types/v3.2';
4
- import type { AnyNestedClient, Client, ORPCError } from '@orpc/client';
5
- import type { AsyncIteratorClass } from '@orpc/shared';
6
- export type { OpenAPIV3_0, OpenAPIV3_1, OpenAPIV3_2 };
1
+ import { AsyncIteratorClass } from "@orpc/shared";
2
+ import { AnyNestedClient, Client, ORPCError } from "@orpc/client";
3
+ import * as OpenAPIV3_0 from "@openapi-spec/types/v3.0";
4
+ import * as OpenAPIV3_1 from "@openapi-spec/types/v3.1";
5
+ import * as OpenAPIV3_2 from "@openapi-spec/types/v3.2";
7
6
  /**
8
7
  * An OpenAPI version `OpenAPIGenerator` can target: any `3.0.x`, `3.1.x`, or `3.2.x` value.
9
8
  *
@@ -16,9 +15,7 @@ export type OpenAPIVersion = `3.0.${number}` | `3.1.${number}` | `3.2.${number}`
16
15
  * @see {@link https://orpc.dev/docs/openapi/specification#openapi-version | OpenAPI Specification - OpenAPI Version}
17
16
  */
18
17
  export type OpenAPIDocument<TVersion extends OpenAPIVersion> = TVersion extends `3.0.${string}` ? OpenAPIV3_0.OpenAPIObject : TVersion extends `3.1.${string}` ? OpenAPIV3_1.OpenAPIObject : OpenAPIV3_2.OpenAPIObject;
19
- export type JsonifiedValue<T> = T extends string | number | boolean | null | undefined ? T : T extends Date | bigint | URL ? string : T extends ReadonlyArray<unknown> ? JsonifiedArray<T> : T extends Blob | ReadonlyMap<any, any> | ReadonlySet<any> | AsyncIteratorObject<any, any, any> | Function ? T extends File ? File : T extends Blob ? Blob : T extends ReadonlyMap<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends ReadonlySet<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorClass<infer U, infer V> ? AsyncIteratorClass<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncGenerator<infer U, infer V> ? AsyncGenerator<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown : T extends object ? {
20
- [K in keyof T]: JsonifiedValue<T[K]>;
21
- } : unknown;
18
+ export type JsonifiedValue<T> = T extends string | number | boolean | null | undefined ? T : T extends Date | bigint | URL ? string : T extends ReadonlyArray<unknown> ? JsonifiedArray<T> : T extends Blob | ReadonlyMap<any, any> | ReadonlySet<any> | AsyncIteratorObject<any, any, any> | Function ? T extends File ? File : T extends Blob ? Blob : T extends ReadonlyMap<infer K, infer V> ? JsonifiedArray<[K, V][]> : T extends ReadonlySet<infer U> ? JsonifiedArray<U[]> : T extends AsyncIteratorClass<infer U, infer V> ? AsyncIteratorClass<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncGenerator<infer U, infer V> ? AsyncGenerator<JsonifiedValue<U>, JsonifiedValue<V>> : T extends AsyncIteratorObject<infer U, infer V> ? AsyncIteratorObject<JsonifiedValue<U>, JsonifiedValue<V>> : unknown : T extends object ? { [K in keyof T]: JsonifiedValue<T[K]>; } : unknown;
22
19
  export type JsonifiedArray<T extends ReadonlyArray<unknown>> = T extends readonly [] ? [] : T extends readonly [infer U, ...infer V] ? [U extends undefined ? null : JsonifiedValue<U>, ...JsonifiedArray<V>] : T extends ReadonlyArray<infer U> ? Array<JsonifiedValue<U>> : unknown;
23
20
  export type JsonifiedClientError<T> = T extends ORPCError<infer UCode, infer UData> ? ORPCError<UCode, JsonifiedValue<UData>> : T;
24
21
  /**
@@ -26,6 +23,5 @@ export type JsonifiedClientError<T> = T extends ORPCError<infer UCode, infer UDa
26
23
  *
27
24
  * @see {@link https://orpc.dev/docs/openapi/link | OpenAPI Link}
28
25
  */
29
- export type JsonifiedClient<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, JsonifiedClientError<UError>> : {
30
- [K in keyof T]: T[K] extends AnyNestedClient ? JsonifiedClient<T[K]> : T[K];
31
- };
26
+ export type JsonifiedClient<T extends AnyNestedClient> = T extends Client<infer UClientContext, infer UInput, infer UOutput, infer UError> ? Client<UClientContext, UInput, JsonifiedValue<UOutput>, JsonifiedClientError<UError>> : { [K in keyof T]: T[K] extends AnyNestedClient ? JsonifiedClient<T[K]> : T[K]; };
27
+ export type { OpenAPIV3_0, OpenAPIV3_1, OpenAPIV3_2 };
package/dist/utils.d.ts CHANGED
@@ -1,14 +1,9 @@
1
- /**
2
- * GET and HEAD requests cannot carry a request body,
3
- * so their compact input maps to query parameters instead.
4
- */
5
- export declare function isBodylessMethod(method: string): boolean;
6
1
  /**
7
2
  * Dynamic parameters are always returned in path order.
8
3
  */
9
4
  export declare function getDynamicPathParams(path: `/${string}`): {
10
- segment: string;
11
- startIndex: number;
12
- parameterName: string;
13
- allowsSlash: boolean;
14
- }[] | undefined;
5
+ segment: string;
6
+ startIndex: number;
7
+ parameterName: string;
8
+ allowsSlash: boolean;
9
+ }[] | undefined;
package/dist/utils.js CHANGED
@@ -1,47 +1,44 @@
1
+ // src/utils.ts
1
2
  /**
2
- * GET and HEAD requests cannot carry a request body,
3
- * so their compact input maps to query parameters instead.
4
- */
5
- export function isBodylessMethod(method) {
6
- return method === 'GET' || method === 'HEAD';
3
+ * GET and HEAD requests cannot carry a request body,
4
+ * so their compact input maps to query parameters instead.
5
+ */
6
+ function isBodylessMethod(method) {
7
+ return method === "GET" || method === "HEAD";
7
8
  }
8
9
  const PARAMETER_NAME_REGEX = /^[\w-]+$/;
9
10
  /**
10
- * Dynamic parameters are always returned in path order.
11
- */
12
- export function getDynamicPathParams(path) {
13
- if (!path.includes('{')) {
14
- return undefined;
15
- }
16
- const len = path.length;
17
- let params;
18
- let index = 1;
19
- while (index < len) {
20
- const segmentStart = index;
21
- const slashPos = path.indexOf('/', index);
22
- const segmentEnd = slashPos === -1 ? len : slashPos;
23
- if (segmentEnd > segmentStart &&
24
- path.charCodeAt(segmentStart) === 123 &&
25
- path.charCodeAt(segmentEnd - 1) === 125) {
26
- let parameterStart = segmentStart + 1;
27
- let allowsSlash = false;
28
- const operator = path.charCodeAt(parameterStart);
29
- if (operator === 43) {
30
- allowsSlash = true;
31
- parameterStart++;
32
- }
33
- const parameterName = path.slice(parameterStart, segmentEnd - 1);
34
- if (PARAMETER_NAME_REGEX.test(parameterName)) {
35
- params ??= [];
36
- params.push({
37
- segment: path.slice(segmentStart, segmentEnd),
38
- startIndex: segmentStart,
39
- parameterName,
40
- allowsSlash,
41
- });
42
- }
43
- }
44
- index = segmentEnd + 1;
45
- }
46
- return params;
11
+ * Dynamic parameters are always returned in path order.
12
+ */
13
+ function getDynamicPathParams(path) {
14
+ if (!path.includes("{")) return;
15
+ const len = path.length;
16
+ let params;
17
+ let index = 1;
18
+ while (index < len) {
19
+ const segmentStart = index;
20
+ const slashPos = path.indexOf("/", index);
21
+ const segmentEnd = slashPos === -1 ? len : slashPos;
22
+ if (segmentEnd > segmentStart && path.charCodeAt(segmentStart) === 123 && path.charCodeAt(segmentEnd - 1) === 125) {
23
+ let parameterStart = segmentStart + 1;
24
+ let allowsSlash = false;
25
+ if (path.charCodeAt(parameterStart) === 43) {
26
+ allowsSlash = true;
27
+ parameterStart++;
28
+ }
29
+ const parameterName = path.slice(parameterStart, segmentEnd - 1);
30
+ if (PARAMETER_NAME_REGEX.test(parameterName)) {
31
+ params ??= [];
32
+ params.push({
33
+ segment: path.slice(segmentStart, segmentEnd),
34
+ startIndex: segmentStart,
35
+ parameterName,
36
+ allowsSlash
37
+ });
38
+ }
39
+ }
40
+ index = segmentEnd + 1;
41
+ }
42
+ return params;
47
43
  }
44
+ export { getDynamicPathParams, isBodylessMethod };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
- "version": "2.0.0-beta.49",
3
+ "version": "2.0.0-beta.50",
4
4
  "description": "Generate OpenAPI specs from oRPC routers and serve OpenAPI-compliant APIs with end-to-end type safety",
5
5
  "keywords": [
6
6
  "api",
@@ -81,20 +81,20 @@
81
81
  }
82
82
  },
83
83
  "dependencies": {
84
- "@openapi-spec/downgrader": "~0.7.1",
85
- "@openapi-spec/router": "~0.7.1",
86
- "@openapi-spec/types": "~0.7.1",
87
- "@orpc/client": "2.0.0-beta.49",
88
- "@orpc/contract": "2.0.0-beta.49",
89
- "@orpc/json-schema": "2.0.0-beta.49",
90
- "@orpc/server": "2.0.0-beta.49",
91
- "@orpc/shared": "2.0.0-beta.49",
92
- "@standard-server/core": "~0.15.0",
93
- "@standard-server/fetch": "~0.15.0"
84
+ "@openapi-spec/downgrader": "~0.8.0",
85
+ "@openapi-spec/router": "~0.8.0",
86
+ "@openapi-spec/types": "~0.8.0",
87
+ "@orpc/client": "2.0.0-beta.50",
88
+ "@orpc/contract": "2.0.0-beta.50",
89
+ "@orpc/json-schema": "2.0.0-beta.50",
90
+ "@orpc/server": "2.0.0-beta.50",
91
+ "@orpc/shared": "2.0.0-beta.50",
92
+ "@standard-server/core": "~0.16.0",
93
+ "@standard-server/fetch": "~0.16.0"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@scalar/api-reference": "^1.76.4",
97
- "@standard-server/aws-lambda": "~0.15.0",
97
+ "@standard-server/aws-lambda": "~0.16.0",
98
98
  "@types/swagger-ui": "^5.32.1",
99
99
  "fastify": "^5.12.8",
100
100
  "swagger-ui": "^5.34.1",
@@ -1,4 +0,0 @@
1
- import type { Public } from '@orpc/shared';
2
- import type { StandardHeaders } from '@standard-server/core';
3
- import type { OpenAPIJsonSerializer } from '../../openapi-json-serializer.ts';
4
- export declare function serializeHeaders(headers: object, serializer: Public<OpenAPIJsonSerializer>): StandardHeaders;
package/dist/types.js DELETED
@@ -1 +0,0 @@
1
- export {};