@orpc/openapi 0.0.0-next.8b6cb3a → 0.0.0-next.8be6412
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 +2 -3
- package/dist/index.d.ts +2 -3
- 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.C_3bk7bB.mjs → openapi.DaYgbD_w.mjs} +25 -98
- package/dist/shared/{openapi.DYi1fARS.d.mts → openapi.qZLdpE0a.d.mts} +2 -48
- package/dist/shared/{openapi.DYi1fARS.d.ts → openapi.qZLdpE0a.d.ts} +2 -48
- package/package.json +8 -8
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 {
|
|
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,
|
|
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 {
|
|
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,
|
|
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.
|
|
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,
|
|
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';
|
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.qZLdpE0a.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.qZLdpE0a.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.DaYgbD_w.mjs';
|
|
3
3
|
import '@orpc/client';
|
|
4
4
|
import '@orpc/client/standard';
|
|
5
5
|
import '@orpc/contract';
|
|
@@ -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 = 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(
|
|
422
|
-
await this.#successResponse(
|
|
423
|
-
await this.#errorResponse(operationObjectRef, def
|
|
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,73 +433,22 @@ ${errors.join("\n\n")}`
|
|
|
444
433
|
}
|
|
445
434
|
return this.serializer.serialize(doc)[0];
|
|
446
435
|
}
|
|
447
|
-
async #
|
|
448
|
-
const baseOptions = {};
|
|
449
|
-
if (commonSchemas) {
|
|
450
|
-
baseOptions.components = [];
|
|
451
|
-
for (const key in commonSchemas) {
|
|
452
|
-
const { schema, strategy = "input" } = commonSchemas[key];
|
|
453
|
-
const [required, json] = await this.converter.convert(schema, { strategy });
|
|
454
|
-
const allowedStrategies = [strategy];
|
|
455
|
-
if (strategy === "input") {
|
|
456
|
-
const [outputRequired, outputJson] = await this.converter.convert(schema, { strategy: "output" });
|
|
457
|
-
if (outputRequired === required && stringifyJSON(outputJson) === stringifyJSON(json)) {
|
|
458
|
-
allowedStrategies.push("output");
|
|
459
|
-
}
|
|
460
|
-
} else if (strategy === "output") {
|
|
461
|
-
const [inputRequired, inputJson] = await this.converter.convert(schema, { strategy: "input" });
|
|
462
|
-
if (inputRequired === required && stringifyJSON(inputJson) === stringifyJSON(json)) {
|
|
463
|
-
allowedStrategies.push("input");
|
|
464
|
-
}
|
|
465
|
-
}
|
|
466
|
-
baseOptions.components.push({
|
|
467
|
-
schema,
|
|
468
|
-
required,
|
|
469
|
-
ref: `#/components/schemas/${key}`,
|
|
470
|
-
allowedStrategies
|
|
471
|
-
});
|
|
472
|
-
}
|
|
473
|
-
doc.components ??= {};
|
|
474
|
-
doc.components.schemas ??= {};
|
|
475
|
-
for (const key in commonSchemas) {
|
|
476
|
-
const { schema, strategy = "input" } = commonSchemas[key];
|
|
477
|
-
const [, json] = await this.converter.convert(
|
|
478
|
-
schema,
|
|
479
|
-
{
|
|
480
|
-
...baseOptions,
|
|
481
|
-
strategy,
|
|
482
|
-
minStructureDepthForRef: 1
|
|
483
|
-
// not allow use $ref for root schemas
|
|
484
|
-
}
|
|
485
|
-
);
|
|
486
|
-
doc.components.schemas[key] = toOpenAPISchema(json);
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
return baseOptions;
|
|
490
|
-
}
|
|
491
|
-
async #request(doc, ref, def, baseSchemaConvertOptions) {
|
|
436
|
+
async #request(ref, def) {
|
|
492
437
|
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
493
438
|
const details = getEventIteratorSchemaDetails(def.inputSchema);
|
|
494
439
|
if (details) {
|
|
495
440
|
ref.requestBody = {
|
|
496
441
|
required: true,
|
|
497
442
|
content: toOpenAPIEventIteratorContent(
|
|
498
|
-
await this.converter.convert(details.yields, {
|
|
499
|
-
await this.converter.convert(details.returns, {
|
|
443
|
+
await this.converter.convert(details.yields, { strategy: "input" }),
|
|
444
|
+
await this.converter.convert(details.returns, { strategy: "input" })
|
|
500
445
|
)
|
|
501
446
|
};
|
|
502
447
|
return;
|
|
503
448
|
}
|
|
504
449
|
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
505
450
|
const inputStructure = fallbackContractConfig("defaultInputStructure", def.route.inputStructure);
|
|
506
|
-
let [required, schema] = await this.converter.convert(
|
|
507
|
-
def.inputSchema,
|
|
508
|
-
{
|
|
509
|
-
...baseSchemaConvertOptions,
|
|
510
|
-
strategy: "input",
|
|
511
|
-
minStructureDepthForRef: dynamicParams?.length || inputStructure === "detailed" ? 1 : 0
|
|
512
|
-
}
|
|
513
|
-
);
|
|
451
|
+
let [required, schema] = await this.converter.convert(def.inputSchema, { strategy: "input" });
|
|
514
452
|
if (isAnySchema(schema) && !dynamicParams?.length) {
|
|
515
453
|
return;
|
|
516
454
|
}
|
|
@@ -553,8 +491,7 @@ ${errors.join("\n\n")}`
|
|
|
553
491
|
if (!isObjectSchema(schema)) {
|
|
554
492
|
throw error;
|
|
555
493
|
}
|
|
556
|
-
|
|
557
|
-
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))) {
|
|
558
495
|
throw new OpenAPIGeneratorError(
|
|
559
496
|
'When input structure is "detailed" and path has dynamic params, the "params" schema must be an object with all dynamic params as required.'
|
|
560
497
|
);
|
|
@@ -562,13 +499,12 @@ ${errors.join("\n\n")}`
|
|
|
562
499
|
for (const from of ["params", "query", "headers"]) {
|
|
563
500
|
const fromSchema = schema.properties?.[from];
|
|
564
501
|
if (fromSchema !== void 0) {
|
|
565
|
-
|
|
566
|
-
if (!isObjectSchema(resolvedSchema)) {
|
|
502
|
+
if (!isObjectSchema(fromSchema)) {
|
|
567
503
|
throw error;
|
|
568
504
|
}
|
|
569
505
|
const parameterIn = from === "params" ? "path" : from === "headers" ? "header" : "query";
|
|
570
506
|
ref.parameters ??= [];
|
|
571
|
-
ref.parameters.push(...toOpenAPIParameters(
|
|
507
|
+
ref.parameters.push(...toOpenAPIParameters(fromSchema, parameterIn));
|
|
572
508
|
}
|
|
573
509
|
}
|
|
574
510
|
if (schema.properties?.body !== void 0) {
|
|
@@ -578,7 +514,7 @@ ${errors.join("\n\n")}`
|
|
|
578
514
|
};
|
|
579
515
|
}
|
|
580
516
|
}
|
|
581
|
-
async #successResponse(
|
|
517
|
+
async #successResponse(ref, def) {
|
|
582
518
|
const outputSchema = def.outputSchema;
|
|
583
519
|
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
584
520
|
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
@@ -589,20 +525,13 @@ ${errors.join("\n\n")}`
|
|
|
589
525
|
ref.responses[status] = {
|
|
590
526
|
description,
|
|
591
527
|
content: toOpenAPIEventIteratorContent(
|
|
592
|
-
await this.converter.convert(eventIteratorSchemaDetails.yields, {
|
|
593
|
-
await this.converter.convert(eventIteratorSchemaDetails.returns, {
|
|
528
|
+
await this.converter.convert(eventIteratorSchemaDetails.yields, { strategy: "output" }),
|
|
529
|
+
await this.converter.convert(eventIteratorSchemaDetails.returns, { strategy: "output" })
|
|
594
530
|
)
|
|
595
531
|
};
|
|
596
532
|
return;
|
|
597
533
|
}
|
|
598
|
-
const [required, json] = await this.converter.convert(
|
|
599
|
-
outputSchema,
|
|
600
|
-
{
|
|
601
|
-
...baseSchemaConvertOptions,
|
|
602
|
-
strategy: "output",
|
|
603
|
-
minStructureDepthForRef: outputStructure === "detailed" ? 1 : 0
|
|
604
|
-
}
|
|
605
|
-
);
|
|
534
|
+
const [required, json] = await this.converter.convert(outputSchema, { strategy: "output" });
|
|
606
535
|
if (outputStructure === "compact") {
|
|
607
536
|
ref.responses ??= {};
|
|
608
537
|
ref.responses[status] = {
|
|
@@ -629,12 +558,11 @@ ${errors.join("\n\n")}`
|
|
|
629
558
|
let schemaStatus;
|
|
630
559
|
let schemaDescription;
|
|
631
560
|
if (item.properties?.status !== void 0) {
|
|
632
|
-
const
|
|
633
|
-
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)) {
|
|
634
562
|
throw error;
|
|
635
563
|
}
|
|
636
|
-
schemaStatus =
|
|
637
|
-
schemaDescription =
|
|
564
|
+
schemaStatus = item.properties.status.const;
|
|
565
|
+
schemaDescription = item.properties.status.description;
|
|
638
566
|
}
|
|
639
567
|
const itemStatus = schemaStatus ?? status;
|
|
640
568
|
const itemDescription = schemaDescription ?? description;
|
|
@@ -650,17 +578,16 @@ ${errors.join("\n\n")}`
|
|
|
650
578
|
description: itemDescription
|
|
651
579
|
};
|
|
652
580
|
if (item.properties?.headers !== void 0) {
|
|
653
|
-
|
|
654
|
-
if (!isObjectSchema(headersSchema)) {
|
|
581
|
+
if (!isObjectSchema(item.properties.headers)) {
|
|
655
582
|
throw error;
|
|
656
583
|
}
|
|
657
|
-
for (const key in
|
|
658
|
-
const headerSchema =
|
|
584
|
+
for (const key in item.properties.headers.properties) {
|
|
585
|
+
const headerSchema = item.properties.headers.properties[key];
|
|
659
586
|
if (headerSchema !== void 0) {
|
|
660
587
|
ref.responses[itemStatus].headers ??= {};
|
|
661
588
|
ref.responses[itemStatus].headers[key] = {
|
|
662
589
|
schema: toOpenAPISchema(headerSchema),
|
|
663
|
-
required: item.
|
|
590
|
+
required: item.properties.headers.required?.includes(key)
|
|
664
591
|
};
|
|
665
592
|
}
|
|
666
593
|
}
|
|
@@ -672,7 +599,7 @@ ${errors.join("\n\n")}`
|
|
|
672
599
|
}
|
|
673
600
|
}
|
|
674
601
|
}
|
|
675
|
-
async #errorResponse(ref, def
|
|
602
|
+
async #errorResponse(ref, def) {
|
|
676
603
|
const errorMap = def.errorMap;
|
|
677
604
|
const errors = {};
|
|
678
605
|
for (const code in errorMap) {
|
|
@@ -682,7 +609,7 @@ ${errors.join("\n\n")}`
|
|
|
682
609
|
}
|
|
683
610
|
const status = fallbackORPCErrorStatus(code, config.status);
|
|
684
611
|
const message = fallbackORPCErrorMessage(code, config.message);
|
|
685
|
-
const [dataRequired, dataSchema] = await this.converter.convert(config.data, {
|
|
612
|
+
const [dataRequired, dataSchema] = await this.converter.convert(config.data, { strategy: "output" });
|
|
686
613
|
errors[status] ??= [];
|
|
687
614
|
errors[status].push({
|
|
688
615
|
type: "object",
|
|
@@ -722,4 +649,4 @@ ${errors.join("\n\n")}`
|
|
|
722
649
|
}
|
|
723
650
|
}
|
|
724
651
|
|
|
725
|
-
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,
|
|
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,34 +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
32
|
}
|
|
79
33
|
/**
|
|
80
34
|
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
@@ -94,5 +48,5 @@ declare class OpenAPIGenerator {
|
|
|
94
48
|
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
95
49
|
}
|
|
96
50
|
|
|
97
|
-
export { OpenAPIGenerator as b, CompositeSchemaConverter as
|
|
98
|
-
export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O,
|
|
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,34 +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
32
|
}
|
|
79
33
|
/**
|
|
80
34
|
* The generator that converts oRPC routers/contracts to OpenAPI specifications.
|
|
@@ -94,5 +48,5 @@ declare class OpenAPIGenerator {
|
|
|
94
48
|
generate(router: AnyContractRouter | AnyRouter, options?: OpenAPIGeneratorGenerateOptions): Promise<OpenAPI.Document>;
|
|
95
49
|
}
|
|
96
50
|
|
|
97
|
-
export { OpenAPIGenerator as b, CompositeSchemaConverter as
|
|
98
|
-
export type { ConditionalSchemaConverter as C, OpenAPIGeneratorOptions as O,
|
|
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.
|
|
4
|
+
"version": "0.0.0-next.8be6412",
|
|
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/
|
|
55
|
-
"@orpc/
|
|
56
|
-
"@orpc/client": "0.0.0-next.
|
|
57
|
-
"@orpc/
|
|
58
|
-
"@orpc/standard-server": "0.0.0-next.
|
|
59
|
-
"@orpc/shared": "0.0.0-next.
|
|
54
|
+
"@orpc/contract": "0.0.0-next.8be6412",
|
|
55
|
+
"@orpc/client": "0.0.0-next.8be6412",
|
|
56
|
+
"@orpc/openapi-client": "0.0.0-next.8be6412",
|
|
57
|
+
"@orpc/server": "0.0.0-next.8be6412",
|
|
58
|
+
"@orpc/standard-server": "0.0.0-next.8be6412",
|
|
59
|
+
"@orpc/shared": "0.0.0-next.8be6412"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"zod": "^3.25.
|
|
62
|
+
"zod": "^3.25.57"
|
|
63
63
|
},
|
|
64
64
|
"scripts": {
|
|
65
65
|
"build": "unbuild",
|