@orpc/openapi 0.0.0-next.73eeb92 → 0.0.0-next.7461b74

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.
package/README.md CHANGED
@@ -21,28 +21,24 @@
21
21
 
22
22
  <h3 align="center">Typesafe APIs Made Simple 🪄</h3>
23
23
 
24
- **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards, ensuring a smooth and enjoyable developer experience.
24
+ **oRPC is a powerful combination of RPC and OpenAPI**, makes it easy to build APIs that are end-to-end type-safe and adhere to OpenAPI standards
25
25
 
26
26
  ---
27
27
 
28
28
  ## Highlights
29
29
 
30
- - **End-to-End Type Safety 🔒**: Ensure complete type safety from inputs to outputs and errors, bridging server and client seamlessly.
31
- - **First-Class OpenAPI 📄**: Adheres to the OpenAPI standard out of the box, ensuring seamless integration and comprehensive API documentation.
32
- - **Contract-First Development 📜**: (Optional) Define your API contract upfront and implement it with confidence.
33
- - **Exceptional Developer Experience ✨**: Enjoy a streamlined workflow with robust typing and clear, in-code documentation.
34
- - **Multi-Runtime Support 🌍**: Run your code seamlessly on Cloudflare, Deno, Bun, Node.js, and more.
35
- - **Framework Integrations 🧩**: Supports Tanstack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
36
- - **Server Actions ⚡️**: Fully compatible with React Server Actions on Next.js, TanStack Start, and more.
37
- - **Standard Schema Support 🗂️**: Effortlessly work with Zod, Valibot, ArkType, and others right out of the box.
38
- - **Fast & Lightweight 💨**: Built on native APIs across all runtimes – optimized for speed and efficiency.
39
- - **Native Types 📦**: Enjoy built-in support for Date, File, Blob, BigInt, URL and more with no extra setup.
40
- - **Lazy Router ⏱️**: Improve cold start times with our lazy routing feature.
41
- - **SSE & Streaming 📡**: Provides SSE and streaming features – perfect for real-time notifications and AI-powered streaming responses.
42
- - **Reusability 🔄**: Write once and reuse your code across multiple purposes effortlessly.
43
- - **Extendability 🔌**: Easily enhance oRPC with plugins, middleware, and interceptors.
44
- - **Reliability 🛡️**: Well-tested, fully TypeScript, production-ready, and MIT licensed for peace of mind.
45
- - **Simplicity 💡**: Enjoy straightforward, clean code with no hidden magic.
30
+ - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
+ - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
+ - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
+ - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
+ - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
+ - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
37
+ - **⏱️ Lazy Router**: Enhance cold start times with our lazy routing feature.
38
+ - **📡 SSE & Streaming**: Enjoy full type-safe support for SSE and streaming.
39
+ - **🌍 Multi-Runtime Support**: Fast and lightweight on Cloudflare, Deno, Bun, Node.js, and beyond.
40
+ - **🔌 Extendability**: Easily extend functionality with plugins, middleware, and interceptors.
41
+ - **🛡️ Reliability**: Well-tested, TypeScript-based, production-ready, and MIT licensed.
46
42
 
47
43
  ## Documentation
48
44
 
@@ -1,9 +1,15 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
- import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
4
4
  import '@orpc/openapi-client/standard';
5
5
  import '@orpc/server/standard';
6
6
 
7
+ /**
8
+ * OpenAPI Handler for Fetch Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/fetch-server Fetch Server Integration Docs}
12
+ */
7
13
  declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
8
14
  constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
9
15
  }
@@ -1,9 +1,15 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { FetchHandler, FetchHandlerOptions } from '@orpc/server/fetch';
3
- import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
4
4
  import '@orpc/openapi-client/standard';
5
5
  import '@orpc/server/standard';
6
6
 
7
+ /**
8
+ * OpenAPI Handler for Fetch Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/fetch-server Fetch Server Integration Docs}
12
+ */
7
13
  declare class OpenAPIHandler<T extends Context> extends FetchHandler<T> {
8
14
  constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & FetchHandlerOptions<T>>);
9
15
  }
@@ -1,10 +1,17 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.CGZ7t-VN.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '../../shared/openapi.sdeu0I7N.mjs';
1
+ import { FetchHandler } from '@orpc/server/fetch';
6
2
  import '@orpc/contract';
