@orpc/openapi 0.0.0-next.141bae5 → 0.0.0-next.1431467
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 +91 -0
- package/dist/adapters/fetch/index.d.mts +13 -0
- package/dist/adapters/fetch/index.d.ts +13 -0
- package/dist/adapters/fetch/index.mjs +10 -0
- package/dist/adapters/hono/index.d.mts +6 -0
- package/dist/adapters/hono/index.d.ts +6 -0
- package/dist/adapters/hono/index.mjs +10 -0
- package/dist/adapters/next/index.d.mts +6 -0
- package/dist/adapters/next/index.d.ts +6 -0
- package/dist/adapters/next/index.mjs +10 -0
- package/dist/adapters/node/index.d.mts +13 -0
- package/dist/adapters/node/index.d.ts +13 -0
- package/dist/adapters/node/index.mjs +32 -0
- package/dist/adapters/standard/index.d.mts +23 -0
- package/dist/adapters/standard/index.d.ts +23 -0
- package/dist/adapters/standard/index.mjs +6 -0
- package/dist/index.d.mts +167 -0
- package/dist/index.d.ts +167 -0
- package/dist/{index.js → index.mjs} +273 -113
- package/dist/shared/openapi.B6uueFtN.mjs +29 -0
- package/dist/shared/openapi.BHG_gu5Z.mjs +8 -0
- package/dist/shared/openapi.C_biOx82.mjs +147 -0
- package/package.json +32 -34
- package/dist/chunk-KNYXLM77.js +0 -107
- package/dist/chunk-XYIZDXKB.js +0 -652
- package/dist/chunk-YOKECDND.js +0 -25
- package/dist/fetch.js +0 -34
- package/dist/hono.js +0 -34
- package/dist/next.js +0 -34
- package/dist/node.js +0 -46
- package/dist/src/adapters/fetch/bracket-notation.d.ts +0 -84
- package/dist/src/adapters/fetch/index.d.ts +0 -10
- package/dist/src/adapters/fetch/input-structure-compact.d.ts +0 -6
- package/dist/src/adapters/fetch/input-structure-detailed.d.ts +0 -11
- package/dist/src/adapters/fetch/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/fetch/openapi-handler.d.ts +0 -32
- package/dist/src/adapters/fetch/openapi-payload-codec.d.ts +0 -15
- package/dist/src/adapters/fetch/openapi-procedure-matcher.d.ts +0 -19
- package/dist/src/adapters/fetch/schema-coercer.d.ts +0 -10
- package/dist/src/adapters/hono/index.d.ts +0 -2
- package/dist/src/adapters/next/index.d.ts +0 -2
- package/dist/src/adapters/node/index.d.ts +0 -5
- package/dist/src/adapters/node/openapi-handler-server.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler-serverless.d.ts +0 -7
- package/dist/src/adapters/node/openapi-handler.d.ts +0 -11
- package/dist/src/adapters/node/types.d.ts +0 -2
- package/dist/src/index.d.ts +0 -12
- package/dist/src/json-serializer.d.ts +0 -5
- package/dist/src/openapi-content-builder.d.ts +0 -10
- package/dist/src/openapi-error.d.ts +0 -3
- package/dist/src/openapi-generator.d.ts +0 -60
- package/dist/src/openapi-input-structure-parser.d.ts +0 -22
- package/dist/src/openapi-output-structure-parser.d.ts +0 -18
- package/dist/src/openapi-parameters-builder.d.ts +0 -12
- package/dist/src/openapi-path-parser.d.ts +0 -8
- package/dist/src/openapi.d.ts +0 -3
- package/dist/src/schema-converter.d.ts +0 -16
- package/dist/src/schema-utils.d.ts +0 -11
- package/dist/src/schema.d.ts +0 -12
- package/dist/src/utils.d.ts +0 -18
|
@@ -1,16 +1,59 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
1
|
+
import { isProcedure, eachAllContractProcedure } from '@orpc/server';
|
|
2
|
+
import { OpenApiBuilder } from 'openapi3-ts/oas31';
|
|
3
|
+
export { OpenApiBuilder } from 'openapi3-ts/oas31';
|
|
4
|
+
import { findDeepMatches, isObject, get, omit, group } from '@orpc/shared';
|
|
5
|
+
import { fallbackORPCErrorStatus } from '@orpc/client';
|
|
6
|
+
import { fallbackContractConfig, getEventIteratorSchemaDetails } from '@orpc/contract';
|
|
7
|
+
import { OpenAPIJsonSerializer } from '@orpc/openapi-client/standard';
|
|
8
|
+
export { Format as JSONSchemaFormat, keywords as JSONSchemaKeywords } from 'json-schema-typed/draft-2020-12';
|
|
9
|
+
import { t as toOpenAPI31RoutePattern } from './shared/openapi.BHG_gu5Z.mjs';
|
|
10
|
+
export { s as standardizeHTTPPath } from './shared/openapi.BHG_gu5Z.mjs';
|
|
7
11
|
|
|
8
|
-
|
|
9
|
-
|
|
12
|
+
const OPERATION_EXTENDER_SYMBOL = Symbol("ORPC_OPERATION_EXTENDER");
|
|
13
|
+
function setOperationExtender(o, extend) {
|
|
14
|
+
return new Proxy(o, {
|
|
15
|
+
get(target, prop, receiver) {
|
|
16
|
+
if (prop === OPERATION_EXTENDER_SYMBOL) {
|
|
17
|
+
return extend;
|
|
18
|
+
}
|
|
19
|
+
return Reflect.get(target, prop, receiver);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function getOperationExtender(o) {
|
|
24
|
+
return o[OPERATION_EXTENDER_SYMBOL];
|
|
25
|
+
}
|
|
26
|
+
function extendOperation(operation, procedure) {
|
|
27
|
+
const operationExtenders = [];
|
|
28
|
+
for (const errorItem of Object.values(procedure["~orpc"].errorMap)) {
|
|
29
|
+
const maybeExtender = getOperationExtender(errorItem);
|
|
30
|
+
if (maybeExtender) {
|
|
31
|
+
operationExtenders.push(maybeExtender);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (isProcedure(procedure)) {
|
|
35
|
+
for (const middleware of procedure["~orpc"].middlewares) {
|
|
36
|
+
const maybeExtender = getOperationExtender(middleware);
|
|
37
|
+
if (maybeExtender) {
|
|
38
|
+
operationExtenders.push(maybeExtender);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
let currentOperation = operation;
|
|
43
|
+
for (const extender of operationExtenders) {
|
|
44
|
+
if (typeof extender === "function") {
|
|
45
|
+
currentOperation = extender(currentOperation, procedure);
|
|
46
|
+
} else {
|
|
47
|
+
currentOperation = {
|
|
48
|
+
...currentOperation,
|
|
49
|
+
...extender
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return currentOperation;
|
|
54
|
+
}
|
|
10
55
|
|
|
11
|
-
|
|
12
|
-
import { findDeepMatches } from "@orpc/shared";
|
|
13
|
-
var OpenAPIContentBuilder = class {
|
|
56
|
+
class OpenAPIContentBuilder {
|
|
14
57
|
constructor(schemaUtils) {
|
|
15
58
|
this.schemaUtils = schemaUtils;
|
|
16
59
|
}
|
|
@@ -33,26 +76,20 @@ var OpenAPIContentBuilder = class {
|
|
|
33
76
|
}
|
|
34
77
|
return content;
|
|
35
78
|
}
|
|
36
|
-
}
|
|
79
|
+
}
|
|
37
80
|
|
|
38
|
-
|
|
39
|
-
|
|
81
|
+
class OpenAPIError extends Error {
|
|
82
|
+
}
|
|
40
83
|
|
|
41
|
-
|
|
42
|
-
var OpenAPIError = class extends Error {
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
// src/openapi-input-structure-parser.ts
|
|
46
|
-
import { fallbackToGlobalConfig } from "@orpc/contract";
|
|
47
|
-
var OpenAPIInputStructureParser = class {
|
|
84
|
+
class OpenAPIInputStructureParser {
|
|
48
85
|
constructor(schemaConverter, schemaUtils, pathParser) {
|
|
49
86
|
this.schemaConverter = schemaConverter;
|
|
50
87
|
this.schemaUtils = schemaUtils;
|
|
51
88
|
this.pathParser = pathParser;
|
|
52
89
|
}
|
|
53
90
|
parse(contract, structure) {
|
|
54
|
-
const inputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
55
|
-
const method =
|
|
91
|
+
const [_, inputSchema] = this.schemaConverter.convert(contract["~orpc"].inputSchema, "input");
|
|
92
|
+
const method = fallbackContractConfig("defaultMethod", contract["~orpc"].route?.method);
|
|
56
93
|
const httpPath = contract["~orpc"].route?.path;
|
|
57
94
|
if (this.schemaUtils.isAnySchema(inputSchema)) {
|
|
58
95
|
return {
|
|
@@ -135,16 +172,15 @@ var OpenAPIInputStructureParser = class {
|
|
|
135
172
|
bodySchema: method !== "GET" ? rest : void 0
|
|
136
173
|
};
|
|
137
174
|
}
|
|
138
|
-
}
|
|
175
|
+
}
|
|
139
176
|
|
|
140
|
-
|
|
141
|
-
var OpenAPIOutputStructureParser = class {
|
|
177
|
+
class OpenAPIOutputStructureParser {
|
|
142
178
|
constructor(schemaConverter, schemaUtils) {
|
|
143
179
|
this.schemaConverter = schemaConverter;
|
|
144
180
|
this.schemaUtils = schemaUtils;
|
|
145
181
|
}
|
|
146
182
|
parse(contract, structure) {
|
|
147
|
-
const outputSchema = this.schemaConverter.convert(contract["~orpc"].
|
|
183
|
+
const [_, outputSchema] = this.schemaConverter.convert(contract["~orpc"].outputSchema, "output");
|
|
148
184
|
if (this.schemaUtils.isAnySchema(outputSchema)) {
|
|
149
185
|
return {
|
|
150
186
|
headersSchema: void 0,
|
|
@@ -180,17 +216,15 @@ var OpenAPIOutputStructureParser = class {
|
|
|
180
216
|
bodySchema: outputSchema
|
|
181
217
|
};
|
|
182
218
|
}
|
|
183
|
-
}
|
|
219
|
+
}
|
|
184
220
|
|
|
185
|
-
|
|
186
|
-
import { get, isPlainObject, omit } from "@orpc/shared";
|
|
187
|
-
var OpenAPIParametersBuilder = class {
|
|
221
|
+
class OpenAPIParametersBuilder {
|
|
188
222
|
build(paramIn, jsonSchema, options) {
|
|
189
223
|
const parameters = [];
|
|
190
224
|
for (const name in jsonSchema.properties) {
|
|
191
225
|
const schema = jsonSchema.properties[name];
|
|
192
226
|
const paramExamples = jsonSchema.examples?.filter((example) => {
|
|
193
|
-
return
|
|
227
|
+
return isObject(example) && name in example;
|
|
194
228
|
}).map((example) => {
|
|
195
229
|
return example[name];
|
|
196
230
|
});
|
|
@@ -218,10 +252,9 @@ var OpenAPIParametersBuilder = class {
|
|
|
218
252
|
}
|
|
219
253
|
return headersObject;
|
|
220
254
|
}
|
|
221
|
-
}
|
|
255
|
+
}
|
|
222
256
|
|
|
223
|
-
|
|
224
|
-
var OpenAPIPathParser = class {
|
|
257
|
+
class OpenAPIPathParser {
|
|
225
258
|
parseDynamicParams(path) {
|
|
226
259
|
const raws = path.match(/\{([^}]+)\}/g) ?? [];
|
|
227
260
|
return raws.map((raw) => {
|
|
@@ -229,34 +262,24 @@ var OpenAPIPathParser = class {
|
|
|
229
262
|
return { name, raw };
|
|
230
263
|
});
|
|
231
264
|
}
|
|
232
|
-
}
|
|
265
|
+
}
|
|
233
266
|
|
|
234
|
-
|
|
235
|
-
var CompositeSchemaConverter = class {
|
|
267
|
+
class CompositeSchemaConverter {
|
|
236
268
|
converters;
|
|
237
269
|
constructor(converters) {
|
|
238
270
|
this.converters = converters;
|
|
239
271
|
}
|
|
240
|
-
|
|
241
|
-
return true;
|
|
242
|
-
}
|
|
243
|
-
convert(schema, options) {
|
|
272
|
+
convert(schema, strategy) {
|
|
244
273
|
for (const converter of this.converters) {
|
|
245
|
-
if (converter.condition(schema,
|
|
246
|
-
return converter.convert(schema,
|
|
274
|
+
if (converter.condition(schema, strategy)) {
|
|
275
|
+
return converter.convert(schema, strategy);
|
|
247
276
|
}
|
|
248
277
|
}
|
|
249
|
-
return {};
|
|
278
|
+
return [false, {}];
|
|
250
279
|
}
|
|
251
|
-
}
|
|
280
|
+
}
|
|
252
281
|
|
|
253
|
-
|
|
254
|
-
import { isPlainObject as isPlainObject2 } from "@orpc/shared";
|
|
255
|
-
|
|
256
|
-
// src/schema.ts
|
|
257
|
-
import * as JSONSchema from "json-schema-typed/draft-2020-12";
|
|
258
|
-
import { Format } from "json-schema-typed/draft-2020-12";
|
|
259
|
-
var NON_LOGIC_KEYWORDS = [
|
|
282
|
+
const NON_LOGIC_KEYWORDS = [
|
|
260
283
|
// Core Documentation Keywords
|
|
261
284
|
"$anchor",
|
|
262
285
|
"$comment",
|
|
@@ -284,23 +307,22 @@ var NON_LOGIC_KEYWORDS = [
|
|
|
284
307
|
"$dynamicRef"
|
|
285
308
|
];
|
|
286
309
|
|
|
287
|
-
|
|
288
|
-
var SchemaUtils = class {
|
|
310
|
+
class SchemaUtils {
|
|
289
311
|
isFileSchema(schema) {
|
|
290
|
-
return
|
|
312
|
+
return isObject(schema) && schema.type === "string" && typeof schema.contentMediaType === "string";
|
|
291
313
|
}
|
|
292
314
|
isObjectSchema(schema) {
|
|
293
|
-
return
|
|
315
|
+
return isObject(schema) && schema.type === "object";
|
|
294
316
|
}
|
|
295
317
|
isAnySchema(schema) {
|
|
296
|
-
return schema === true || Object.keys(schema).length === 0;
|
|
318
|
+
return schema === true || Object.keys(schema).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
297
319
|
}
|
|
298
320
|
isUndefinableSchema(schema) {
|
|
299
321
|
const [matches] = this.filterSchemaBranches(schema, (schema2) => {
|
|
300
322
|
if (typeof schema2 === "boolean") {
|
|
301
323
|
return schema2;
|
|
302
324
|
}
|
|
303
|
-
return Object.keys(schema2).length === 0;
|
|
325
|
+
return Object.keys(schema2).filter((key) => !NON_LOGIC_KEYWORDS.includes(key)).length === 0;
|
|
304
326
|
});
|
|
305
327
|
return matches.length > 0;
|
|
306
328
|
}
|
|
@@ -313,7 +335,7 @@ var SchemaUtils = class {
|
|
|
313
335
|
}, {});
|
|
314
336
|
matched.required = schema.required?.filter((key) => separatedProperties.includes(key));
|
|
315
337
|
matched.examples = schema.examples?.map((example) => {
|
|
316
|
-
if (!
|
|
338
|
+
if (!isObject(example)) {
|
|
317
339
|
return example;
|
|
318
340
|
}
|
|
319
341
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -329,7 +351,7 @@ var SchemaUtils = class {
|
|
|
329
351
|
}, {});
|
|
330
352
|
rest.required = schema.required?.filter((key) => !separatedProperties.includes(key));
|
|
331
353
|
rest.examples = schema.examples?.map((example) => {
|
|
332
|
-
if (!
|
|
354
|
+
if (!isObject(example)) {
|
|
333
355
|
return example;
|
|
334
356
|
}
|
|
335
357
|
return Object.entries(example).reduce((acc, [key, value]) => {
|
|
@@ -369,10 +391,9 @@ var SchemaUtils = class {
|
|
|
369
391
|
}
|
|
370
392
|
return [matches, schema];
|
|
371
393
|
}
|
|
372
|
-
}
|
|
394
|
+
}
|
|
373
395
|
|
|
374
|
-
|
|
375
|
-
var OpenAPIGenerator = class {
|
|
396
|
+
class OpenAPIGenerator {
|
|
376
397
|
contentBuilder;
|
|
377
398
|
parametersBuilder;
|
|
378
399
|
schemaConverter;
|
|
@@ -384,11 +405,12 @@ var OpenAPIGenerator = class {
|
|
|
384
405
|
errorHandlerStrategy;
|
|
385
406
|
ignoreUndefinedPathProcedures;
|
|
386
407
|
considerMissingTagDefinitionAsError;
|
|
408
|
+
strictErrorResponses;
|
|
387
409
|
constructor(options) {
|
|
388
410
|
this.parametersBuilder = options?.parametersBuilder ?? new OpenAPIParametersBuilder();
|
|
389
411
|
this.schemaConverter = new CompositeSchemaConverter(options?.schemaConverters ?? []);
|
|
390
412
|
this.schemaUtils = options?.schemaUtils ?? new SchemaUtils();
|
|
391
|
-
this.jsonSerializer = options?.jsonSerializer ?? new
|
|
413
|
+
this.jsonSerializer = options?.jsonSerializer ?? new OpenAPIJsonSerializer();
|
|
392
414
|
this.contentBuilder = options?.contentBuilder ?? new OpenAPIContentBuilder(this.schemaUtils);
|
|
393
415
|
this.pathParser = new OpenAPIPathParser();
|
|
394
416
|
this.inputStructureParser = options?.inputStructureParser ?? new OpenAPIInputStructureParser(this.schemaConverter, this.schemaUtils, this.pathParser);
|
|
@@ -396,6 +418,7 @@ var OpenAPIGenerator = class {
|
|
|
396
418
|
this.errorHandlerStrategy = options?.errorHandlerStrategy ?? "throw";
|
|
397
419
|
this.ignoreUndefinedPathProcedures = options?.ignoreUndefinedPathProcedures ?? false;
|
|
398
420
|
this.considerMissingTagDefinitionAsError = options?.considerMissingTagDefinitionAsError ?? false;
|
|
421
|
+
this.strictErrorResponses = options?.strictErrorResponses ?? true;
|
|
399
422
|
}
|
|
400
423
|
async generate(router, doc) {
|
|
401
424
|
const builder = new OpenApiBuilder({
|
|
@@ -403,37 +426,186 @@ var OpenAPIGenerator = class {
|
|
|
403
426
|
openapi: "3.1.1"
|
|
404
427
|
});
|
|
405
428
|
const rootTags = doc.tags?.map((tag) => tag.name) ?? [];
|
|
406
|
-
await
|
|
429
|
+
await eachAllContractProcedure({
|
|
430
|
+
path: [],
|
|
431
|
+
router
|
|
432
|
+
}, ({ contract, path }) => {
|
|
407
433
|
try {
|
|
408
434
|
const def = contract["~orpc"];
|
|
409
435
|
if (this.ignoreUndefinedPathProcedures && def.route?.path === void 0) {
|
|
410
436
|
return;
|
|
411
437
|
}
|
|
412
|
-
const method =
|
|
413
|
-
const httpPath = def.route?.path ?
|
|
414
|
-
const
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
438
|
+
const method = fallbackContractConfig("defaultMethod", def.route?.method);
|
|
439
|
+
const httpPath = def.route?.path ? toOpenAPI31RoutePattern(def.route?.path) : `/${path.map(encodeURIComponent).join("/")}`;
|
|
440
|
+
const { parameters, requestBody } = (() => {
|
|
441
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.inputSchema);
|
|
442
|
+
if (eventIteratorSchemaDetails) {
|
|
443
|
+
const requestBody3 = {
|
|
444
|
+
required: true,
|
|
445
|
+
content: {
|
|
446
|
+
"text/event-stream": {
|
|
447
|
+
schema: {
|
|
448
|
+
oneOf: [
|
|
449
|
+
{
|
|
450
|
+
type: "object",
|
|
451
|
+
properties: {
|
|
452
|
+
event: { type: "string", const: "message" },
|
|
453
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, "input")[1],
|
|
454
|
+
id: { type: "string" },
|
|
455
|
+
retry: { type: "number" }
|
|
456
|
+
},
|
|
457
|
+
required: ["event", "data"]
|
|
458
|
+
},
|
|
459
|
+
{
|
|
460
|
+
type: "object",
|
|
461
|
+
properties: {
|
|
462
|
+
event: { type: "string", const: "done" },
|
|
463
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, "input")[1],
|
|
464
|
+
id: { type: "string" },
|
|
465
|
+
retry: { type: "number" }
|
|
466
|
+
},
|
|
467
|
+
required: ["event", "data"]
|
|
468
|
+
},
|
|
469
|
+
{
|
|
470
|
+
type: "object",
|
|
471
|
+
properties: {
|
|
472
|
+
event: { type: "string", const: "error" },
|
|
473
|
+
data: {},
|
|
474
|
+
id: { type: "string" },
|
|
475
|
+
retry: { type: "number" }
|
|
476
|
+
},
|
|
477
|
+
required: ["event", "data"]
|
|
478
|
+
}
|
|
479
|
+
]
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
return { requestBody: requestBody3, parameters: [] };
|
|
485
|
+
}
|
|
486
|
+
const inputStructure = fallbackContractConfig("defaultInputStructure", def.route?.inputStructure);
|
|
487
|
+
const { paramsSchema, querySchema, headersSchema, bodySchema } = this.inputStructureParser.parse(contract, inputStructure);
|
|
488
|
+
const params = paramsSchema ? this.parametersBuilder.build("path", paramsSchema, {
|
|
489
|
+
required: true
|
|
490
|
+
}) : [];
|
|
491
|
+
const query = querySchema ? this.parametersBuilder.build("query", querySchema) : [];
|
|
492
|
+
const headers = headersSchema ? this.parametersBuilder.build("header", headersSchema) : [];
|
|
493
|
+
const parameters2 = [...params, ...query, ...headers];
|
|
494
|
+
const requestBody2 = bodySchema !== void 0 ? {
|
|
495
|
+
required: this.schemaUtils.isUndefinableSchema(bodySchema),
|
|
496
|
+
content: this.contentBuilder.build(bodySchema)
|
|
497
|
+
} : void 0;
|
|
498
|
+
return { parameters: parameters2, requestBody: requestBody2 };
|
|
499
|
+
})();
|
|
500
|
+
const { responses } = (() => {
|
|
501
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(def.outputSchema);
|
|
502
|
+
if (eventIteratorSchemaDetails) {
|
|
503
|
+
const responses3 = {};
|
|
504
|
+
responses3[fallbackContractConfig("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
505
|
+
description: fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription),
|
|
506
|
+
content: {
|
|
507
|
+
"text/event-stream": {
|
|
508
|
+
schema: {
|
|
509
|
+
oneOf: [
|
|
510
|
+
{
|
|
511
|
+
type: "object",
|
|
512
|
+
properties: {
|
|
513
|
+
event: { type: "string", const: "message" },
|
|
514
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.yields, "input")[1],
|
|
515
|
+
id: { type: "string" },
|
|
516
|
+
retry: { type: "number" }
|
|
517
|
+
},
|
|
518
|
+
required: ["event", "data"]
|
|
519
|
+
},
|
|
520
|
+
{
|
|
521
|
+
type: "object",
|
|
522
|
+
properties: {
|
|
523
|
+
event: { type: "string", const: "done" },
|
|
524
|
+
data: this.schemaConverter.convert(eventIteratorSchemaDetails.returns, "input")[1],
|
|
525
|
+
id: { type: "string" },
|
|
526
|
+
retry: { type: "number" }
|
|
527
|
+
},
|
|
528
|
+
required: ["event", "data"]
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
type: "object",
|
|
532
|
+
properties: {
|
|
533
|
+
event: { type: "string", const: "error" },
|
|
534
|
+
data: {},
|
|
535
|
+
id: { type: "string" },
|
|
536
|
+
retry: { type: "number" }
|
|
537
|
+
},
|
|
538
|
+
required: ["event", "data"]
|
|
539
|
+
}
|
|
540
|
+
]
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
};
|
|
545
|
+
return { responses: responses3 };
|
|
546
|
+
}
|
|
547
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", def.route?.outputStructure);
|
|
548
|
+
const { headersSchema: resHeadersSchema, bodySchema: resBodySchema } = this.outputStructureParser.parse(contract, outputStructure);
|
|
549
|
+
const responses2 = {};
|
|
550
|
+
responses2[fallbackContractConfig("defaultSuccessStatus", def.route?.successStatus)] = {
|
|
551
|
+
description: fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription),
|
|
552
|
+
content: resBodySchema !== void 0 ? this.contentBuilder.build(resBodySchema) : void 0,
|
|
553
|
+
headers: resHeadersSchema !== void 0 ? this.parametersBuilder.buildHeadersObject(resHeadersSchema) : void 0
|
|
554
|
+
};
|
|
555
|
+
return { responses: responses2 };
|
|
556
|
+
})();
|
|
557
|
+
const errors = group(Object.entries(def.errorMap ?? {}).filter(([_, config]) => config).map(([code, config]) => ({
|
|
558
|
+
...config,
|
|
559
|
+
code,
|
|
560
|
+
status: fallbackORPCErrorStatus(code, config?.status)
|
|
561
|
+
})), (error) => error.status);
|
|
562
|
+
for (const status in errors) {
|
|
563
|
+
const configs = errors[status];
|
|
564
|
+
if (!configs || configs.length === 0) {
|
|
565
|
+
continue;
|
|
566
|
+
}
|
|
567
|
+
const schemas = configs.map(({ data, code, message }) => {
|
|
568
|
+
const json = {
|
|
569
|
+
type: "object",
|
|
570
|
+
properties: {
|
|
571
|
+
defined: { const: true },
|
|
572
|
+
code: { const: code },
|
|
573
|
+
status: { const: Number(status) },
|
|
574
|
+
message: { type: "string", default: message },
|
|
575
|
+
data: {}
|
|
576
|
+
},
|
|
577
|
+
required: ["defined", "code", "status", "message"]
|
|
578
|
+
};
|
|
579
|
+
if (data) {
|
|
580
|
+
const dataJson = this.schemaConverter.convert(data, "output")[1];
|
|
581
|
+
json.properties.data = dataJson;
|
|
582
|
+
if (!this.schemaUtils.isUndefinableSchema(dataJson)) {
|
|
583
|
+
json.required.push("data");
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return json;
|
|
587
|
+
});
|
|
588
|
+
if (this.strictErrorResponses) {
|
|
589
|
+
schemas.push({
|
|
590
|
+
type: "object",
|
|
591
|
+
properties: {
|
|
592
|
+
defined: { const: false },
|
|
593
|
+
code: { type: "string" },
|
|
594
|
+
status: { type: "number" },
|
|
595
|
+
message: { type: "string" },
|
|
596
|
+
data: {}
|
|
597
|
+
},
|
|
598
|
+
required: ["defined", "code", "status", "message"]
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
const contentSchema = schemas.length === 1 ? schemas[0] : {
|
|
602
|
+
oneOf: schemas
|
|
603
|
+
};
|
|
604
|
+
responses[status] = {
|
|
605
|
+
description: status,
|
|
606
|
+
content: this.contentBuilder.build(contentSchema)
|
|
607
|
+
};
|
|
608
|
+
}
|
|
437
609
|
if (this.considerMissingTagDefinitionAsError && def.route?.tags) {
|
|
438
610
|
const missingTag = def.route?.tags.find((tag) => !rootTags.includes(tag));
|
|
439
611
|
if (missingTag !== void 0) {
|
|
@@ -450,12 +622,11 @@ var OpenAPIGenerator = class {
|
|
|
450
622
|
operationId: path.join("."),
|
|
451
623
|
parameters: parameters.length ? parameters : void 0,
|
|
452
624
|
requestBody,
|
|
453
|
-
responses
|
|
454
|
-
[fallbackToGlobalConfig2("defaultSuccessStatus", def.route?.successStatus)]: successResponse
|
|
455
|
-
}
|
|
625
|
+
responses
|
|
456
626
|
};
|
|
627
|
+
const extendedOperation = extendOperation(operation, contract);
|
|
457
628
|
builder.addPath(httpPath, {
|
|
458
|
-
[method.toLocaleLowerCase()]:
|
|
629
|
+
[method.toLocaleLowerCase()]: extendedOperation
|
|
459
630
|
});
|
|
460
631
|
} catch (e) {
|
|
461
632
|
if (e instanceof OpenAPIError) {
|
|
@@ -474,23 +645,12 @@ var OpenAPIGenerator = class {
|
|
|
474
645
|
}
|
|
475
646
|
}
|
|
476
647
|
});
|
|
477
|
-
return this.jsonSerializer.serialize(builder.getSpec());
|
|
648
|
+
return this.jsonSerializer.serialize(builder.getSpec())[0];
|
|
478
649
|
}
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
const oo = {
|
|
653
|
+
spec: setOperationExtender
|
|
479
654
|
};
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
JSONSchema,
|
|
483
|
-
Format as JSONSchemaFormat,
|
|
484
|
-
JSONSerializer,
|
|
485
|
-
NON_LOGIC_KEYWORDS,
|
|
486
|
-
OpenAPIContentBuilder,
|
|
487
|
-
OpenAPIGenerator,
|
|
488
|
-
OpenAPIParametersBuilder,
|
|
489
|
-
OpenAPIPathParser,
|
|
490
|
-
OpenApiBuilder,
|
|
491
|
-
SchemaUtils,
|
|
492
|
-
forEachAllContractProcedure,
|
|
493
|
-
forEachContractProcedure,
|
|
494
|
-
standardizeHTTPPath
|
|
495
|
-
};
|
|
496
|
-
//# sourceMappingURL=index.js.map
|
|
655
|
+
|
|
656
|
+
export { CompositeSchemaConverter, NON_LOGIC_KEYWORDS, OpenAPIContentBuilder, OpenAPIGenerator, OpenAPIParametersBuilder, OpenAPIPathParser, SchemaUtils, extendOperation, getOperationExtender, oo, setOperationExtender, toOpenAPI31RoutePattern };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OpenAPISerializer } from '@orpc/openapi-client/standard';
|
|
2
|
+
import { StandardHandler } from '@orpc/server/standard';
|
|
3
|
+
import { toStandardLazyRequest, toFetchResponse } from '@orpc/standard-server-fetch';
|
|
4
|
+
import { a as OpenAPIMatcher, O as OpenAPICodec } from './openapi.C_biOx82.mjs';
|
|
5
|
+
|
|
6
|
+
class OpenAPIHandler {
|
|
7
|
+
standardHandler;
|
|
8
|
+
constructor(router, options = {}) {
|
|
9
|
+
const serializer = new OpenAPISerializer();
|
|
10
|
+
const matcher = new OpenAPIMatcher();
|
|
11
|
+
const codec = new OpenAPICodec(serializer);
|
|
12
|
+
this.standardHandler = new StandardHandler(router, matcher, codec, options);
|
|
13
|
+
}
|
|
14
|
+
async handle(request, ...[
|
|
15
|
+
options = {}
|
|
16
|
+
]) {
|
|
17
|
+
const standardRequest = toStandardLazyRequest(request);
|
|
18
|
+
const result = await this.standardHandler.handle(standardRequest, options);
|
|
19
|
+
if (!result.matched) {
|
|
20
|
+
return result;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
matched: true,
|
|
24
|
+
response: toFetchResponse(result.response, options)
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export { OpenAPIHandler as O };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
function standardizeHTTPPath(path) {
|
|
2
|
+
return `/${path.replace(/\/{2,}/g, "/").replace(/^\/|\/$/g, "")}`;
|
|
3
|
+
}
|
|
4
|
+
function toOpenAPI31RoutePattern(path) {
|
|
5
|
+
return standardizeHTTPPath(path).replace(/\{\+([^}]+)\}/g, "{$1}");
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export { standardizeHTTPPath as s, toOpenAPI31RoutePattern as t };
|