@orpc/openapi 0.0.0-next.865fe1f → 0.0.0-next.8719bd7

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
@@ -30,7 +30,7 @@
30
30
  - **🔗 End-to-End Type Safety**: Ensure type-safe inputs, outputs, and errors from client to server.
31
31
  - **📘 First-Class OpenAPI**: Built-in support that fully adheres to the OpenAPI standard.
32
32
  - **📝 Contract-First Development**: Optionally define your API contract before implementation.
33
- - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), Pinia Colada, and more.
33
+ - **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte), Pinia Colada, and more.
34
34
  - **🚀 Server Actions**: Fully compatible with React Server Actions on Next.js, TanStack Start, and other platforms.
35
35
  - **🔠 Standard Schema Support**: Works out of the box with Zod, Valibot, ArkType, and other schema validators.
36
36
  - **🗃️ Native Types**: Supports native types like Date, File, Blob, BigInt, URL, and more.
@@ -1,6 +1,6 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { AwsLambdaHandler, AwsLambdaHandlerOptions } from '@orpc/server/aws-lambda';
3
- import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.BWrlhfev.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
 
@@ -1,6 +1,6 @@
1
1
  import { Context, Router } from '@orpc/server';
2
2
  import { AwsLambdaHandler, AwsLambdaHandlerOptions } from '@orpc/server/aws-lambda';
