@orpc/openapi 1.5.1 → 1.5.2

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/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.CbIlrReM.mjs';
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';
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';
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.CbIlrReM.js';
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';
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';
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { c as customOpenAPIOperation } from './shared/openapi.C_3bk7bB.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.C_3bk7bB.mjs';
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';
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.CbIlrReM.mjs';
5
+ import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.B3hexduL.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.CbIlrReM.js';
5
+ import { O as OpenAPIGeneratorOptions, a as OpenAPIGeneratorGenerateOptions } from '../shared/openapi.B3hexduL.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.C_3bk7bB.mjs';
2
+ import { O as OpenAPIGenerator } from '../shared/openapi.DrrBsJ0w.mjs';
3
3
  import '@orpc/client';
4
4
  import '@orpc/client/standard';
5
5
  import '@orpc/contract';
@@ -5,7 +5,7 @@ import { Promisable } from '@orpc/shared';
5
5
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
6
 
7
7
  interface SchemaConverterComponent {
8
- allowedStrategies: SchemaConvertOptions['strategy'][];
8
+ allowedStrategies: readonly SchemaConvertOptions['strategy'][];
9
9
  schema: AnySchema;
10
10
  required: boolean;
11
11
  ref: string;
@@ -15,7 +15,7 @@ interface SchemaConvertOptions {
15
15
  /**
16
16
  * Common components should use `$ref` to represent themselves if matched.
17
17
  */
18
- components?: SchemaConverterComponent[];
18
+ components?: readonly SchemaConverterComponent[];
19
19
  /**
20
20
  * Minimum schema structure depth required before using `$ref` for components.
21
21
  *
@@ -74,6 +74,9 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
74
74
  */
75
75
  strategy?: SchemaConvertOptions['strategy'];
76
76
  schema: AnySchema;
77
+ } | {
78
+ error: 'UndefinedError';
79
+ schema?: never;
77
80
  }>;
78
81
  }
79
82
  /**
@@ -5,7 +5,7 @@ import { Promisable } from '@orpc/shared';
5
5
  import { JSONSchema } from 'json-schema-typed/draft-2020-12';
6
6
 
7
7
  interface SchemaConverterComponent {
8
- allowedStrategies: SchemaConvertOptions['strategy'][];
8
+ allowedStrategies: readonly SchemaConvertOptions['strategy'][];
9
9
  schema: AnySchema;
10
10
  required: boolean;
11
11
  ref: string;
@@ -15,7 +15,7 @@ interface SchemaConvertOptions {
15
15
  /**
16
16
  * Common components should use `$ref` to represent themselves if matched.
17
17
  */
18
- components?: SchemaConverterComponent[];
18
+ components?: readonly SchemaConverterComponent[];
19
19
  /**
20
20
  * Minimum schema structure depth required before using `$ref` for components.
21
21
  *
@@ -74,6 +74,9 @@ interface OpenAPIGeneratorGenerateOptions extends Partial<Omit<OpenAPI.Document,
74
74
  */
75
75
  strategy?: SchemaConvertOptions['strategy'];
76
76
  schema: AnySchema;
77
+ } | {
78
+ error: 'UndefinedError';
79
+ schema?: never;
77
80
  }>;
78
81
  }
