@orpc/openapi 0.0.0-next.73eb96a → 0.0.0-next.7b09958
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/chunk-HC5PVG4R.js +52 -0
- package/dist/chunk-ICLAXOVR.js +32 -0
- package/dist/chunk-PWOV66X6.js +421 -0
- package/dist/fetch.js +5 -657
- package/dist/hono.js +9 -0
- package/dist/index.js +86 -30
- package/dist/next.js +9 -0
- package/dist/node.js +30 -0
- package/dist/src/adapters/fetch/index.d.ts +2 -0
- package/dist/src/adapters/fetch/openapi-handler.d.ts +10 -0
- package/dist/src/adapters/hono/index.d.ts +2 -0
- package/dist/src/adapters/next/index.d.ts +2 -0
- package/dist/src/adapters/node/index.d.ts +2 -0
- package/dist/src/adapters/node/openapi-handler.d.ts +10 -0
- package/dist/src/adapters/standard/index.d.ts +6 -0
- package/dist/src/adapters/standard/openapi-codec.d.ts +15 -0
- package/dist/src/adapters/standard/openapi-handler.d.ts +7 -0
- package/dist/src/adapters/standard/openapi-matcher.d.ts +20 -0
- package/dist/src/adapters/standard/openapi-serializer.d.ts +11 -0
- package/dist/src/openapi-generator.d.ts +10 -3
- package/dist/src/openapi-input-structure-parser.d.ts +2 -2
- package/dist/src/openapi-output-structure-parser.d.ts +2 -2
- package/dist/src/schema-converter.d.ts +2 -2
- package/dist/src/schema.d.ts +1 -1
- package/dist/src/utils.d.ts +1 -16
- package/dist/standard.js +14 -0
- package/package.json +27 -10
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/src/fetch/index.d.ts +0 -10
- package/dist/src/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/fetch/openapi-handler.d.ts +0 -33
- package/dist/src/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/fetch/schema-coercer.d.ts +0 -10
- /package/dist/src/{fetch → adapters/standard}/bracket-notation.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JSONSerializer,
|
|
3
|
-
forEachAllContractProcedure,
|
|
4
|
-
forEachContractProcedure,
|
|
5
3
|
standardizeHTTPPath
|
|
6
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-HC5PVG4R.js";
|
|
7
5
|
|
|
8
6
|
// src/openapi.ts
|
|
9
7
|
import { OpenApiBuilder } from "openapi3-ts/oas31";
|
|
@@ -35,11 +33,17 @@ var OpenAPIContentBuilder = class {
|
|
|
35
33
|
}
|
|
36
34
|
};
|
|
37
35
|
|
|
36
|
+
// src/openapi-generator.ts
|
|
37
|
+
import { fallbackContractConfig as fallbackContractConfig2, fallbackORPCErrorStatus } from "@orpc/contract";
|
|
38
|
+
import { eachAllContractProcedure } from "@orpc/server";
|
|
39
|
+
import { group } from "@orpc/shared";
|
|
40
|
+
|
|
38
41
|
// src/openapi-error.ts
|
|
39
42
|
var OpenAPIError = class extends Error {
|
|
40
43
|
};
|
|
41
44
|
|
|
42
45
|
// src/openapi-input-structure-parser.ts
|
|
46
|
+
import { fallbackContractConfig } from "@orpc/contract";
|
|
43
47
|
var OpenAPIInputStructureParser = class {
|
|
44
48
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
45
49
|
this.schemaConverter = schemaConverter;
|
|
@@ -47,8 +51,8 @@ var OpenAPIInputStructureParser = class {
|
|
|
47
51
|
this.pathParser = pathParser;
|
|
48
52
|
}
|
|
49
53
|
parse(contract, structure) {
|
|
50
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
51
|
-
const method = contract["~orpc"].route?.method
|
|
54
|
+
const inputSchema = this.schemaConverter.convert(contract["~orpc"].inputSchema, { strategy: "input" });
|
|
55
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
52
56
|
const httpPath = contract["~orpc"].route?.path;
|
|
53
57
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
54
58
|
return {
|
|
@@ -140,7 +144,7 @@ var OpenAPIOutputStructureParser = class {
|
|
|
140
144
|
this.schemaUtils = schemaUtils;
|
|
141
145
|
}
|
|
142
146
|
parse(contract, structure) {
|
|
143
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
147
|
+
const outputSchema = this.schemaConverter.convert(contract["~orpc"].outputSchema, { strategy: "output" });
|
|
144
148
|
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
145
149
|
return {
|
|
146
150
|
headersSchema: void 0,
|
|
@@ -179,14 +183,14 @@ var OpenAPIOutputStructureParser = class {
|
|
|
179
183
|
};
|
|
180
184
|
|
|
181
185
|
// src/openapi-parameters-builder.ts
|
|
182
|
-
import { get,
|
|
186
|
+
import { get, isObject, omit } from "@orpc/shared";
|
|
183
187
|
var OpenAPIParametersBuilder = class {
|
|
184
188
|
build(paramIn, jsonSchema, options) {
|
|
185
189
|
const parameters = [];
|
|
186
190
|
for (const name in jsonSchema.properties) {
|
|
187
191
|
const schema = jsonSchema.properties[name];
|
|
188
192
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
189
|
-
return
|
|
193
|
+
return isObject(example) && name in example;
|
|
190
194
|
}).map((example) => {
|
|
191
195
|
return example[name];
|
|
192
196
|
});
|
|
@@ -247,7 +251,7 @@ var CompositeSchemaConverter = class {
|
|
|
247
251
|
};
|
|
248
252
|
|
|
249
253
|
// src/schema-utils.ts
|
|
250
|
-
import {
|
|
254
|
+
import { isObject as isObject2 } from "@orpc/shared";
|
|
251
255
|
|
|
252
256
|
// src/schema.ts
|
|
253
257
|
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
@@ -289,14 +293,14 @@ var SchemaUtils = class {
|
|
|
289
293
|
return typeof schema === "object" && schema.type === "object";
|
|
290
294
|
}
|
|
291
295
|
isAnySchema(schema) {
|
|
292
|
-
return schema === true || Object.keys(schema).length === 0;
|
|
296
|
+
return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
293
297
|
}
|
|
294
298
|
isUndefinableSchema(schema) {
|
|
295
299
|
const [matches] = this.filterSchemaBranches(schema, (schema2) => {
|
|
296
300
|
if (typeof schema2 === "boolean") {
|
|
297
301
|
return schema2;
|
|
298
302
|
}
|
|
299
|
-
return Object.keys(schema2).length === 0;
|
|
303
|
+
return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
300
304
|
});
|
|
301
305
|
return matches.length > 0;
|
|
302
306
|
}
|
|
@@ -309,7 +313,7 @@ var SchemaUtils = class {
|
|
|
309
313
|
}, {});
|
|
310
314
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
311
315
|
matched.examples = schema.examples?.map((example) => {
|
|
312
|
-
if (!
|
|
316
|
+
if (!isObject2(example)) {
|
|
313
317
|
return example;
|
|
314
318
|
}
|
|
315
319
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -325,7 +329,7 @@ var SchemaUtils = class {
|
|
|
325
329
|
}, {});
|
|
326
330
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
327
331
|
rest.examples = schema.examples?.map((example) => {
|
|
328
|
-
if (!
|
|
332
|
+
if (!isObject2(example)) {
|
|
329
333
|
return example;
|
|
330
334
|
}
|
|
331
335
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -380,6 +384,7 @@ var OpenAPIGenerator = class {
|
|
|
380
384
|
errorHandlerStrategy;
|
|
381
385
|
ignoreUndefinedPathProcedures;
|
|
382
386
|
considerMissingTagDefinitionAsError;
|
|
387
|
+
strictErrorResponses;
|
|
383
388
|
constructor(options) {
|
|
384
389
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
385
390
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
@@ -392,6 +397,7 @@ var OpenAPIGenerator = class {
|
|
|
392
397
|
this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
|
|
393
398
|
this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
394
399
|
this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
|
|
400
|
+
this.strictErrorResponses = options?.strictErrorResponses ?? true;
|
|
395
401
|
}
|
|
396
402
|
async generate(router, doc) {
|
|
397
403
|
const builder = new OpenApiBuilder({
|
|
@@ -399,16 +405,21 @@ var OpenAPIGenerator = class {
|
|
|
399
405
|
openapi: "3.1.1"
|
|
400
406
|
});
|
|
401
407
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
402
|
-
await
|
|
408
|
+
await eachAllContractProcedure({
|
|
409
|
+
path: [],
|
|
410
|
+
router
|
|
411
|
+
}, ({ contract, path }) => {
|
|
403
412
|
try {
|
|
404
413
|
const def = contract["~orpc"];
|
|
405
414
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
406
415
|
return;
|
|
407
416
|
}
|
|
408
|
-
const method = def.route?.method
|
|
417
|
+
const method = fallbackContractConfig2("defaultMethod", def.route?.method);
|
|
409
418
|
const httpPath = def.route?.path ? standardizeHTTPPath(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
410
|
-
const
|
|
411
|
-
const
|
|
419
|
+
const inputStructure = fallbackContractConfig2("defaultInputStructure", def.route?.inputStructure);
|
|
420
|
+
const outputStructure = fallbackContractConfig2("defaultOutputStructure", def.route?.outputStructure);
|
|
421
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
422
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
412
423
|
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
413
424
|
required: true
|
|
414
425
|
}) : [];
|
|
@@ -419,15 +430,64 @@ var OpenAPIGenerator = class {
|
|
|
419
430
|
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
420
431
|
content: this.contentBuilder.build(bodySchema)
|
|
421
432
|
} : void 0;
|
|
422
|
-
const
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema, {
|
|
428
|
-
example: def.outputExample
|
|
429
|
-
}) : void 0
|
|
433
|
+
const responses = {};
|
|
434
|
+
responses[fallbackContractConfig2("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
435
|
+
description: fallbackContractConfig2("defaultSuccessDescription", def.route?.successDescription),
|
|
436
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
437
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
430
438
|
};
|
|
439
|
+
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
440
|
+
...config,
|
|
441
|
+
code,
|
|
442
|
+
status: fallbackORPCErrorStatus(code, config?.status)
|
|
443
|
+
})), (error) => error.status);
|
|
444
|
+
for (const status in errors) {
|
|
445
|
+
const configs = errors[status];
|
|
446
|
+
if (!configs || configs.length === 0) {
|
|
447
|
+
continue;
|
|
448
|
+
}
|
|
449
|
+
const schemas = configs.map(({ data, code, message }) => {
|
|
450
|
+
const json = {
|
|
451
|
+
type: "object",
|
|
452
|
+
properties: {
|
|
453
|
+
defined: { const: true },
|
|
454
|
+
code: { const: code },
|
|
455
|
+
status: { const: Number(status) },
|
|
456
|
+
message: { type: "string", default: message },
|
|
457
|
+
data: {}
|
|
458
|
+
},
|
|
459
|
+
required: ["defined", "code", "status", "message"]
|
|
460
|
+
};
|
|
461
|
+
if (data) {
|
|
462
|
+
const dataJson = this.schemaConverter.convert(data, { strategy: "output" });
|
|
463
|
+
json.properties.data = dataJson;
|
|
464
|
+
if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
|
|
465
|
+
json.required.push("data");
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
return json;
|
|
469
|
+
});
|
|
470
|
+
if (this.strictErrorResponses) {
|
|
471
|
+
schemas.push({
|
|
472
|
+
type: "object",
|
|
473
|
+
properties: {
|
|
474
|
+
defined: { const: false },
|
|
475
|
+
code: { type: "string" },
|
|
476
|
+
status: { type: "number" },
|
|
477
|
+
message: { type: "string" },
|
|
478
|
+
data: {}
|
|
479
|
+
},
|
|
480
|
+
required: ["defined", "code", "status", "message"]
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
const contentSchema = schemas.length === 1 ? schemas[0] : {
|
|
484
|
+
oneOf: schemas
|
|
485
|
+
};
|
|
486
|
+
responses[status] = {
|
|
487
|
+
description: status,
|
|
488
|
+
content: this.contentBuilder.build(contentSchema)
|
|
489
|
+
};
|
|
490
|
+
}
|
|
431
491
|
if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
|
|
432
492
|
const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
433
493
|
if (missingTag !== void 0) {
|
|
@@ -444,9 +504,7 @@ var OpenAPIGenerator = class {
|
|
|
444
504
|
operationId: path.join("."),
|
|
445
505
|
parameters: parameters.length ? parameters : void 0,
|
|
446
506
|
requestBody,
|
|
447
|
-
responses
|
|
448
|
-
[def.route?.successStatus ?? 200]: successResponse
|
|
449
|
-
}
|
|
507
|
+
responses
|
|
450
508
|
};
|
|
451
509
|
builder.addPath(httpPath, {
|
|
452
510
|
[method.toLocaleLowerCase()]: operation
|
|
@@ -483,8 +541,6 @@ export {
|
|
|
483
541
|
OpenAPIPathParser,
|
|
484
542
|
OpenApiBuilder,
|
|
485
543
|
SchemaUtils,
|
|
486
|
-
forEachAllContractProcedure,
|
|
487
|
-
forEachContractProcedure,
|
|
488
544
|
standardizeHTTPPath
|
|
489
545
|
};
|
|
490
546
|
//# sourceMappingURL=index.js.map
|
package/dist/next.js
ADDED
package/dist/node.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher
|
|
4
|
+
} from "./chunk-PWOV66X6.js";
|
|
5
|
+
import "./chunk-HC5PVG4R.js";
|
|
6
|
+
|
|
7
|
+
// src/adapters/node/openapi-handler.ts
|
|
8
|
+
import { nodeHttpResponseSendStandardResponse, nodeHttpToStandardRequest } from "@orpc/server/node";
|
|
9
|
+
import { StandardHandler } from "@orpc/server/standard";
|
|
10
|
+
var OpenAPIHandler = class {
|
|
11
|
+
standardHandler;
|
|
12
|
+
constructor(router, options) {
|
|
13
|
+
const matcher = options?.matcher ?? new OpenAPIMatcher(options);
|
|
14
|
+
const codec = options?.codec ?? new OpenAPICodec(options);
|
|
15
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, { ...options });
|
|
16
|
+
}
|
|
17
|
+
async handle(req, res, ...rest) {
|
|
18
|
+
const standardRequest = nodeHttpToStandardRequest(req, res);
|
|
19
|
+
const result = await this.standardHandler.handle(standardRequest, ...rest);
|
|
20
|
+
if (!result.matched) {
|
|
21
|
+
return { matched: false };
|
|
22
|
+
}
|
|
23
|
+
await nodeHttpResponseSendStandardResponse(res, result.response);
|
|
24
|
+
return { matched: true };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export {
|
|
28
|
+
OpenAPIHandler
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=node.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { FetchHandler, FetchHandleResult } from '@orpc/server/fetch';
|
|
3
|
+
import type { StandardHandleRest } from '@orpc/server/standard';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
5
|
+
export declare class OpenAPIHandler<T extends Context> implements FetchHandler<T> {
|
|
6
|
+
private readonly standardHandler;
|
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
8
|
+
handle(request: Request, ...rest: StandardHandleRest<T>): Promise<FetchHandleResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Context, Router } from '@orpc/server';
|
|
2
|
+
import type { NodeHttpHandler, NodeHttpHandleResult, NodeHttpRequest, NodeHttpResponse } from '@orpc/server/node';
|
|
3
|
+
import type { StandardHandleRest } from '@orpc/server/standard';
|
|
4
|
+
import type { OpenAPIHandlerOptions } from '../standard';
|
|
5
|
+
export declare class OpenAPIHandler<T extends Context> implements NodeHttpHandler<T> {
|
|
6
|
+
private readonly standardHandler;
|
|
7
|
+
constructor(router: Router<T, any>, options?: NoInfer<OpenAPIHandlerOptions<T>>);
|
|
8
|
+
handle(req: NodeHttpRequest, res: NodeHttpResponse, ...rest: StandardHandleRest<T>): Promise<NodeHttpHandleResult>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyProcedure } from '@orpc/server';
|
|
2
|
+
import type { StandardCodec, StandardParams, StandardRequest, StandardResponse } from '@orpc/server/standard';
|
|
3
|
+
import { type ORPCError } from '@orpc/contract';
|
|
4
|
+
import { OpenAPISerializer } from './openapi-serializer';
|
|
5
|
+
export interface OpenAPICodecOptions {
|
|
6
|
+
serializer?: OpenAPISerializer;
|
|
7
|
+
}
|
|
8
|
+
export declare class OpenAPICodec implements StandardCodec {
|
|
9
|
+
private readonly serializer;
|
|
10
|
+
constructor(options?: OpenAPICodecOptions);
|
|
11
|
+
decode(request: StandardRequest, params: StandardParams | undefined, procedure: AnyProcedure): Promise<unknown>;
|
|
12
|
+
encode(output: unknown, procedure: AnyProcedure): StandardResponse;
|
|
13
|
+
encodeError(error: ORPCError<any, any>): StandardResponse;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=openapi-codec.d.ts.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Context } from '@orpc/server';
|
|
2
|
+
import type { RPCHandlerOptions } from '@orpc/server/standard';
|
|
3
|
+
import type { OpenAPICodecOptions } from './openapi-codec';
|
|
4
|
+
import type { OpenAPIMatcherOptions } from './openapi-matcher';
|
|
5
|
+
export interface OpenAPIHandlerOptions<T extends Context> extends RPCHandlerOptions<T>, OpenAPIMatcherOptions, OpenAPICodecOptions {
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=openapi-handler.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AnyRouter } from '@orpc/server';
|
|
2
|
+
import type { StandardMatcher, StandardMatchResult } from '@orpc/server/standard';
|
|
3
|
+
import { type HTTPPath } from '@orpc/contract';
|
|
4
|
+
export interface OpenAPIMatcherOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Ignore procedure that does not have a method defined in the contract.
|
|
7
|
+
*
|
|
8
|
+
* @default false
|
|
9
|
+
*/
|
|
10
|
+
ignoreUndefinedMethod?: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare class OpenAPIMatcher implements StandardMatcher {
|
|
13
|
+
private readonly tree;
|
|
14
|
+
private readonly ignoreUndefinedMethod;
|
|
15
|
+
constructor(options?: OpenAPIMatcherOptions);
|
|
16
|
+
private pendingRouters;
|
|
17
|
+
init(router: AnyRouter, path?: string[]): void;
|
|
18
|
+
match(method: string, pathname: HTTPPath): Promise<StandardMatchResult>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=openapi-matcher.d.ts.map
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PublicJSONSerializer } from '../../json-serializer';
|
|
2
|
+
export interface OpenAPISerializerOptions {
|
|
3
|
+
jsonSerializer?: PublicJSONSerializer;
|
|
4
|
+
}
|
|
5
|
+
export declare class OpenAPISerializer {
|
|
6
|
+
private readonly jsonSerializer;
|
|
7
|
+
constructor(options?: OpenAPISerializerOptions);
|
|
8
|
+
serialize(data: unknown): unknown;
|
|
9
|
+
deserialize(serialized: unknown): unknown;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=openapi-serializer.d.ts.map
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract';
|
|
2
|
-
import type { ANY_ROUTER } from '@orpc/server';
|
|
3
1
|
import type { PublicOpenAPIInputStructureParser } from './openapi-input-structure-parser';
|
|
4
2
|
import type { PublicOpenAPIOutputStructureParser } from './openapi-output-structure-parser';
|
|
5
3
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
6
4
|
import type { SchemaConverter } from './schema-converter';
|
|
5
|
+
import { type ContractRouter } from '@orpc/contract';
|
|
6
|
+
import { type AnyRouter } from '@orpc/server';
|
|
7
7
|
import { type PublicJSONSerializer } from './json-serializer';
|
|
8
8
|
import { type OpenAPI } from './openapi';
|
|
9
9
|
import { type PublicOpenAPIContentBuilder } from './openapi-content-builder';
|
|
@@ -40,6 +40,12 @@ export interface OpenAPIGeneratorOptions {
|
|
|
40
40
|
* @default 'throw'
|
|
41
41
|
*/
|
|
42
42
|
errorHandlerStrategy?: ErrorHandlerStrategy;
|
|
43
|
+
/**
|
|
44
|
+
* Strict error response
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
48
|
+
strictErrorResponses?: boolean;
|
|
43
49
|
}
|
|
44
50
|
export declare class OpenAPIGenerator {
|
|
45
51
|
private readonly contentBuilder;
|
|
@@ -53,8 +59,9 @@ export declare class OpenAPIGenerator {
|
|
|
53
59
|
private readonly errorHandlerStrategy;
|
|
54
60
|
private readonly ignoreUndefinedPathProcedures;
|
|
55
61
|
private readonly considerMissingTagDefinitionAsError;
|
|
62
|
+
private readonly strictErrorResponses;
|
|
56
63
|
constructor(options?: OpenAPIGeneratorOptions);
|
|
57
|
-
generate(router: ContractRouter |
|
|
64
|
+
generate(router: ContractRouter<any> | AnyRouter, doc: Omit<OpenAPI.OpenAPIObject, 'openapi'>): Promise<OpenAPI.OpenAPIObject>;
|
|
58
65
|
}
|
|
59
66
|
export {};
|
|
60
67
|
//# sourceMappingURL=openapi-generator.d.ts.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyContractProcedure } from '@orpc/contract';
|
|
2
2
|
import type { PublicOpenAPIPathParser } from './openapi-path-parser';
|
|
3
3
|
import type { JSONSchema, ObjectSchema } from './schema';
|
|
4
4
|
import type { SchemaConverter } from './schema-converter';
|
|
@@ -14,7 +14,7 @@ export declare class OpenAPIInputStructureParser {
|
|
|
14
14
|
private readonly schemaUtils;
|
|
15
15
|
private readonly pathParser;
|
|
16
16
|
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils, pathParser: PublicOpenAPIPathParser);
|
|
17
|
-
parse(contract:
|
|
17
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIInputStructureParseResult;
|
|
18
18
|
private parseDetailedSchema;
|
|
19
19
|
private parseCompactSchema;
|
|
20
20
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AnyContractProcedure } from '@orpc/contract';
|
|
2
2
|
import type { JSONSchema, ObjectSchema } from './schema';
|
|
3
3
|
import type { SchemaConverter } from './schema-converter';
|
|
4
4
|
import type { PublicSchemaUtils } from './schema-utils';
|
|
@@ -10,7 +10,7 @@ export declare class OpenAPIOutputStructureParser {
|
|
|
10
10
|
private readonly schemaConverter;
|
|
11
11
|
private readonly schemaUtils;
|
|
12
12
|
constructor(schemaConverter: SchemaConverter, schemaUtils: PublicSchemaUtils);
|
|
13
|
-
parse(contract:
|
|
13
|
+
parse(contract: AnyContractProcedure, structure: 'compact' | 'detailed'): OpenAPIOutputStructureParseResult;
|
|
14
14
|
private parseDetailedSchema;
|
|
15
15
|
private parseCompactSchema;
|
|
16
16
|
}
|
|
@@ -4,8 +4,8 @@ export interface SchemaConvertOptions {
|
|
|
4
4
|
strategy: 'input' | 'output';
|
|
5
5
|
}
|
|
6
6
|
export interface SchemaConverter {
|
|
7
|
-
condition
|
|
8
|
-
convert
|
|
7
|
+
condition(schema: Schema, options: SchemaConvertOptions): boolean;
|
|
8
|
+
convert(schema: Schema, options: SchemaConvertOptions): JSONSchema.JSONSchema;
|
|
9
9
|
}
|
|
10
10
|
export declare class CompositeSchemaConverter implements SchemaConverter {
|
|
11
11
|
private readonly converters;
|
package/dist/src/schema.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ export type FileSchema = JSONSchema.JSONSchema & {
|
|
|
8
8
|
type: 'string';
|
|
9
9
|
contentMediaType: string;
|
|
10
10
|
} & object;
|
|
11
|
-
export declare const NON_LOGIC_KEYWORDS:
|
|
11
|
+
export declare const NON_LOGIC_KEYWORDS: string[];
|
|
12
12
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,18 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ANY_PROCEDURE, ANY_ROUTER, Lazy } from '@orpc/server';
|
|
3
|
-
export interface EachLeafOptions {
|
|
4
|
-
router: ContractRouter | ANY_ROUTER;
|
|
5
|
-
path: string[];
|
|
6
|
-
}
|
|
7
|
-
export interface EachLeafCallbackOptions {
|
|
8
|
-
contract: WELL_CONTRACT_PROCEDURE;
|
|
9
|
-
path: string[];
|
|
10
|
-
}
|
|
11
|
-
export interface EachContractLeafResultItem {
|
|
12
|
-
router: Lazy<ANY_PROCEDURE> | Lazy<Record<string, ANY_ROUTER> | ANY_PROCEDURE>;
|
|
13
|
-
path: string[];
|
|
14
|
-
}
|
|
15
|
-
export declare function forEachContractProcedure(options: EachLeafOptions, callback: (options: EachLeafCallbackOptions) => void, result?: EachContractLeafResultItem[], isCurrentRouterContract?: boolean): EachContractLeafResultItem[];
|
|
16
|
-
export declare function forEachAllContractProcedure(router: ContractRouter | ANY_ROUTER, callback: (options: EachLeafCallbackOptions) => void): Promise<void>;
|
|
1
|
+
import type { HTTPPath } from '@orpc/contract';
|
|
17
2
|
export declare function standardizeHTTPPath(path: HTTPPath): HTTPPath;
|
|
18
3
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/standard.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
OpenAPICodec,
|
|
3
|
+
OpenAPIMatcher,
|
|
4
|
+
OpenAPISerializer,
|
|
5
|
+
bracket_notation_exports
|
|
6
|
+
} from "./chunk-PWOV66X6.js";
|
|
7
|
+
import "./chunk-HC5PVG4R.js";
|
|
8
|
+
export {
|
|
9
|
+
bracket_notation_exports as BracketNotation,
|
|
10
|
+
OpenAPICodec,
|
|
11
|
+
OpenAPIMatcher,
|
|
12
|
+
OpenAPISerializer
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=standard.js.map
|
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.7b09958",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://orpc.unnoq.com",
|
|
7
7
|
"repository": {
|
|
@@ -19,11 +19,31 @@
|
|
|
19
19
|
"import": "./dist/index.js",
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./standard": {
|
|
23
|
+
"types": "./dist/src/adapters/standard/index.d.ts",
|
|
24
|
+
"import": "./dist/standard.js",
|
|
25
|
+
"default": "./dist/standard.js"
|
|
26
|
+
},
|
|
22
27
|
"./fetch": {
|
|
23
|
-
"types": "./dist/src/fetch/index.d.ts",
|
|
28
|
+
"types": "./dist/src/adapters/fetch/index.d.ts",
|
|
24
29
|
"import": "./dist/fetch.js",
|
|
25
30
|
"default": "./dist/fetch.js"
|
|
26
31
|
},
|
|
32
|
+
"./hono": {
|
|
33
|
+
"types": "./dist/src/adapters/hono/index.d.ts",
|
|
34
|
+
"import": "./dist/hono.js",
|
|
35
|
+
"default": "./dist/hono.js"
|
|
36
|
+
},
|
|
37
|
+
"./next": {
|
|
38
|
+
"types": "./dist/src/adapters/next/index.d.ts",
|
|
39
|
+
"import": "./dist/next.js",
|
|
40
|
+
"default": "./dist/next.js"
|
|
41
|
+
},
|
|
42
|
+
"./node": {
|
|
43
|
+
"types": "./dist/src/adapters/node/index.d.ts",
|
|
44
|
+
"import": "./dist/node.js",
|
|
45
|
+
"default": "./dist/node.js"
|
|
46
|
+
},
|
|
27
47
|
"./🔒/*": {
|
|
28
48
|
"types": "./dist/src/*.d.ts"
|
|
29
49
|
}
|
|
@@ -34,25 +54,22 @@
|
|
|
34
54
|
"dist"
|
|
35
55
|
],
|
|
36
56
|
"dependencies": {
|
|
37
|
-
"@standard-schema/spec": "1.0.0-beta.4",
|
|
38
|
-
"@types/content-disposition": "^0.5.8",
|
|
39
|
-
"content-disposition": "^0.5.4",
|
|
40
57
|
"escape-string-regexp": "^5.0.0",
|
|
41
58
|
"fast-content-type-parse": "^2.0.0",
|
|
42
|
-
"hono": "^4.6.12",
|
|
43
59
|
"json-schema-typed": "^8.0.1",
|
|
44
60
|
"openapi3-ts": "^4.4.0",
|
|
61
|
+
"rou3": "^0.5.1",
|
|
45
62
|
"wildcard-match": "^5.1.3",
|
|
46
|
-
"@orpc/
|
|
47
|
-
"@orpc/shared": "0.0.0-next.
|
|
48
|
-
"@orpc/
|
|
63
|
+
"@orpc/contract": "0.0.0-next.7b09958",
|
|
64
|
+
"@orpc/shared": "0.0.0-next.7b09958",
|
|
65
|
+
"@orpc/server": "0.0.0-next.7b09958"
|
|
49
66
|
},
|
|
50
67
|
"devDependencies": {
|
|
51
68
|
"@readme/openapi-parser": "^2.6.0",
|
|
52
69
|
"zod": "^3.24.1"
|
|
53
70
|
},
|
|
54
71
|
"scripts": {
|
|
55
|
-
"build": "tsup --
|
|
72
|
+
"build": "tsup --onSuccess='tsc -b --noCheck'",
|
|
56
73
|
"build:watch": "pnpm run build --watch",
|
|
57
74
|
"type:check": "tsc -b"
|
|
58
75
|
}
|