3
- import { S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.BWrlhfev.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
 
@@ -2,7 +2,7 @@ import { AwsLambdaHandler } from '@orpc/server/aws-lambda';
2
2
  import '@orpc/client';
3
3
  import '@orpc/contract';
4
4
  import '@orpc/shared';
5
- import { a as StandardOpenAPIHandler } from '../../shared/openapi.-sXpEIAO.mjs';
5
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
6
6
  import '@orpc/client/standard';
7
7
  import '@orpc/server';
8
8
  import 'rou3';
@@ -1,6 +1,6 @@
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.BWrlhfev.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
 
@@ -1,6 +1,6 @@
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.BWrlhfev.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
 
@@ -2,7 +2,7 @@ import { FetchHandler } from '@orpc/server/fetch';
2
2
  import '@orpc/client';
3
3
  import '@orpc/contract';
4
4
  import '@orpc/shared';
5
- import { a as StandardOpenAPIHandler } from '../../shared/openapi.-sXpEIAO.mjs';
5
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
6
6
  import '@orpc/client/standard';
7
7
  import '@orpc/server';
8
8
  import 'rou3';
@@ -1,6 +1,6 @@
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.BWrlhfev.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
 
@@ -1,6 +1,6 @@
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.BWrlhfev.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
 
@@ -2,7 +2,7 @@ import { NodeHttpHandler } from '@orpc/server/node';
2
2
  import '@orpc/client';
3
3
  import '@orpc/contract';
4
4
  import '@orpc/shared';
5
- import { a as StandardOpenAPIHandler } from '../../shared/openapi.-sXpEIAO.mjs';
5
+ import { a as StandardOpenAPIHandler } from '../../shared/openapi.C_UtQ8Us.mjs';
6
6
  import '@orpc/client/standard';
7
7
  import '@orpc/server';
8
8
  import 'rou3';
@@ -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 { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.BWrlhfev.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;
@@ -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 { a as StandardOpenAPIHandler, S as StandardOpenAPIHandlerOptions } from '../../shared/openapi.BWrlhfev.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;
@@ -1,4 +1,4 @@
1
- export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.-sXpEIAO.mjs';
1
+ export { S as StandardOpenAPICodec, a as StandardOpenAPIHandler, b as StandardOpenAPIMatcher, d as decodeParams, t as toRou3Pattern } from '../../shared/openapi.C_UtQ8Us.mjs';
2
2
  import '@orpc/openapi-client/standard';
3
3
  import '@orpc/server/standard';
4
4
  import '@orpc/client';
package/dist/index.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
2
2
  export { OpenAPI } from '@orpc/contract';
3
- export { e as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, c as SchemaConvertOptions, d as SchemaConverter, S as SchemaConverterComponent } from './shared/openapi.B3hexduL.mjs';
3
+ export { d as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, S as SchemaConvertOptions, c as SchemaConverter } from './shared/openapi.qZLdpE0a.mjs';
4
4
  import { HTTPPath, HTTPMethod } from '@orpc/client';
5
5
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
6
  export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
@@ -65,7 +65,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
65
65
  * @internal
66
66
  */
67
67
  declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
68
- declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
69
68
 
70
69
  declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
71
70
 
@@ -106,5 +105,5 @@ declare const oo: {
106
105
  spec: typeof customOpenAPIOperation;
107
106
  };
108
107
 
109
- export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
108
+ export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
110
109
  export type { FileSchema, ObjectSchema, OverrideOperationValue };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { OpenAPI, AnyContractProcedure } from '@orpc/contract';
2
2
  export { OpenAPI } from '@orpc/contract';
3
- export { e as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, c as SchemaConvertOptions, d as SchemaConverter, S as SchemaConverterComponent } from './shared/openapi.B3hexduL.js';
3
+ export { d as CompositeSchemaConverter, C as ConditionalSchemaConverter, b as OpenAPIGenerator, a as OpenAPIGeneratorGenerateOptions, O as OpenAPIGeneratorOptions, S as SchemaConvertOptions, c as SchemaConverter } from './shared/openapi.qZLdpE0a.js';
4
4
  import { HTTPPath, HTTPMethod } from '@orpc/client';
5
5
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
6
  export { JSONSchema, ContentEncoding as JSONSchemaContentEncoding, Format as JSONSchemaFormat, TypeName as JSONSchemaTypeName } from 'json-schema-typed/draft-2020-12';
@@ -65,7 +65,6 @@ declare function checkParamsSchema(schema: ObjectSchema, params: string[]): bool
65
65
  * @internal
66
66
  */
67
67
  declare function toOpenAPISchema(schema: JSONSchema): OpenAPI.SchemaObject & object;
68
- declare function resolveOpenAPIJsonSchemaRef(doc: OpenAPI.Document, schema: JSONSchema): JSONSchema;
69
68
 
70
69
  declare function createJsonifiedRouterClient<T extends AnyRouter, TClientContext extends ClientContext>(router: Lazyable<T | undefined>, ...rest: MaybeOptionalOptions<CreateProcedureClientOptions<InferRouterInitialContext<T>, Schema<unknown, unknown>, ErrorMap, Meta, TClientContext>>): JsonifiedClient<RouterClient<T, TClientContext>>;
71
70
 
@@ -106,5 +105,5 @@ declare const oo: {
106
105
  spec: typeof customOpenAPIOperation;
107
106
  };
108
107
 
109
- export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
108
+ export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, createJsonifiedRouterClient, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
110
109
  export type { FileSchema, ObjectSchema, OverrideOperationValue };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as customOpenAPIOperation } from './shared/openapi.DrrBsJ0w.mjs';
2
- export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation, n as applySchemaOptionality, h as checkParamsSchema, p as expandArrayableSchema, o as expandUnionSchema, m as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, k as isObjectSchema, q as isPrimitiveSchema, r as resolveOpenAPIJsonSchemaRef, s as separateObjectSchema, d as toOpenAPIContent, e as toOpenAPIEventIteratorContent, b as toOpenAPIMethod, f as toOpenAPIParameters, t as toOpenAPIPath, i as toOpenAPISchema } from './shared/openapi.DrrBsJ0w.mjs';
1
+ import { c as customOpenAPIOperation } from './shared/openapi.DaYgbD_w.mjs';
2
+ export { C as CompositeSchemaConverter, L as LOGIC_KEYWORDS, O as OpenAPIGenerator, a as applyCustomOpenAPIOperation, n as applySchemaOptionality, h as checkParamsSchema, p as expandArrayableSchema, o as expandUnionSchema, m as filterSchemaBranches, g as getCustomOpenAPIOperation, l as isAnySchema, j as isFileSchema, k as isObjectSchema, q as isPrimitiveSchema, s as separateObjectSchema, d as toOpenAPIContent, e as toOpenAPIEventIteratorContent, b as toOpenAPIMethod, f as toOpenAPIParameters, t as toOpenAPIPath, i as toOpenAPISchema } from './shared/openapi.DaYgbD_w.mjs';
3
3
  import { createORPCErrorFromJson } from '@orpc/client';
