@orpc/openapi 1.0.0-beta.7 → 1.0.3

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
 
@@ -4,6 +4,12 @@ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9
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
  }
@@ -4,6 +4,12 @@ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9
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
  }
@@ -4,6 +4,12 @@ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9
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
  }
@@ -4,6 +4,12 @@ import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.D3j94c9
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
  }
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
 
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
 
package/dist/index.mjs CHANGED
@@ -287,9 +287,9 @@ class CompositeSchemaConverter {
287
287
  constructor(converters) {
288
288
  this.converters = converters;
289
289
  }
290
- convert(schema, options) {
290
+ async convert(schema, options) {
291
291
  for (const converter of this.converters) {
292
- if (converter.condition(schema, options)) {
292
+ if (await converter.condition(schema, options)) {
293
293
  return converter.convert(schema, options);
294
294
  }
295
295
  }
@@ -306,11 +306,20 @@ class OpenAPIGenerator {
306
306
  this.serializer = new StandardOpenAPIJsonSerializer(options);
307
307
  this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters));
308
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
+ */
309
314
  async generate(router, base) {
310
315
  const doc = clone(base);
311
316
  doc.openapi = "3.1.1";
312
- const errors = [];
317
+ const contracts = [];
313
318
  await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
319
+ contracts.push({ contract, path });
320
+ });
321
+ const errors = [];
322
+ for (const { contract, path } of contracts) {
314
323
  const operationId = path.join(".");
315
324
  try {
316
325
  const def = contract["~orpc"];
@@ -323,9 +332,9 @@ class OpenAPIGenerator {
323
332
  deprecated: def.route.deprecated,
324
333
  tags: def.route.tags?.map((tag) => tag)
325
334
  };
326
- this.#request(operationObjectRef, def);
327
- this.#successResponse(operationObjectRef, def);
328
- this.#errorResponse(operationObjectRef, def);
335
+ await this.#request(operationObjectRef, def);
336
+ await this.#successResponse(operationObjectRef, def);
337
+ await this.#errorResponse(operationObjectRef, def);
329
338
  doc.paths ??= {};
330
339
  doc.paths[httpPath] ??= {};
331
340
  doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
@@ -338,7 +347,7 @@ class OpenAPIGenerator {
338
347
  ${e.message}`
339
348
  );
340
349
  }
341
- });
350
+ }
342
351
  if (errors.length) {
343
352
  throw new OpenAPIGeneratorError(
344
353
  `Some error occurred during OpenAPI generation:
@@ -348,22 +357,22 @@ ${errors.join("\n\n")}`
348
357
  }
349
358
  return this.serializer.serialize(doc)[0];
350
359
  }
351
- #request(ref, def) {
360
+ async #request(ref, def) {
352
361
  const method = fallbackContractConfig("defaultMethod", def.route.method);
353
362
  const details = getEventIteratorSchemaDetails(def.inputSchema);
354
363
  if (details) {
355
364
  ref.requestBody = {
356
365
  required: true,
357
366
  content: toOpenAPIEventIteratorContent(
358
- this.converter.convert(details.yields, { strategy: "input" }),
359
- 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" })
360
369
  )
361
370
  };
362
371
  return;
363
372
  }
364
373
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
365
374
  const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
366
- let [required, schema] = this.converter.convert(def.inputSchema, { strategy: "input" });
375
+ let [required, schema] = await this.converter.convert(def.inputSchema, { strategy: "input" });
367
376
  if (isAnySchema(schema) && !dynamicParams?.length) {
368
377
  return;
369
378
  }
@@ -429,7 +438,7 @@ ${errors.join("\n\n")}`
429
438
  };
430
439
  }
431
440
  }
432
- #successResponse(ref, def) {
441
+ async #successResponse(ref, def) {
433
442
  const outputSchema = def.outputSchema;
434
443
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
435
444
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
@@ -440,13 +449,13 @@ ${errors.join("\n\n")}`
440
449
  ref.responses[status] = {
441
450
  description,
442
451
  content: toOpenAPIEventIteratorContent(
443
- this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
444
- 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" })
445
454
  )
446
455
  };
447
456
  return;
448
457
  }
449
- const [required, json] = this.converter.convert(outputSchema, { strategy: "output" });
458
+ const [required, json] = await this.converter.convert(outputSchema, { strategy: "output" });
450
459
  ref.responses ??= {};
451
460
  ref.responses[status] = {
452
461
  description
@@ -479,7 +488,7 @@ ${errors.join("\n\n")}`
479
488
  );
480
489
  }
481
490
  }
482
- #errorResponse(ref, def) {
491
+ async #errorResponse(ref, def) {
483
492
  const errorMap = def.errorMap;
484
493
  const errors = {};
485
494
  for (const code in errorMap) {
@@ -489,7 +498,7 @@ ${errors.join("\n\n")}`
489
498
  }
490
499
  const status = fallbackORPCErrorStatus(code, config.status);
491
500
  const message = fallbackORPCErrorMessage(code, config.message);
492
- const [dataRequired, dataSchema] = this.converter.convert(config.data, { strategy: "output" });
501
+ const [dataRequired, dataSchema] = await this.converter.convert(config.data, { strategy: "output" });
493
502
  errors[status] ??= [];
494
503
  errors[status].push({
495
504
  type: "object",
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "1.0.0-beta.7",
4
+ "version": "1.0.3",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -42,12 +42,12 @@
42
42
  "json-schema-typed": "^8.0.1",
43
43
  "openapi-types": "^12.1.3",
44
44
  "rou3": "^0.5.1",
45
- "@orpc/client": "1.0.0-beta.7",
46
- "@orpc/contract": "1.0.0-beta.7",
47
- "@orpc/server": "1.0.0-beta.7",
48
- "@orpc/shared": "1.0.0-beta.7",
49
- "@orpc/openapi-client": "1.0.0-beta.7",
50
- "@orpc/standard-server": "1.0.0-beta.7"
45
+ "@orpc/client": "1.0.3",
46
+ "@orpc/openapi-client": "1.0.3",
47
+ "@orpc/server": "1.0.3",
48
+ "@orpc/shared": "1.0.3",
49
+ "@orpc/contract": "1.0.3",
50
+ "@orpc/standard-server": "1.0.3"
51
51
  },
52
52
  "devDependencies": {
53
53
  "zod": "^3.24.2"