@orpc/openapi 1.5.1 → 1.6.0
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 +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.mjs +2 -2
- package/dist/plugins/index.d.mts +1 -1
- package/dist/plugins/index.d.ts +1 -1
- package/dist/plugins/index.mjs +1 -1
- package/dist/shared/{openapi.CbIlrReM.d.mts → openapi.B3hexduL.d.mts} +5 -2
- package/dist/shared/{openapi.CbIlrReM.d.ts → openapi.B3hexduL.d.ts} +5 -2
- package/dist/shared/{openapi.C_3bk7bB.mjs → openapi.DrrBsJ0w.mjs} +34 -21
- package/package.json +9 -9
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), Pinia Colada, and more.
|
33
|
+
- **⚙️ Framework Integrations**: Seamlessly integrate with TanStack Query (React, Vue, Solid, Svelte, Angular), 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.
|
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.
|
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.
|
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.
|
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.
|
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';
|
package/dist/plugins/index.d.mts
CHANGED
@@ -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.
|
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
|
|
package/dist/plugins/index.d.ts
CHANGED
@@ -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.
|
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
|
|
package/dist/plugins/index.mjs
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { stringifyJSON, once, value } from '@orpc/shared';
|
2
|
-
import { O as OpenAPIGenerator } from '../shared/openapi.
|
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
|
-
|
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
|
-
|
461
|
+
baseSchemaConvertOptions.components = [];
|
451
462
|
for (const key in commonSchemas) {
|
452
|
-
const
|
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
|
-
|
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
|
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
|
-
...
|
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
|
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.
|
4
|
+
"version": "1.6.0",
|
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.
|
54
|
-
"@orpc/
|
55
|
-
"@orpc/
|
56
|
-
"@orpc/openapi-client": "1.
|
57
|
-
"@orpc/
|
58
|
-
"@orpc/
|
59
|
-
"@orpc/server": "1.
|
53
|
+
"rou3": "^0.7.2",
|
54
|
+
"@orpc/client": "1.6.0",
|
55
|
+
"@orpc/contract": "1.6.0",
|
56
|
+
"@orpc/openapi-client": "1.6.0",
|
57
|
+
"@orpc/server": "1.6.0",
|
58
|
+
"@orpc/shared": "1.6.0",
|
59
|
+
"@orpc/standard-server": "1.6.0"
|
60
60
|
},
|
61
61
|
"devDependencies": {
|
62
|
-
"zod": "^3.25.
|
62
|
+
"zod": "^3.25.67"
|
63
63
|
},
|
64
64
|
"scripts": {
|
65
65
|
"build": "unbuild",
|