4
4
  import { StandardOpenAPISerializer, StandardOpenAPIJsonSerializer, StandardBracketNotationSerializer } from '@orpc/openapi-client/standard';
5
5
  import { ORPCError, createRouterClient } from '@orpc/server';
@@ -2,7 +2,7 @@ import { OpenAPI } from '@orpc/contract';
2
2
  import { Context, HTTPPath, Router } from '@orpc/server';
3
3
  import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
4
4
  import { Value, Promisable } from '@orpc/shared';
5
- import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.B3hexduL.mjs';
5
+ import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.qZLdpE0a.mjs';
6
6
  import '@orpc/openapi-client/standard';
7
7
  import 'json-schema-typed/draft-2020-12';
8
8
 
@@ -2,7 +2,7 @@ import { OpenAPI } from '@orpc/contract';
2
2
  import { Context, HTTPPath, Router } from '@orpc/server';
3
3
  import { StandardHandlerInterceptorOptions, StandardHandlerPlugin, StandardHandlerOptions } from '@orpc/server/standard';
4
4
  import { Value, Promisable } from '@orpc/shared';
5
- import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.B3hexduL.js';
5
+ import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.qZLdpE0a.js';
6
6
  import '@orpc/openapi-client/standard';
7
7
  import 'json-schema-typed/draft-2020-12';
8
8
 
@@ -1,5 +1,5 @@
1
1
  import { stringifyJSON, once, value } from '@orpc/shared';
2
- import { O as OpenAPIGenerator } from '../shared/openapi.DrrBsJ0w.mjs';
2
+ import { O as OpenAPIGenerator } from '../shared/openapi.DaYgbD_w.mjs';
3
3
  import '@orpc/client';
4
4
  import '@orpc/client/standard';
5
5
  import '@orpc/contract';