79
82
  /**
@@ -393,7 +393,7 @@ class OpenAPIGenerator {
393
393
  exclude: void 0,
394
394
  commonSchemas: void 0
395
395
  };
396
- const baseSchemaConvertOptions = await this.#resolveCommonSchemas(doc, options.commonSchemas);
396
+ const { baseSchemaConvertOptions, undefinedErrorJsonSchema } = await this.#resolveCommonSchemas(doc, options.commonSchemas);
397
397
  const contracts = [];
398
398
  await resolveContractProcedures({ path: [], router }, ({ contract, path }) => {
399
399
  if (!exclude(contract, path)) {
@@ -420,7 +420,7 @@ class OpenAPIGenerator {
420
420
  };
421
421
  await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
422
422
  await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
423
- await this.#errorResponse(operationObjectRef, def, baseSchemaConvertOptions);
423
+ await this.#errorResponse(operationObjectRef, def, baseSchemaConvertOptions, undefinedErrorJsonSchema);
424
424
  }
425
425
  doc.paths ??= {};
426
426
  doc.paths[httpPath] ??= {};
@@ -445,11 +445,26 @@ ${errors.join("\n\n")}`
445
445
  return this.serializer.serialize(doc)[0];
446
446
  }
447
447
  async #resolveCommonSchemas(doc, commonSchemas) {
448
- const baseOptions = {};
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 = {};
449
460
  if (commonSchemas) {
450
- baseOptions.components = [];
461
+ baseSchemaConvertOptions.components = [];
451
462
  for (const key in commonSchemas) {
452
- const { schema, strategy = "input" } = commonSchemas[key];
463
+ const options = commonSchemas[key];
464
+ if (options.schema === void 0) {
465
+ continue;
466
+ }
467
+ const { schema, strategy = "input" } = options;
453
468
  const [required, json] = await this.converter.convert(schema, { strategy });
454
469
  const allowedStrategies = [strategy];
455
470
  if (strategy === "input") {
@@ -463,7 +478,7 @@ ${errors.join("\n\n")}`
463
478
  allowedStrategies.push("input");
464
479
  }
465
480
  }
466
- baseOptions.components.push({
481
+ baseSchemaConvertOptions.components.push({
467
482
  schema,
468
483
  required,
469
484
  ref: `#/components/schemas/${key}`,
@@ -473,11 +488,19 @@ ${errors.join("\n\n")}`
473
488
  doc.components ??= {};
474
489
  doc.components.schemas ??= {};
475
490
  for (const key in commonSchemas) {
476
- const { schema, strategy = "input" } = commonSchemas[key];
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;
477
500
  const [, json] = await this.converter.convert(
478
501
  schema,
479
502
  {
480
- ...baseOptions,
503
+ ...baseSchemaConvertOptions,
481
504
  strategy,
482
505
  minStructureDepthForRef: 1
483
506
  // not allow use $ref for root schemas
@@ -486,7 +509,7 @@ ${errors.join("\n\n")}`
486
509
  doc.components.schemas[key] = toOpenAPISchema(json);
487
510
  }
488
511
  }
489
- return baseOptions;
512
+ return { baseSchemaConvertOptions, undefinedErrorJsonSchema };
490
513
  }
491
514
  async #request(doc, ref, def, baseSchemaConvertOptions) {
492
515
  const method = fallbackContractConfig("defaultMethod", def.route.method);
@@ -672,7 +695,7 @@ ${errors.join("\n\n")}`
672
695
  }
673
696
  }
674
697
  }
675
- async #errorResponse(ref, def, baseSchemaConvertOptions) {
698
+ async #errorResponse(ref, def, baseSchemaConvertOptions, undefinedErrorSchema) {
676
699
  const errorMap = def.errorMap;
677
700
  const errors = {};
678
701
  for (const code in errorMap) {
@@ -704,17 +727,7 @@ ${errors.join("\n\n")}`
704
727
  content: toOpenAPIContent({
705
728
  oneOf: [
706
729
  ...schemas,
707
- {
708
- type: "object",
709
- properties: {
710
- defined: { const: false },
711
- code: { type: "string" },
712
- status: { type: "number" },
713
- message: { type: "string" },
714
- data: {}
715
- },
716
- required: ["defined", "code", "status", "message"]
717
- }
730
+ undefinedErrorSchema
718
731
  ]
719
732
  })
720
733
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@orpc/openapi",
3
3
  "type": "module",
4
- "version": "1.5.1",
4
+ "version": "1.5.2",
5
5
  "license": "MIT",
6
6
  "homepage": "https://orpc.unnoq.com",
7
7
  "repository": {
@@ -51,15 +51,15 @@
51
51
  "dependencies": {
52
52
  "json-schema-typed": "^8.0.1",
53
53
  "rou3": "^0.6.0",
54
- "@orpc/contract": "1.5.1",
55
- "@orpc/client": "1.5.1",
56
- "@orpc/openapi-client": "1.5.1",
57
- "@orpc/shared": "1.5.1",
58
- "@orpc/standard-server": "1.5.1",
59
- "@orpc/server": "1.5.1"
54
+ "@orpc/openapi-client": "1.5.2",
55
+ "@orpc/server": "1.5.2",
56
+ "@orpc/shared": "1.5.2",
57
+ "@orpc/standard-server": "1.5.2",
58
+ "@orpc/client": "1.5.2",
59
+ "@orpc/contract": "1.5.2"
60
60
  },
61
61
  "devDependencies": {
62
- "zod": "^3.25.63"
62
+ "zod": "^3.25.64"
63
63
  },
64
64
  "scripts": {
65
65
  "build": "unbuild",