7
3
  import '@orpc/shared';
4
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.p5tsmBXx.mjs';
8
5
  import '@orpc/client/standard';
9
6
  import '@orpc/server';
10
7
  import 'rou3';
8
+ import '@orpc/openapi-client/standard';
9
+ import '@orpc/server/standard';
10
+
11
+ class OpenAPIHandler extends FetchHandler {
12
+ constructor(router, options = {}) {
13
+ super(new StandardOpenAPIHandler(router, options), options);
14
+ }
15
+ }
16
+
17
+ export { OpenAPIHandler };
@@ -1,9 +1,15 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
- import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
4
4
  import '@orpc/openapi-client/standard';
5
5
  import '@orpc/server/standard';
6
6
 
7
+ /**
8
+ * OpenAPI Handler for Node Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/node Node Integration Docs}
12
+ */
7
13
  declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
8
14
  constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
9
15
  }
@@ -1,9 +1,15 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { NodeHttpHandler, NodeHttpHandlerOptions } from '@orpc/server/node';
3
- import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
3
+ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
4
4
  import '@orpc/openapi-client/standard';
5
5
  import '@orpc/server/standard';
6
6
 
7
+ /**
8
+ * OpenAPI Handler for Node Server
9
+ *
10
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-handler OpenAPI Handler Docs}
11
+ * @see {@link https://orpc.unnoq.com/docs/integrations/node Node Integration Docs}
12
+ */
7
13
  declare class OpenAPIHandler<T extends Context> extends NodeHttpHandler<T> {
8
14
  constructor(router: Router<any, T>, options?: NoInfer<StandardOpenAPIHandlerOptions<T> & NodeHttpHandlerOptions<T>>);
9
15
  }
@@ -1,21 +1,16 @@
1
- import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
1
  import { NodeHttpHandler } from '@orpc/server/node';
3
- import { StandardHandler } from '@orpc/server/standard';
4
- import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from '../../shared/openapi.sdeu0I7N.mjs';
5
2
  import '@orpc/contract';
6
3
  import '@orpc/shared';
4
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.p5tsmBXx.mjs';
7
5
  import '@orpc/client/standard';
8
6
  import '@orpc/server';
9
7
  import 'rou3';
8
+ import '@orpc/openapi-client/standard';
9
+ import '@orpc/server/standard';
10
10
 
11
11
  class OpenAPIHandler extends NodeHttpHandler {
12
12
  constructor(router, options = {}) {
13
- const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
14
- const bracketNotationSerializer = new StandardBracketNotationSerializer();
15
- const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
16
- const matcher = new StandardOpenAPIMatcher();
17
- const codec = new StandardOpenAPICodec(serializer);
18
- super(new StandardHandler(router, matcher, codec, options), options);
13
+ super(new StandardOpenAPIHandler(router, options), options);
19
14
  }
20
15
  }
21
16
 
@@ -3,7 +3,7 @@ import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
3
3
  import { AnyProcedure, AnyRouter } from '@orpc/server';
4
4
  import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
5
5
  import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
6
- export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.mjs';
6
+ export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.mjs';
7
7
 