@@ -168,7 +168,7 @@ class StandardOpenAPIMatcher {
168
168
  class StandardOpenAPIHandler extends StandardHandler {
169
169
  constructor(router, options) {
170
170
  const jsonSerializer = new StandardOpenAPIJsonSerializer(options);
171
- const bracketNotationSerializer = new StandardBracketNotationSerializer(options);
171
+ const bracketNotationSerializer = new StandardBracketNotationSerializer();
172
172
  const serializer = new StandardOpenAPISerializer(jsonSerializer, bracketNotationSerializer);
173
173
  const matcher = new StandardOpenAPIMatcher();
174
174
  const codec = new StandardOpenAPICodec(serializer);
@@ -1,8 +1,8 @@
1
- import { StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
1
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
2
  import { Context, Router } from '@orpc/server';
3
3
  import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
4
4
 
5
- interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions {
5
+ interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
6
  }
7
7
  declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
8
8
  constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
@@ -1,8 +1,8 @@
1
- import { StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions } from '@orpc/openapi-client/standard';
1
+ import { StandardOpenAPIJsonSerializerOptions } from '@orpc/openapi-client/standard';
2
2
  import { Context, Router } from '@orpc/server';
3
3
  import { StandardHandlerOptions, StandardHandler } from '@orpc/server/standard';
4
4
 
5
- interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions, StandardBracketNotationSerializerOptions {
5
+ interface StandardOpenAPIHandlerOptions<T extends Context> extends StandardHandlerOptions<T>, StandardOpenAPIJsonSerializerOptions {
6
6
  }
7
7
  declare class StandardOpenAPIHandler<T extends Context> extends StandardHandler<T> {
8
8
  constructor(router: Router<any, T>, options: NoInfer<StandardOpenAPIHandlerOptions<T>>);
@@ -345,15 +345,6 @@ function checkParamsSchema(schema, params) {
345
345
  function toOpenAPISchema(schema) {
346
346
  return schema === true ? {} : schema === false ? { not: {} } : schema;
347
347
  }
348
- const OPENAPI_JSON_SCHEMA_REF_PREFIX = "#/components/schemas/";
349
- function resolveOpenAPIJsonSchemaRef(doc, schema) {
350
- if (typeof schema !== "object" || !schema.$ref?.startsWith(OPENAPI_JSON_SCHEMA_REF_PREFIX)) {
351
- return schema;
352
- }
353
- const name = schema.$ref.slice(OPENAPI_JSON_SCHEMA_REF_PREFIX.length);
354
- const resolved = doc.components?.schemas?.[name];
355
- return resolved ?? schema;
356
- }
357
348
 
358
349
  class CompositeSchemaConverter {
359
350
  converters;
@@ -390,10 +381,8 @@ class OpenAPIGenerator {
390
381
  ...clone(options),
391
382
  info: options.info ?? { title: "API Reference", version: "0.0.0" },
392
383
  openapi: "3.1.1",
393
- exclude: void 0,
394
- commonSchemas: void 0
384
+ exclude: void 0
395
385
  };
396
- const { baseSchemaConvertOptions, undefinedErrorJsonSchema } = await this.#resolveCommonSchemas(doc, options.commonSchemas);
397
386
  const contracts = [];
398
387
  await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
399
388
  if (!exclude(contract, path)) {
@@ -418,9 +407,9 @@ class OpenAPIGenerator {
418
407
  deprecated: def.route.deprecated,
419
408
  tags: def.route.tags?.map((tag) => tag)
420
409
  };
421
- await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
422
- await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
423
- await this.#errorResponse(operationObjectRef, def, baseSchemaConvertOptions, undefinedErrorJsonSchema);
410
+ await this.#request(operationObjectRef, def);
411
+ await this.#successResponse(operationObjectRef, def);
412
+ await this.#errorResponse(operationObjectRef, def);
424
413
  }
425
414
  doc.paths ??= {};
426
415
  doc.paths[httpPath] ??= {};
@@ -444,96 +433,22 @@ ${errors.join("\n\n")}`
444
433
  }
445
434
  return this.serializer.serialize(doc)[0];
446
435
  }
447
- async #resolveCommonSchemas(doc, commonSchemas) {
448
- let undefinedErrorJsonSchema = {
449
- type: "object",
450
- properties: {
451
- defined: { const: false },
452
- code: { type: "string" },
453
- status: { type: "number" },
454
- message: { type: "string" },
455
- data: {}
456
- },
457
- required: ["defined", "code", "status", "message"]
458
- };
459
- const baseSchemaConvertOptions = {};
460
- if (commonSchemas) {
461
- baseSchemaConvertOptions.components = [];
462
- for (const key in commonSchemas) {
463
- const options = commonSchemas[key];
464
- if (options.schema === void 0) {
465
- continue;
466
- }
467
- const { schema, strategy = "input" } = options;
468
- const [required, json] = await this.converter.convert(schema, { strategy });
469
- const allowedStrategies = [strategy];
470
- if (strategy === "input") {
471
- const [outputRequired, outputJson] = await this.converter.convert(schema, { strategy: "output" });
472
- if (outputRequired === required && stringifyJSON(outputJson) === stringifyJSON(json)) {
473
- allowedStrategies.push("output");
474
- }
475
- } else if (strategy === "output") {
476
- const [inputRequired, inputJson] = await this.converter.convert(schema, { strategy: "input" });
477
- if (inputRequired === required && stringifyJSON(inputJson) === stringifyJSON(json)) {
478
- allowedStrategies.push("input");
479
- }
480
- }
481
- baseSchemaConvertOptions.components.push({
482
- schema,
483
- required,
484
- ref: `#/components/schemas/${key}`,
485
- allowedStrategies
486
- });
487
- }
488
- doc.components ??= {};
489
- doc.components.schemas ??= {};
490
- for (const key in commonSchemas) {
491
- const options = commonSchemas[key];
492
- if (options.schema === void 0) {
493
- if (options.error === "UndefinedError") {
494
- doc.components.schemas[key] = toOpenAPISchema(undefinedErrorJsonSchema);
495
- undefinedErrorJsonSchema = { $ref: `#/components/schemas/${key}` };
496
- }
497
- continue;
498
- }
499
- const { schema, strategy = "input" } = options;
500
- const [, json] = await this.converter.convert(
501
- schema,
502
- {
503
- ...baseSchemaConvertOptions,
504
- strategy,
505
- minStructureDepthForRef: 1
506
- // not allow use $ref for root schemas
507
- }
508
- );
509
- doc.components.schemas[key] = toOpenAPISchema(json);
510
- }
511
- }
512
- return { baseSchemaConvertOptions, undefinedErrorJsonSchema };
513
- }
514
- async #request(doc, ref, def, baseSchemaConvertOptions) {
436
+ async #request(ref, def) {
515
437
  const method = fallbackContractConfig("defaultMethod", def.route.method);
516
438
  const details = getEventIteratorSchemaDetails(def.inputSchema);
517
439
  if (details) {
518
440
  ref.requestBody = {
519
441
  required: true,
520
442
  content: toOpenAPIEventIteratorContent(
521
- await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
522
- await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
443
+ await this.converter.convert(details.yields, { strategy: "input" }),
444
+ await this.converter.convert(details.returns, { strategy: "input" })
523
445
  )
524
446
  };
525
447
  return;
526
448
  }
527
449
  const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
528
450
  const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
529
- let [required, schema] = await this.converter.convert(
530
- def.inputSchema,
531
- {
532
- ...baseSchemaConvertOptions,
533
- strategy: "input",
534
- minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
535
- }
536
- );
451
+ let [required, schema] = await this.converter.convert(def.inputSchema, { strategy: "input" });
537
452
  if (isAnySchema(schema) && !dynamicParams?.length) {
538
453
  return;
539
454
  }
@@ -576,8 +491,7 @@ ${errors.join("\n\n")}`
576
491
  if (!isObjectSchema(schema)) {
577
492
  throw error;
578
493
  }
579
- const resolvedParamSchema = schema.properties?.params !== void 0 ? resolveOpenAPIJsonSchemaRef(doc, schema.properties.params) : void 0;
580
- if (dynamicParams?.length && (resolvedParamSchema === void 0 || !isObjectSchema(resolvedParamSchema) || !checkParamsSchema(resolvedParamSchema, dynamicParams))) {
494
+ if (dynamicParams?.length && (schema.properties?.params === void 0 || !isObjectSchema(schema.properties.params) || !checkParamsSchema(schema.properties.params, dynamicParams))) {
581
495
  throw new OpenAPIGeneratorError(
582
496
  'When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.'
583
497
  );
@@ -585,13 +499,12 @@ ${errors.join("\n\n")}`
585
499
  for (const from of ["params", "query", "headers"]) {
586
500
  const fromSchema = schema.properties?.[from];
587
501
  if (fromSchema !== void 0) {
588
- const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, fromSchema);
589
- if (!isObjectSchema(resolvedSchema)) {
502
+ if (!isObjectSchema(fromSchema)) {
590
503
  throw error;
591
504
  }
592
505
  const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
593
506
  ref.parameters ??= [];
594
- ref.parameters.push(...toOpenAPIParameters(resolvedSchema, parameterIn));
507
+ ref.parameters.push(...toOpenAPIParameters(fromSchema, parameterIn));
595
508
  }
596
509
  }
597
510
  if (schema.properties?.body !== void 0) {
@@ -601,7 +514,7 @@ ${errors.join("\n\n")}`
601
514
  };
602
515
  }
603
516
  }
604
- async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
517
+ async #successResponse(ref, def) {
605
518
  const outputSchema = def.outputSchema;
606
519
  const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
607
520
  const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
@@ -612,20 +525,13 @@ ${errors.join("\n\n")}`
612
525
  ref.responses[status] = {
613
526
  description,
614
527
  content: toOpenAPIEventIteratorContent(
615
- await this.converter.convert(eventIteratorSchemaDetails.yields, { ...baseSchemaConvertOptions, strategy: "output" }),
616
- await this.converter.convert(eventIteratorSchemaDetails.returns, { ...baseSchemaConvertOptions, strategy: "output" })
528
+ await this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
529
+ await this.converter.convert(eventIteratorSchemaDetails.returns, { strategy: "output" })
617
530
  )
618
531
  };
619
532
  return;
620
533
  }
621
- const [required, json] = await this.converter.convert(
622
- outputSchema,
623
- {
624
- ...baseSchemaConvertOptions,
625
- strategy: "output",
626
- minStructureDepthForRef: outputStructure === "detailed" ? 1 : 0
627
- }
628
- );
534
+ const [required, json] = await this.converter.convert(outputSchema, { strategy: "output" });
629
535
  if (outputStructure === "compact") {
630
536
  ref.responses ??= {};
631
537
  ref.responses[status] = {
@@ -652,12 +558,11 @@ ${errors.join("\n\n")}`
652
558
  let schemaStatus;
653
559
  let schemaDescription;
654
560
  if (item.properties?.status !== void 0) {
655
- const statusSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.status);
656
- if (typeof statusSchema !== "object" || statusSchema.const === void 0 || typeof statusSchema.const !== "number" || !Number.isInteger(statusSchema.const) || isORPCErrorStatus(statusSchema.const)) {
561
+ if (typeof item.properties.status !== "object" || item.properties.status.const === void 0 || typeof item.properties.status.const !== "number" || !Number.isInteger(item.properties.status.const) || isORPCErrorStatus(item.properties.status.const)) {
657
562
  throw error;
658
563
  }
659
- schemaStatus = statusSchema.const;
660
- schemaDescription = statusSchema.description;
564
+ schemaStatus = item.properties.status.const;
565
+ schemaDescription = item.properties.status.description;
661
566
  }
662
567
  const itemStatus = schemaStatus ?? status;
663
568
  const itemDescription = schemaDescription ?? description;
@@ -673,17 +578,16 @@ ${errors.join("\n\n")}`
673
578
  description: itemDescription
674
579
  };
675
580
  if (item.properties?.headers !== void 0) {
676
- const headersSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.headers);
677
- if (!isObjectSchema(headersSchema)) {
581
+ if (!isObjectSchema(item.properties.headers)) {
678
582
  throw error;
679
583
  }
680
- for (const key in headersSchema.properties) {
681
- const headerSchema = headersSchema.properties[key];
584
+ for (const key in item.properties.headers.properties) {
585
+ const headerSchema = item.properties.headers.properties[key];
682
586
  if (headerSchema !== void 0) {
683
587
  ref.responses[itemStatus].headers ??= {};
684
588
  ref.responses[itemStatus].headers[key] = {
685
589
  schema: toOpenAPISchema(headerSchema),
686
- required: item.required?.includes("headers") && headersSchema.required?.includes(key)
590
+ required: item.properties.headers.required?.includes(key)
687
591
  };
688
592
  }
689
593
  }
@@ -695,7 +599,7 @@ ${errors.join("\n\n")}`
695
599
  }
696
600
  }
697
601
  }
698
- async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
602
+ async #errorResponse(ref, def) {
699
603
  const errorMap = def.errorMap;
700
604
  const errors = {};
701
605
  for (const code in errorMap) {
@@ -705,7 +609,7 @@ ${errors.join("\n\n")}`
705
609
  }
706
610
  const status = fallbackORPCErrorStatus(code, config.status);
707
611
  const message = fallbackORPCErrorMessage(code, config.message);
708
- const [dataRequired, dataSchema] = await this.converter.convert(config.data, { ...baseSchemaConvertOptions, strategy: "output" });
612
+ const [dataRequired, dataSchema] = await this.converter.convert(config.data, { strategy: "output" });
709
613
  errors[status] ??= [];
710
614
  errors[status].push({
711
615
  type: "object",
@@ -727,7 +631,17 @@ ${errors.join("\n\n")}`
727
631
  content: toOpenAPIContent({
728
632
  oneOf: [
729
633
  ...schemas,
730
- undefinedErrorSchema
634
+ {
635
+ type: "object",
636
+ properties: {
637
+ defined: { const: false },
638
+ code: { type: "string" },
639
+ status: { type: "number" },
640
+ message: { type: "string" },
641
+ data: {}
642
+ },
643
+ required: ["defined", "code", "status", "message"]
644
+ }
731
645
  ]
732
646
  })
733
647
  };
@@ -735,4 +649,4 @@ ${errors.join("\n\n")}`
735
649
  }
736
650
  }
737
651
 
738
- export { CompositeSchemaConverter as C, LOGIC_KEYWORDS as L, OpenAPIGenerator as O, applyCustomOpenAPIOperation as a, toOpenAPIMethod as b, customOpenAPIOperation as c, toOpenAPIContent as d, toOpenAPIEventIteratorContent as e, toOpenAPIParameters as f, getCustomOpenAPIOperation as g, checkParamsSchema as h, toOpenAPISchema as i, isFileSchema as j, isObjectSchema as k, isAnySchema as l, filterSchemaBranches as m, applySchemaOptionality as n, expandUnionSchema as o, expandArrayableSchema as p, isPrimitiveSchema as q, resolveOpenAPIJsonSchemaRef as r, separateObjectSchema as s, toOpenAPIPath as t };
652
+ export { CompositeSchemaConverter as C, LOGIC_KEYWORDS as L, OpenAPIGenerator as O, applyCustomOpenAPIOperation as a, toOpenAPIMethod as b, customOpenAPIOperation as c, toOpenAPIContent as d, toOpenAPIEventIteratorContent as e, toOpenAPIParameters as f, getCustomOpenAPIOperation as g, checkParamsSchema as h, toOpenAPISchema as i, isFileSchema as j, isObjectSchema as k, isAnySchema as l, filterSchemaBranches as m, applySchemaOptionality as n, expandUnionSchema as o, expandArrayableSchema as p, isPrimitiveSchema as q, separateObjectSchema as s, toOpenAPIPath as t };
@@ -4,26 +4,8 @@ import { AnyProcedure, AnyRouter } from '@orpc/server';
4
4
  import { Promisable } from '@orpc/shared';
5
5
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
6
 
7
- interface SchemaConverterComponent {
8
- allowedStrategies: readonly SchemaConvertOptions['strategy'][];
9
- schema: AnySchema;
10
- required: boolean;
11
- ref: string;
12
- }
13
7
  interface SchemaConvertOptions {
14
8
  strategy: 'input' | 'output';
15
- /**
16
- * Common components should use `$ref` to represent themselves if matched.
17
- */
18
- components?: readonly SchemaConverterComponent[];
19
- /**
20
- * Minimum schema structure depth required before using `$ref` for components.
21
- *
22
- * For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
23
- *
24
- * @default 0 - No depth limit;
25
- */
26
- minStructureDepthForRef?: number;
27
9
  }
28
10
  interface SchemaConverter {
29
11
  convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
@@ -47,37 +29,6 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
47
29
  * @default () => false
48
30
  */
49
31
  exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
50
- /**
51
- * Common schemas to be used for $ref resolution.
52
- */
53
- commonSchemas?: Record<string, {
54
- /**
55
- * Determines which schema definition to use when input and output schemas differ.
56
- * This is needed because some schemas transform data differently between input and output,
57
- * making it impossible to use a single $ref for both cases.
58
- *
59
- * @example
60
- * ```ts
61
- * // This schema transforms a string input into a number output
62
- * const Schema = z.string()
63
- * .transform(v => Number(v))
64
- * .pipe(z.number())
65
- *
66
- * // Input schema: { type: 'string' }
67
- * // Output schema: { type: 'number' }
68
- * ```
69
- *
70
- * When schemas differ between input and output, you must explicitly choose
71
- * which version to use for the OpenAPI specification.
72
- *
73
- * @default 'input' - Uses the input schema definition by default
74
- */
75
- strategy?: SchemaConvertOptions['strategy'];
76
- schema: AnySchema;
77
- } | {
78
- error: 'UndefinedError';
79
- schema?: never;
80
- }>;
81
32
  }
82
33
  /**
83
34
  * The generator that converts oRPC routers/contracts to OpenAPI specifications.
@@ -97,5 +48,5 @@ declare class OpenAPIGenerator {
97
48
  generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
98
49
  }
99
50
 
100
- export { OpenAPIGenerator as b, CompositeSchemaConverter as e };
101
- export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConverterComponent as S, OpenAPIGeneratorGenerateOptions as a, SchemaConvertOptions as c, SchemaConverter as d };
51
+ export { OpenAPIGenerator as b, CompositeSchemaConverter as d };
52
+ export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConvertOptions as S, OpenAPIGeneratorGenerateOptions as a, SchemaConverter as c };
@@ -4,26 +4,8 @@ import { AnyProcedure, AnyRouter } from '@orpc/server';
4
4
  import { Promisable } from '@orpc/shared';
5
5
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
6
 
7
- interface SchemaConverterComponent {
8
- allowedStrategies: readonly SchemaConvertOptions['strategy'][];
9
- schema: AnySchema;
10
- required: boolean;
11
- ref: string;
12
- }
13
7
  interface SchemaConvertOptions {
14
8
  strategy: 'input' | 'output';
15
- /**
16
- * Common components should use `$ref` to represent themselves if matched.
17
- */
18
- components?: readonly SchemaConverterComponent[];
19
- /**
20
- * Minimum schema structure depth required before using `$ref` for components.
21
- *
22
- * For example, if set to 2, `$ref` will only be used for schemas nested at depth 2 or greater.
23
- *
24
- * @default 0 - No depth limit;
25
- */
26
- minStructureDepthForRef?: number;
27
9
  }
28
10
  interface SchemaConverter {
29
11
  convert(schema: AnySchema | undefined, options: SchemaConvertOptions): Promisable<[required: boolean, jsonSchema: JSONSchema]>;
@@ -47,37 +29,6 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
47
29
  * @default () => false
48
30
  */
49
31
  exclude?: (procedure: AnyProcedure | AnyContractProcedure, path: readonly string[]) => boolean;
50
- /**
51
- * Common schemas to be used for $ref resolution.
52
- */
53
- commonSchemas?: Record<string, {
54
- /**
55
- * Determines which schema definition to use when input and output schemas differ.
56
- * This is needed because some schemas transform data differently between input and output,
57
- * making it impossible to use a single $ref for both cases.
58
- *
59
- * @example
60
- * ```ts
61
- * // This schema transforms a string input into a number output
62
- * const Schema = z.string()
63
- * .transform(v => Number(v))
64
- * .pipe(z.number())
65
- *
66
- * // Input schema: { type: 'string' }
67
- * // Output schema: { type: 'number' }
68
- * ```
69
- *
70
- * When schemas differ between input and output, you must explicitly choose
71
- * which version to use for the OpenAPI specification.
72
- *
73
- * @default 'input' - Uses the input schema definition by default
74
- */
75
- strategy?: SchemaConvertOptions['strategy'];
76
- schema: AnySchema;
77
- } | {
78
- error: 'UndefinedError';
79
- schema?: never;
80
- }>;
81
32
  }
82
33
  /**
83
34
  * The generator that converts oRPC routers/contracts to OpenAPI specifications.
@@ -97,5 +48,5 @@ declare class OpenAPIGenerator {
97
48
  generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
98
49
  }
99
50
 
100
- export { OpenAPIGenerator as b, CompositeSchemaConverter as e };
101
- export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConverterComponent as S, OpenAPIGeneratorGenerateOptions as a, SchemaConvertOptions as c, SchemaConverter as d };
51
+ export { OpenAPIGenerator as b, CompositeSchemaConverter as d };
52
+ export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O, SchemaConvertOptions as S, OpenAPIGeneratorGenerateOptions as a, SchemaConverter as c };
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.865fe1f",
4
+ "version": "0.0.0-next.8719bd7",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -50,16 +50,16 @@
50
50
  ],
51
51
  "dependencies": {
52
52
  "json-schema-typed": "^8.0.1",
53
- "rou3": "^0.7.3",
54
- "@orpc/client": "0.0.0-next.865fe1f",
55
- "@orpc/contract": "0.0.0-next.865fe1f",
56
- "@orpc/openapi-client": "0.0.0-next.865fe1f",
57
- "@orpc/server": "0.0.0-next.865fe1f",
58
- "@orpc/shared": "0.0.0-next.865fe1f",
59
- "@orpc/standard-server": "0.0.0-next.865fe1f"
53
+ "rou3": "^0.6.0",
54
+ "@orpc/openapi-client": "0.0.0-next.8719bd7",
55
+ "@orpc/contract": "0.0.0-next.8719bd7",
56
+ "@orpc/client": "0.0.0-next.8719bd7",
57
+ "@orpc/server": "0.0.0-next.8719bd7",
58
+ "@orpc/shared": "0.0.0-next.8719bd7",
59
+ "@orpc/standard-server": "0.0.0-next.8719bd7"
60
60
  },
61
61
  "devDependencies": {
62
- "zod": "^3.25.74"
62
+ "zod": "^3.25.61"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "unbuild",