8
8
  declare class StandardOpenAPICodec implements StandardCodec {
9
9
  private readonly serializer;
@@ -3,7 +3,7 @@ import { StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
3
3
  import { AnyProcedure, AnyRouter } from '@orpc/server';
4
4
  import { StandardCodec, StandardParams, StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
5
5
  import { StandardLazyRequest, StandardResponse } from '@orpc/standard-server';
6
- export { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.IfmmOyba.js';
6
+ export { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9n.js';
7
7
 
8
8
  declare class StandardOpenAPICodec implements StandardCodec {
9
9
  private readonly serializer;
@@ -1,7 +1,8 @@
1
- export { S as StandardOpenAPICodec, a as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.sdeu0I7N.mjs';
1
+ export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.p5tsmBXx.mjs';
2
+ import '@orpc/openapi-client/standard';
3
+ import '@orpc/server/standard';
2
4
  import '@orpc/contract';
3
5
  import '@orpc/shared';
4
6
  import '@orpc/client/standard';
5
7
  import '@orpc/server';
6
8
  import 'rou3';
7
- import '@orpc/openapi-client/standard';
package/dist/index.d.mts CHANGED
@@ -3,11 +3,17 @@ import { OpenAPIV3_1 } from 'openapi-types';
3
3
  export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
4
4
  import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
5
5
  import { AnyRouter } from '@orpc/server';
6
+ import { Promisable } from '@orpc/shared';
6
7
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
7
8
  export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
8
9
  import { HTTPPath, HTTPMethod } from '@orpc/client';
9
10
 
10
11
  type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
12
+ /**
13
+ * Customize The Operation Object by proxy an error map item or a middleware.
14
+ *
15
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
16
+ */
11
17
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
12
18
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
13
19
  declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
@@ -34,25 +40,35 @@ interface SchemaConvertOptions {
34
40
  strategy: 'input' | 'output';
35
41
  }
36
42
  interface SchemaConverter {
37
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
43
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
38
44
  }
39
45
  interface ConditionalSchemaConverter extends SchemaConverter {
40
- condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean;
46
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
41
47
  }
42
48
  declare class CompositeSchemaConverter implements SchemaConverter {
43
49
  private readonly converters;
44
50
  constructor(converters: ConditionalSchemaConverter[]);
45
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
51
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
46
52
  }
47
53
 
48
54
  interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
49
55
  schemaConverters?: ConditionalSchemaConverter[];
50
56
  }
57
+ /**
58
+ * The generator that converts oRPC routers/contracts to OpenAPI specifications.
59
+ *
60
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
61
+ */
51
62
  declare class OpenAPIGenerator {
52
63
  #private;
53
64
  private readonly serializer;
54
65
  private readonly converter;
55
66
  constructor(options?: OpenAPIGeneratorOptions);
67
+ /**
68
+ * Generates OpenAPI specifications from oRPC routers/contracts.
69
+ *
70
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
71
+ */
56
72
  generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
57
73
  }
58
74
 
@@ -105,9 +121,11 @@ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties:
105
121
  * @internal
106
122
  */
107
123
  declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
124
+ declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
108
125
 
109
126
  declare const oo: {
110
127
  spec: typeof customOpenAPIOperation;
111
128
  };
112
129
 
113
- export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
130
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
131
+ export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter };
package/dist/index.d.ts CHANGED
@@ -3,11 +3,17 @@ import { OpenAPIV3_1 } from 'openapi-types';
3
3
  export { OpenAPIV3_1 as OpenAPI } from 'openapi-types';
4
4
  import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
5
5
  import { AnyRouter } from '@orpc/server';
6
+ import { Promisable } from '@orpc/shared';
6
7
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
7
8
  export { JSONSchema, Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
8
9
  import { HTTPPath, HTTPMethod } from '@orpc/client';
9
10
 
10
11
  type OverrideOperationValue = Partial<OpenAPIV3_1.OperationObject> | ((current: OpenAPIV3_1.OperationObject, procedure: AnyContractProcedure) => OpenAPIV3_1.OperationObject);
12
+ /**
13
+ * Customize The Operation Object by proxy an error map item or a middleware.
14
+ *
15
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification#customizing-operation-objects Customizing Operation Objects Docs}
16
+ */
11
17
  declare function customOpenAPIOperation<T extends object>(o: T, extend: OverrideOperationValue): T;
12
18
  declare function getCustomOpenAPIOperation(o: object): OverrideOperationValue | undefined;
13
19
  declare function applyCustomOpenAPIOperation(operation: OpenAPIV3_1.OperationObject, contract: AnyContractProcedure): OpenAPIV3_1.OperationObject;
@@ -34,25 +40,35 @@ interface SchemaConvertOptions {
34
40
  strategy: 'input' | 'output';
35
41
  }
36
42
  interface SchemaConverter {
37
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
43
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
38
44
  }
39
45
  interface ConditionalSchemaConverter extends SchemaConverter {
40
- condition(schema: AnySchema | undefined, options: SchemaConvertOptions): boolean;
46
+ condition(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<boolean>;
41
47
  }
42
48
  declare class CompositeSchemaConverter implements SchemaConverter {
43
49
  private readonly converters;
44
50
  constructor(converters: ConditionalSchemaConverter[]);
45
- convert(schema: AnySchema | undefined, options: SchemaConvertOptions): [required: boolean, jsonSchema: JSONSchema];
51
+ convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promise<[required: boolean, jsonSchema: JSONSchema]>;
46
52
  }
47
53
 
48
54
  interface OpenAPIGeneratorOptions extends StandardOpenAPIJsonSerializerOptions {
49
55
  schemaConverters?: ConditionalSchemaConverter[];
50
56
  }
57
+ /**
58
+ * The generator that converts oRPC routers/contracts to OpenAPI specifications.
59
+ *
60
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
61
+ */
51
62
  declare class OpenAPIGenerator {
52
63
  #private;
53
64
  private readonly serializer;
54
65
  private readonly converter;
55
66
  constructor(options?: OpenAPIGeneratorOptions);
67
+ /**
68
+ * Generates OpenAPI specifications from oRPC routers/contracts.
69
+ *
70
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
71
+ */
56
72
  generate(router: AnyContractRouter | AnyRouter, base: Omit<OpenAPIV3_1.Document, 'openapi'>): Promise<OpenAPIV3_1.Document>;
57
73
  }
58
74
 
@@ -105,9 +121,11 @@ declare function separateObjectSchema(schema: ObjectSchema, separatedProperties:
105
121
  * @internal
106
122
  */
107
123
  declare function filterSchemaBranches(schema: JSONSchema, check: (schema: JSONSchema) => boolean, matches?: JSONSchema[]): [matches: JSONSchema[], rest: JSONSchema | undefined];
124
+ declare function applySchemaOptionality(required: boolean, schema: JSONSchema): JSONSchema;
108
125
 
109
126
  declare const oo: {
110
127
  spec: typeof customOpenAPIOperation;
111
128
  };
112
129
 
113
- export { CompositeSchemaConverter, type ConditionalSchemaConverter, type FileSchema, LOGIC_KEYWORDS, type ObjectSchema, OpenAPIGenerator, type OpenAPIGeneratorOptions, type OverrideOperationValue, type SchemaConvertOptions, type SchemaConverter, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
130
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
131
+ export type { ConditionalSchemaConverter, FileSchema, ObjectSchema, OpenAPIGeneratorOptions, OverrideOperationValue, SchemaConvertOptions, SchemaConverter };
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@ import { fallbackORPCErrorStatus, fallbackORPCErrorMessage } from '@orpc/client'
3
3
  import { toHttpPath } from '@orpc/client/standard';
4
4
  import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@orpc/contract';
5
5
  import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, getDynamicParams } from '@orpc/openapi-client/standard';
6
- import { isObject, findDeepMatches, clone } from '@orpc/shared';
6
+ import { isObject, findDeepMatches, toArray, clone } from '@orpc/shared';
7
7
  export { Format as JSONSchemaFormat } from 'json-schema-typed/draft-2020-12';
8
8
 
9
9
  const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
@@ -173,6 +173,17 @@ function filterSchemaBranches(schema, check, matches = []) {
173
173
  }
174
174
  return [matches, schema];
175
175
  }
176
+ function applySchemaOptionality(required, schema) {
177
+ if (required) {
178
+ return schema;
179
+ }
180
+ return {
181
+ anyOf: [
182
+ schema,
183
+ { not: {} }
184
+ ]
185
+ };
186
+ }
176
187
 
177
188
  function toOpenAPIPath(path) {
178
189
  return standardizeHTTPPath(path).replace(/\/\{\+([^}]+)\}/g, "/{$1}");
@@ -276,9 +287,9 @@ class CompositeSchemaConverter {
276
287
  constructor(converters) {
277
288
  this.converters = converters;
278
289
  }
279
- convert(schema, options) {
290
+ async convert(schema, options) {
280
291
  for (const converter of this.converters) {
281
- if (converter.condition(schema, options)) {
292
+ if (await converter.condition(schema, options)) {
282
293
  return converter.convert(schema, options);
283
294
  }
284
295
  }
@@ -293,13 +304,22 @@ class OpenAPIGenerator {
293
304
  converter;
294
305
  constructor(options = {}) {
295
306
  this.serializer = new StandardOpenAPIJsonSerializer(options);
296
- this.converter = new CompositeSchemaConverter(options.schemaConverters ?? []);
307
+ this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters));
297
308
  }
309
+ /**
310
+ * Generates OpenAPI specifications from oRPC routers/contracts.
311
+ *
312
+ * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
313
+ */
298
314
  async generate(router, base) {
299
315
  const doc = clone(base);
300
316
  doc.openapi = "3.1.1";
301
- const errors = [];
317
+ const contracts = [];
302
318
  await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
319
+ contracts.push({ contract, path });
320
+ });
321
+ const errors = [];
322
+ for (const { contract, path } of contracts) {
303
323
  const operationId = path.join(".");
304
324
  try {
305
325
  const def = contract["~orpc"];
@@ -312,9 +332,9 @@ class OpenAPIGenerator {
312
332
  deprecated: def.route.deprecated,
313
333
  tags: def.route.tags?.map((tag) => tag)
314
334
  };
315
- this.#request(operationObjectRef, def);
316
- this.#successResponse(operationObjectRef, def);
317
- this.#errorResponse(operationObjectRef, def);
335
+ await this.#request(operationObjectRef, def);
336
+ await this.#successResponse(operationObjectRef, def);
337
+ await this.#errorResponse(operationObjectRef, def);
318
338
  doc.paths ??= {};
319
339
  doc.paths[httpPath] ??= {};
320
340
  doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
@@ -327,7 +347,7 @@ class OpenAPIGenerator {
327
347
  ${e.message}`
328
348
  );
329
349
  }
330
- });
350
+ }
331
351
  if (errors.length) {
332
352
  throw new OpenAPIGeneratorError(
333
353
  `Some error occurred during OpenAPI generation:
@@ -337,22 +357,22 @@ ${errors.join("\n\n")}`
337
357
  }
338
358
  return this.serializer.serialize(doc)[0];
339
359
  }
340
- #request(ref, def) {
360
+ async #request(ref, def) {
341
361
  const method = fallbackContractConfig("defaultMethod", def.route.method);
342
362
  const details = getEventIteratorSchemaDetails(def.inputSchema);
343
363
  if (details) {
344
364
  ref.requestBody = {
345
365
  required: true,
346
366
  content: toOpenAPIEventIteratorContent(
347
- this.converter.convert(details.yields, { strategy: "input" }),
348
- this.converter.convert(details.returns, { strategy: "input" })
367
+ await this.converter.convert(details.yields, { strategy: "input" }),
368
+ await this.converter.convert(details.returns, { strategy: "input" })
349
369
  )
350
370
  };
351
371
  return;
352
372
  }
353
373
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
354
374
  const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
355
- let [required, schema] = this.converter.convert(def.inputSchema, { strategy: "input" });
375
+ let [required, schema] = await this.converter.convert(def.inputSchema, { strategy: "input" });
356
376
  if (isAnySchema(schema) && !dynamicParams?.length) {
357
377
  return;
358
378
  }
@@ -418,7 +438,7 @@ ${errors.join("\n\n")}`
418
438
  };
419
439
  }
420
440
  }
421
- #successResponse(ref, def) {
441
+ async #successResponse(ref, def) {
422
442
  const outputSchema = def.outputSchema;
423
443
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
424
444
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
@@ -429,19 +449,19 @@ ${errors.join("\n\n")}`
429
449
  ref.responses[status] = {
430
450
  description,
431
451
  content: toOpenAPIEventIteratorContent(
432
- this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
433
- this.converter.convert(eventIteratorSchemaDetails.returns, { strategy: "output" })
452
+ await this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
453
+ await this.converter.convert(eventIteratorSchemaDetails.returns, { strategy: "output" })
434
454
  )
435
455
  };
436
456
  return;
437
457
  }
438
- const [_, json] = this.converter.convert(outputSchema, { strategy: "output" });
458
+ const [required, json] = await this.converter.convert(outputSchema, { strategy: "output" });
439
459
  ref.responses ??= {};
440
460
  ref.responses[status] = {
441
461
  description
442
462
  };
443
463
  if (outputStructure === "compact") {
444
- ref.responses[status].content = toOpenAPIContent(json);
464
+ ref.responses[status].content = toOpenAPIContent(applySchemaOptionality(required, json));
445
465
  return;
446
466
  }
447
467
  const error = new OpenAPIGeneratorError(
@@ -463,10 +483,12 @@ ${errors.join("\n\n")}`
463
483
  }
464
484
  }
465
485
  if (json.properties?.body !== void 0) {
466
- ref.responses[status].content = toOpenAPIContent(json.properties.body);
486
+ ref.responses[status].content = toOpenAPIContent(
487
+ applySchemaOptionality(json.required?.includes("body") ?? false, json.properties.body)
488
+ );
467
489
  }
468
490
  }
469
- #errorResponse(ref, def) {
491
+ async #errorResponse(ref, def) {
470
492
  const errorMap = def.errorMap;
471
493
  const errors = {};
472
494
  for (const code in errorMap) {
@@ -476,7 +498,7 @@ ${errors.join("\n\n")}`
476
498
  }
477
499
  const status = fallbackORPCErrorStatus(code, config.status);
478
500
  const message = fallbackORPCErrorMessage(code, config.message);
479
- const [dataRequired, dataSchema] = this.converter.convert(config.data, { strategy: "output" });
501
+ const [dataRequired, dataSchema] = await this.converter.convert(config.data, { strategy: "output" });
480
502
  errors[status] ??= [];
481
503
  errors[status].push({
482
504
  type: "object",
@@ -520,4 +542,4 @@ const oo = {
520
542
  spec: customOpenAPIOperation
521
543
  };
522
544
 
523
- export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
545
+ export { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
@@ -0,0 +1,12 @@
1
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
+ import { Context, Router } from '@orpc/server';
3
+ import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
4
+
5
+ interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
+ }
7
+ declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
8
+ constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
9
+ }
10
+
11
+ export { StandardOpenAPIHandler as a };
12
+ export type { StandardOpenAPIHandlerOptions as S };
@@ -0,0 +1,12 @@
1
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
+ import { Context, Router } from '@orpc/server';
3
+ import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
4
+
5
+ interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
+ }
7
+ declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
8
+ constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
9
+ }
10
+
11
+ export { StandardOpenAPIHandler as a };
12
+ export type { StandardOpenAPIHandlerOptions as S };
@@ -1,9 +1,10 @@
1
+ import { standardizeHTTPPath, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
+ import { StandardHandler } from '@orpc/server/standard';
1
3
  import { fallbackContractConfig } from '@orpc/contract';
2
4
  import { isObject } from '@orpc/shared';
3
5
  import { toHttpPath } from '@orpc/client/standard';
4
6
  import { traverseContractProcedures, isProcedure, getLazyMeta, unlazy, getRouter, createContractedProcedure } from '@orpc/server';
5
7
  import { createRouter, addRoute, findRoute } from 'rou3';
6
- import { standardizeHTTPPath } from '@orpc/openapi-client/standard';
7
8
 
8
9
  class StandardOpenAPICodec {
9
10
  constructor(serializer) {
@@ -143,4 +144,15 @@ class StandardOpenAPIMatcher {
143
144
  }
144
145
  }
145
146
 
146
- export { StandardOpenAPICodec as S, StandardOpenAPIMatcher as a, decodeParams as d, toRou3Pattern as t };
147
+ class StandardOpenAPIHandler extends StandardHandler {
148
+ constructor(router, options) {
149
+ const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
150
+ const bracketNotationSerializer = new StandardBracketNotationSerializer();
151
+ const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
152
+ const matcher = new StandardOpenAPIMatcher();
153
+ const codec = new StandardOpenAPICodec(serializer);
154
+ super(router, matcher, codec, options);
155
+ }
156
+ }
157
+
158
+ export { StandardOpenAPICodec as S, StandardOpenAPIHandler as a, StandardOpenAPIMatcher as b, decodeParams as d, toRou3Pattern as t };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "0.0.0-next.73eeb92",
4
+ "version": "0.0.0-next.7461b74",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -29,16 +29,6 @@
29
29
  "import": "./dist/adapters/fetch/index.mjs",
30
30
  "default": "./dist/adapters/fetch/index.mjs"
31
31
  },
32
- "./hono": {
33
- "types": "./dist/adapters/hono/index.d.mts",
34
- "import": "./dist/adapters/hono/index.mjs",
35
- "default": "./dist/adapters/hono/index.mjs"
36
- },
37
- "./next": {
38
- "types": "./dist/adapters/next/index.d.mts",
39
- "import": "./dist/adapters/next/index.mjs",
40
- "default": "./dist/adapters/next/index.mjs"
41
- },
42
32
  "./node": {
43
33
  "types": "./dist/adapters/node/index.d.mts",
44
34
  "import": "./dist/adapters/node/index.mjs",
@@ -51,13 +41,13 @@
51
41
  "dependencies": {
52
42
  "json-schema-typed": "^8.0.1",
53
43
  "openapi-types": "^12.1.3",
54
- "rou3": "^0.5.1",
55
- "@orpc/client": "0.0.0-next.73eeb92",
56
- "@orpc/server": "0.0.0-next.73eeb92",
57
- "@orpc/shared": "0.0.0-next.73eeb92",
58
- "@orpc/standard-server": "0.0.0-next.73eeb92",
59
- "@orpc/contract": "0.0.0-next.73eeb92",
60
- "@orpc/openapi-client": "0.0.0-next.73eeb92"
44
+ "rou3": "^0.6.0",
45
+ "@orpc/client": "0.0.0-next.7461b74",
46
+ "@orpc/contract": "0.0.0-next.7461b74",
47
+ "@orpc/openapi-client": "0.0.0-next.7461b74",
48
+ "@orpc/server": "0.0.0-next.7461b74",
49
+ "@orpc/shared": "0.0.0-next.7461b74",
50
+ "@orpc/standard-server": "0.0.0-next.7461b74"
61
51
  },
62
52
  "devDependencies": {
63
53
  "zod": "^3.24.2"
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.mjs';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.mjs';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.js';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.js';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,10 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.CGZ7t-VN.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '../../shared/openapi.sdeu0I7N.mjs';
6
- import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/client/standard';
9
- import '@orpc/server';
10
- import 'rou3';
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.mjs';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.mjs';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,6 +0,0 @@
1
- export { OpenAPIHandler } from '../fetch/index.js';
2
- import '@orpc/server';
3
- import '@orpc/server/fetch';
4
- import '../../shared/openapi.IfmmOyba.js';
5
- import '@orpc/openapi-client/standard';
6
- import '@orpc/server/standard';
@@ -1,10 +0,0 @@
1
- export { O as OpenAPIHandler } from '../../shared/openapi.CGZ7t-VN.mjs';
2
- import '@orpc/openapi-client/standard';
3
- import '@orpc/server/fetch';
4
- import '@orpc/server/standard';
5
- import '../../shared/openapi.sdeu0I7N.mjs';
6
- import '@orpc/contract';
7
- import '@orpc/shared';
8
- import '@orpc/client/standard';
9
- import '@orpc/server';
10
- import 'rou3';
@@ -1,17 +0,0 @@
1
- import { StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer, StandardOpenAPISerializer } from '@orpc/openapi-client/standard';
2
- import { FetchHandler } from '@orpc/server/fetch';
3
- import { StandardHandler } from '@orpc/server/standard';
4
- import { a as StandardOpenAPIMatcher, S as StandardOpenAPICodec } from './openapi.sdeu0I7N.mjs';
5
-
6
- class OpenAPIHandler extends FetchHandler {
7
- constructor(router, options = {}) {
8
- const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
9
- const bracketNotationSerializer = new StandardBracketNotationSerializer();
10
- const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
11
- const matcher = new StandardOpenAPIMatcher();
12
- const codec = new StandardOpenAPICodec(serializer);
13
- super(new StandardHandler(router, matcher, codec, options), options);
14
- }
15
- }
16
-
17
- export { OpenAPIHandler as O };
@@ -1,8 +0,0 @@
1
- import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
- import { Context } from '@orpc/server';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
-
5
- interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardOpenAPIHandlerOptions as S };
@@ -1,8 +0,0 @@
1
- import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
- import { Context } from '@orpc/server';
3
- import { StandardHandlerOptions } from '@orpc/server/standard';
4
-
5
- interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
- }
7
-
8
- export type { StandardOpenAPIHandlerOptions as S };