@temporary-name/server 1.9.3-alpha.ec3bfb9dce56198911349c322c970208b21b50db → 1.9.3-alpha.fb7b7d19964e1b2def7056f4345b63d6fcacce10
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/adapters/aws-lambda/index.d.mts +2 -2
- package/dist/adapters/aws-lambda/index.d.ts +2 -2
- package/dist/adapters/fetch/index.d.mts +2 -2
- package/dist/adapters/fetch/index.d.ts +2 -2
- package/dist/adapters/node/index.d.mts +2 -2
- package/dist/adapters/node/index.d.ts +2 -2
- package/dist/adapters/standard/index.d.mts +2 -2
- package/dist/adapters/standard/index.d.ts +2 -2
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.mjs +43 -39
- package/dist/openapi/index.d.mts +10 -30
- package/dist/openapi/index.d.ts +10 -30
- package/dist/openapi/index.mjs +335 -293
- package/dist/shared/{server.D8RAzJ_p.d.ts → server.B0LJ_wu-.d.ts} +1 -1
- package/dist/shared/{server.CVhIyQ4x.d.mts → server.BQZMQrPe.d.mts} +1 -1
- package/dist/shared/{server.Cj3_Lp61.d.mts → server.DXPMDozZ.d.mts} +26 -11
- package/dist/shared/{server.Cj3_Lp61.d.ts → server.DXPMDozZ.d.ts} +26 -11
- package/package.json +9 -8
package/dist/openapi/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ZodToJsonSchemaConverter } from '@temporary-name/json-schema';
|
|
2
|
+
import { isObject, stringifyJSON, findDeepMatches, clone, value, fallbackContractConfig, toHttpPath, assertNever, isORPCErrorStatus } from '@temporary-name/shared';
|
|
2
3
|
import { j as jsonSerialize } from '../shared/server.CQIFwyhc.mjs';
|
|
3
4
|
import '@temporary-name/standard-server';
|
|
4
5
|
import { g as getEventIteratorSchemaDetails } from '../shared/server.YUvuxHty.mjs';
|
|
@@ -355,330 +356,371 @@ function resolveOpenAPIJsonSchemaRef(doc, schema) {
|
|
|
355
356
|
return resolved ?? schema;
|
|
356
357
|
}
|
|
357
358
|
|
|
358
|
-
class
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
359
|
+
class OpenAPIGeneratorError extends Error {
|
|
360
|
+
}
|
|
361
|
+
async function generateOpenApiSpec(router, options = {}) {
|
|
362
|
+
const converter = typeof options.schemaConverter === "function" ? options.schemaConverter : new ZodToJsonSchemaConverter(options.schemaConverter ?? {}).convert;
|
|
363
|
+
const filter = options.filter ?? (({ contract, path }) => {
|
|
364
|
+
return !(options.exclude?.(contract, path) ?? false);
|
|
365
|
+
});
|
|
366
|
+
const doc = {
|
|
367
|
+
...clone(options.spec),
|
|
368
|
+
info: options.spec?.info ?? { title: "API Reference", version: "0.0.0" },
|
|
369
|
+
openapi: "3.1.1"
|
|
370
|
+
};
|
|
371
|
+
const { baseSchemaConvertOptions } = await resolveCommonSchemas(doc, options.commonSchemas, converter);
|
|
372
|
+
const contracts = [];
|
|
373
|
+
await resolveContractProcedures({ path: [], router }, (traverseOptions) => {
|
|
374
|
+
if (!value(filter, traverseOptions)) {
|
|
375
|
+
return;
|
|
376
|
+
}
|
|
377
|
+
contracts.push(traverseOptions);
|
|
378
|
+
});
|
|
379
|
+
const namesByAuthConfig = /* @__PURE__ */ new Map();
|
|
380
|
+
const authConfigNames = /* @__PURE__ */ new Set();
|
|
381
|
+
for (const { contract } of contracts) {
|
|
382
|
+
for (const authConfig of contract["~orpc"].authConfigs) {
|
|
383
|
+
if (authConfig.type === "none" || namesByAuthConfig.has(authConfig)) {
|
|
384
|
+
continue;
|
|
367
385
|
}
|
|
386
|
+
const oasNameBase = authConfig.oasName ?? `${authConfig.type}Auth`;
|
|
387
|
+
let oasName = oasNameBase;
|
|
388
|
+
for (let i = 2; authConfigNames.has(oasName); i++) {
|
|
389
|
+
oasName = `${oasNameBase}${i}`;
|
|
390
|
+
}
|
|
391
|
+
namesByAuthConfig.set(authConfig, oasName);
|
|
392
|
+
authConfigNames.add(oasName);
|
|
368
393
|
}
|
|
369
|
-
return [false, {}];
|
|
370
394
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
constructor(options = {}) {
|
|
378
|
-
this.converter = new CompositeSchemaConverter(toArray(options.schemaConverters));
|
|
395
|
+
if (namesByAuthConfig.size > 0) {
|
|
396
|
+
doc.components ??= {};
|
|
397
|
+
const schemes = doc.components.securitySchemes ??= {};
|
|
398
|
+
for (const [authConfig, name] of namesByAuthConfig) {
|
|
399
|
+
schemes[name] ??= authConfigToSecurityScheme(authConfig);
|
|
400
|
+
}
|
|
379
401
|
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
if (!value(filter, traverseOptions)) {
|
|
401
|
-
return;
|
|
402
|
-
}
|
|
403
|
-
contracts.push(traverseOptions);
|
|
404
|
-
});
|
|
405
|
-
const errors = [];
|
|
406
|
-
for (const { contract, path } of contracts) {
|
|
407
|
-
const stringPath = path.join(".");
|
|
408
|
-
try {
|
|
409
|
-
const def = contract["~orpc"];
|
|
410
|
-
const method = toOpenAPIMethod(fallbackContractConfig("defaultMethod", def.route.method));
|
|
411
|
-
const httpPath = toOpenAPIPath(def.route.path ?? toHttpPath(path));
|
|
412
|
-
let operationObjectRef;
|
|
413
|
-
if (def.route.spec !== void 0 && typeof def.route.spec !== "function") {
|
|
414
|
-
operationObjectRef = def.route.spec;
|
|
415
|
-
} else {
|
|
416
|
-
operationObjectRef = {
|
|
417
|
-
operationId: def.route.operationId ?? stringPath,
|
|
418
|
-
summary: def.route.summary,
|
|
419
|
-
description: def.route.description,
|
|
420
|
-
deprecated: def.route.deprecated,
|
|
421
|
-
tags: def.route.tags?.map((tag) => tag)
|
|
422
|
-
};
|
|
423
|
-
await this.#request(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
424
|
-
await this.#successResponse(doc, operationObjectRef, def, baseSchemaConvertOptions);
|
|
425
|
-
}
|
|
426
|
-
if (typeof def.route.spec === "function") {
|
|
427
|
-
operationObjectRef = def.route.spec(operationObjectRef);
|
|
428
|
-
}
|
|
429
|
-
doc.paths ??= {};
|
|
430
|
-
doc.paths[httpPath] ??= {};
|
|
431
|
-
doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
|
|
432
|
-
} catch (e) {
|
|
433
|
-
if (!(e instanceof OpenAPIGeneratorError)) {
|
|
434
|
-
throw e;
|
|
435
|
-
}
|
|
436
|
-
errors.push(
|
|
437
|
-
`[OpenAPIGenerator] Error occurred while generating OpenAPI for procedure at path: ${stringPath}
|
|
438
|
-
${e.message}`
|
|
402
|
+
const errors = [];
|
|
403
|
+
for (const { contract, path } of contracts) {
|
|
404
|
+
const stringPath = path.join(".");
|
|
405
|
+
try {
|
|
406
|
+
const def = contract["~orpc"];
|
|
407
|
+
const method = toOpenAPIMethod(fallbackContractConfig("defaultMethod", def.route.method));
|
|
408
|
+
const httpPath = toOpenAPIPath(def.route.path ?? toHttpPath(path));
|
|
409
|
+
let operationObjectRef;
|
|
410
|
+
if (def.route.spec !== void 0 && typeof def.route.spec !== "function") {
|
|
411
|
+
operationObjectRef = def.route.spec;
|
|
412
|
+
} else {
|
|
413
|
+
operationObjectRef = {
|
|
414
|
+
operationId: def.route.operationId ?? stringPath,
|
|
415
|
+
summary: def.route.summary,
|
|
416
|
+
description: def.route.description,
|
|
417
|
+
deprecated: def.route.deprecated,
|
|
418
|
+
tags: def.route.tags?.map((tag) => tag)
|
|
419
|
+
};
|
|
420
|
+
const security = def.authConfigs.map(
|
|
421
|
+
(authConfig) => authConfig.type === "none" ? {} : { [namesByAuthConfig.get(authConfig)]: [] }
|
|
439
422
|
);
|
|
423
|
+
if (security.length > 0) {
|
|
424
|
+
operationObjectRef.security = security;
|
|
425
|
+
}
|
|
426
|
+
await handleRequest(doc, operationObjectRef, def, baseSchemaConvertOptions, converter);
|
|
427
|
+
await handleSuccessResponse(doc, operationObjectRef, def, baseSchemaConvertOptions, converter);
|
|
428
|
+
}
|
|
429
|
+
if (typeof def.route.spec === "function") {
|
|
430
|
+
operationObjectRef = def.route.spec(operationObjectRef);
|
|
431
|
+
}
|
|
432
|
+
doc.paths ??= {};
|
|
433
|
+
doc.paths[httpPath] ??= {};
|
|
434
|
+
doc.paths[httpPath][method] = applyCustomOpenAPIOperation(operationObjectRef, contract);
|
|
435
|
+
} catch (e) {
|
|
436
|
+
if (!(e instanceof OpenAPIGeneratorError)) {
|
|
437
|
+
throw e;
|
|
440
438
|
}
|
|
439
|
+
errors.push(
|
|
440
|
+
`[OpenAPIGenerator] Error occurred while generating OpenAPI for procedure at path: ${stringPath}
|
|
441
|
+
${e.message}`
|
|
442
|
+
);
|
|
441
443
|
}
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
444
|
+
}
|
|
445
|
+
if (errors.length) {
|
|
446
|
+
throw new OpenAPIGeneratorError(
|
|
447
|
+
`Some error occurred during OpenAPI generation:
|
|
445
448
|
|
|
446
449
|
${errors.join("\n\n")}`
|
|
447
|
-
|
|
448
|
-
}
|
|
449
|
-
return jsonSerialize(doc)[0];
|
|
450
|
+
);
|
|
450
451
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
},
|
|
461
|
-
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
452
|
+
return jsonSerialize(doc)[0];
|
|
453
|
+
}
|
|
454
|
+
async function resolveCommonSchemas(doc, commonSchemas, converter) {
|
|
455
|
+
let undefinedErrorJsonSchema = {
|
|
456
|
+
type: "object",
|
|
457
|
+
properties: {
|
|
458
|
+
defined: { const: false },
|
|
459
|
+
code: { type: "string" },
|
|
460
|
+
status: { type: "number" },
|
|
461
|
+
message: { type: "string" },
|
|
462
|
+
data: {}
|
|
463
|
+
},
|
|
464
|
+
required: ["defined", "code", "status", "message"]
|
|
465
|
+
};
|
|
466
|
+
const baseSchemaConvertOptions = {};
|
|
467
|
+
if (commonSchemas) {
|
|
468
|
+
baseSchemaConvertOptions.components = [];
|
|
469
|
+
for (const key in commonSchemas) {
|
|
470
|
+
const options = commonSchemas[key];
|
|
471
|
+
if (options.schema === void 0) {
|
|
472
|
+
continue;
|
|
473
|
+
}
|
|
474
|
+
const { schema, strategy = "input" } = options;
|
|
475
|
+
const [required, json] = await converter(schema, { strategy });
|
|
476
|
+
const allowedStrategies = [strategy];
|
|
477
|
+
if (strategy === "input") {
|
|
478
|
+
const [outputRequired, outputJson] = await converter(schema, { strategy: "output" });
|
|
479
|
+
if (outputRequired === required && stringifyJSON(outputJson) === stringifyJSON(json)) {
|
|
480
|
+
allowedStrategies.push("output");
|
|
470
481
|
}
|
|
471
|
-
|
|
472
|
-
const [
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
const [outputRequired, outputJson] = await this.converter.convert(schema, { strategy: "output" });
|
|
476
|
-
if (outputRequired === required && stringifyJSON(outputJson) === stringifyJSON(json)) {
|
|
477
|
-
allowedStrategies.push("output");
|
|
478
|
-
}
|
|
479
|
-
} else if (strategy === "output") {
|
|
480
|
-
const [inputRequired, inputJson] = await this.converter.convert(schema, { strategy: "input" });
|
|
481
|
-
if (inputRequired === required && stringifyJSON(inputJson) === stringifyJSON(json)) {
|
|
482
|
-
allowedStrategies.push("input");
|
|
483
|
-
}
|
|
482
|
+
} else if (strategy === "output") {
|
|
483
|
+
const [inputRequired, inputJson] = await converter(schema, { strategy: "input" });
|
|
484
|
+
if (inputRequired === required && stringifyJSON(inputJson) === stringifyJSON(json)) {
|
|
485
|
+
allowedStrategies.push("input");
|
|
484
486
|
}
|
|
485
|
-
baseSchemaConvertOptions.components.push({
|
|
486
|
-
schema,
|
|
487
|
-
required,
|
|
488
|
-
ref: `#/components/schemas/${key}`,
|
|
489
|
-
allowedStrategies
|
|
490
|
-
});
|
|
491
487
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
488
|
+
baseSchemaConvertOptions.components.push({
|
|
489
|
+
schema,
|
|
490
|
+
required,
|
|
491
|
+
ref: `#/components/schemas/${key}`,
|
|
492
|
+
allowedStrategies
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
doc.components ??= {};
|
|
496
|
+
doc.components.schemas ??= {};
|
|
497
|
+
for (const key in commonSchemas) {
|
|
498
|
+
const options = commonSchemas[key];
|
|
499
|
+
if (options.schema === void 0) {
|
|
500
|
+
if (options.error === "UndefinedError") {
|
|
501
|
+
doc.components.schemas[key] = toOpenAPISchema(undefinedErrorJsonSchema);
|
|
502
|
+
undefinedErrorJsonSchema = { $ref: `#/components/schemas/${key}` };
|
|
502
503
|
}
|
|
503
|
-
|
|
504
|
-
const [, json] = await this.converter.convert(schema, {
|
|
505
|
-
...baseSchemaConvertOptions,
|
|
506
|
-
strategy,
|
|
507
|
-
minStructureDepthForRef: 1
|
|
508
|
-
// not allow use $ref for root schemas
|
|
509
|
-
});
|
|
510
|
-
doc.components.schemas[key] = toOpenAPISchema(json);
|
|
504
|
+
continue;
|
|
511
505
|
}
|
|
506
|
+
const { schema, strategy = "input" } = options;
|
|
507
|
+
const [, json] = await converter(schema, {
|
|
508
|
+
...baseSchemaConvertOptions,
|
|
509
|
+
strategy,
|
|
510
|
+
minStructureDepthForRef: 1
|
|
511
|
+
// not allow use $ref for root schemas
|
|
512
|
+
});
|
|
513
|
+
doc.components.schemas[key] = toOpenAPISchema(json);
|
|
512
514
|
}
|
|
513
|
-
return { baseSchemaConvertOptions, undefinedErrorJsonSchema };
|
|
514
515
|
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
throw error;
|
|
533
|
-
}
|
|
534
|
-
ref.parameters ??= [];
|
|
535
|
-
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
536
|
-
} else {
|
|
537
|
-
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
538
|
-
if (!isObjectSchema(pathSchema)) {
|
|
539
|
-
console.log("FOO", pathSchema);
|
|
540
|
-
throw error;
|
|
541
|
-
}
|
|
542
|
-
if (!checkParamsSchema(pathSchema, [])) {
|
|
543
|
-
console.log("BAR", pathSchema);
|
|
544
|
-
throw error;
|
|
545
|
-
}
|
|
516
|
+
return { baseSchemaConvertOptions, undefinedErrorJsonSchema };
|
|
517
|
+
}
|
|
518
|
+
async function handleRequest(doc, ref, def, baseSchemaConvertOptions, converter) {
|
|
519
|
+
const method = fallbackContractConfig("defaultMethod", def.route.method);
|
|
520
|
+
const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
|
|
521
|
+
const [_pathRequired, pathSchema] = await converter(def.schemas.pathSchema, {
|
|
522
|
+
...baseSchemaConvertOptions,
|
|
523
|
+
strategy: "input",
|
|
524
|
+
minStructureDepthForRef: 1
|
|
525
|
+
});
|
|
526
|
+
if (dynamicParams?.length) {
|
|
527
|
+
const error = new OpenAPIGeneratorError(
|
|
528
|
+
// TODO: fix this error
|
|
529
|
+
'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
|
|
530
|
+
);
|
|
531
|
+
if (!isObjectSchema(pathSchema)) {
|
|
532
|
+
throw error;
|
|
546
533
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
strategy: "input",
|
|
550
|
-
minStructureDepthForRef: 0
|
|
551
|
-
});
|
|
552
|
-
if (!isAnySchema(querySchema)) {
|
|
553
|
-
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
554
|
-
if (!isObjectSchema(resolvedSchema)) {
|
|
555
|
-
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
556
|
-
}
|
|
557
|
-
ref.parameters ??= [];
|
|
558
|
-
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
534
|
+
if (!checkParamsSchema(pathSchema, dynamicParams)) {
|
|
535
|
+
throw error;
|
|
559
536
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
};
|
|
583
|
-
}
|
|
537
|
+
ref.parameters ??= [];
|
|
538
|
+
ref.parameters.push(...toOpenAPIParameters(pathSchema, "path"));
|
|
539
|
+
} else {
|
|
540
|
+
const error = new OpenAPIGeneratorError("Params set via path do not match those on the route");
|
|
541
|
+
if (!isObjectSchema(pathSchema)) {
|
|
542
|
+
console.log("FOO", pathSchema);
|
|
543
|
+
throw error;
|
|
544
|
+
}
|
|
545
|
+
if (!checkParamsSchema(pathSchema, [])) {
|
|
546
|
+
console.log("BAR", pathSchema);
|
|
547
|
+
throw error;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const [_queryRequired, querySchema] = await converter(def.schemas.querySchema, {
|
|
551
|
+
...baseSchemaConvertOptions,
|
|
552
|
+
strategy: "input",
|
|
553
|
+
minStructureDepthForRef: 0
|
|
554
|
+
});
|
|
555
|
+
if (!isAnySchema(querySchema)) {
|
|
556
|
+
const resolvedSchema = resolveOpenAPIJsonSchemaRef(doc, querySchema);
|
|
557
|
+
if (!isObjectSchema(resolvedSchema)) {
|
|
558
|
+
throw new OpenAPIGeneratorError("Query param schema must satisfy: object | any | unknown");
|
|
584
559
|
}
|
|
560
|
+
ref.parameters ??= [];
|
|
561
|
+
ref.parameters.push(...toOpenAPIParameters(resolvedSchema, "query"));
|
|
585
562
|
}
|
|
586
|
-
|
|
587
|
-
const
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
const outputStructure = fallbackContractConfig("defaultOutputStructure", def.route.outputStructure);
|
|
592
|
-
if (eventIteratorSchemaDetails) {
|
|
593
|
-
ref.responses ??= {};
|
|
594
|
-
ref.responses[status] = {
|
|
595
|
-
description,
|
|
563
|
+
if (method !== "GET") {
|
|
564
|
+
const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
|
|
565
|
+
if (details) {
|
|
566
|
+
ref.requestBody = {
|
|
567
|
+
required: true,
|
|
596
568
|
content: toOpenAPIEventIteratorContent(
|
|
597
|
-
await
|
|
598
|
-
|
|
599
|
-
strategy: "output"
|
|
600
|
-
}),
|
|
601
|
-
await this.converter.convert(eventIteratorSchemaDetails.returns, {
|
|
602
|
-
...baseSchemaConvertOptions,
|
|
603
|
-
strategy: "output"
|
|
604
|
-
})
|
|
569
|
+
await converter(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
|
|
570
|
+
await converter(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
|
|
605
571
|
)
|
|
606
572
|
};
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
ref.
|
|
617
|
-
|
|
573
|
+
} else {
|
|
574
|
+
const [bodyRequired, bodySchema] = await converter(def.schemas.bodySchema, {
|
|
575
|
+
...baseSchemaConvertOptions,
|
|
576
|
+
strategy: "input",
|
|
577
|
+
minStructureDepthForRef: 0
|
|
578
|
+
});
|
|
579
|
+
if (isAnySchema(bodySchema)) {
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
ref.requestBody = {
|
|
583
|
+
required: bodyRequired,
|
|
584
|
+
content: toOpenAPIContent(bodySchema)
|
|
618
585
|
};
|
|
619
|
-
ref.responses[status].content = toOpenAPIContent(applySchemaOptionality(required, json));
|
|
620
|
-
return;
|
|
621
586
|
}
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
async function handleSuccessResponse(doc, ref, def, baseSchemaConvertOptions, converter) {
|
|
590
|
+
const outputSchema = def.schemas.outputSchema;
|
|
591
|
+
const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
|
|
592
|
+
const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
|
|
593
|
+
const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
|
|
594
|
+
const outputStructure = fallbackContractConfig("defaultOutputStructure", def.route.outputStructure);
|
|
595
|
+
if (eventIteratorSchemaDetails) {
|
|
596
|
+
ref.responses ??= {};
|
|
597
|
+
ref.responses[status] = {
|
|
598
|
+
description,
|
|
599
|
+
content: toOpenAPIEventIteratorContent(
|
|
600
|
+
await converter(eventIteratorSchemaDetails.yields, {
|
|
601
|
+
...baseSchemaConvertOptions,
|
|
602
|
+
strategy: "output"
|
|
603
|
+
}),
|
|
604
|
+
await converter(eventIteratorSchemaDetails.returns, {
|
|
605
|
+
...baseSchemaConvertOptions,
|
|
606
|
+
strategy: "output"
|
|
607
|
+
})
|
|
608
|
+
)
|
|
609
|
+
};
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
const [required, json] = await converter(outputSchema, {
|
|
613
|
+
...baseSchemaConvertOptions,
|
|
614
|
+
strategy: "output",
|
|
615
|
+
minStructureDepthForRef: outputStructure === "detailed" ? 1 : 0
|
|
616
|
+
});
|
|
617
|
+
if (outputStructure === "compact") {
|
|
618
|
+
ref.responses ??= {};
|
|
619
|
+
ref.responses[status] = {
|
|
620
|
+
description
|
|
621
|
+
};
|
|
622
|
+
ref.responses[status].content = toOpenAPIContent(applySchemaOptionality(required, json));
|
|
623
|
+
return;
|
|
624
|
+
}
|
|
625
|
+
const handledStatuses = /* @__PURE__ */ new Set();
|
|
626
|
+
for (const item of expandUnionSchema(json)) {
|
|
627
|
+
const error = new OpenAPIGeneratorError(`
|
|
628
|
+
When output structure is "detailed", output schema must satisfy:
|
|
629
|
+
{
|
|
630
|
+
status?: number, // must be a literal number and in the range of 200-399
|
|
631
|
+
headers?: Record<string, unknown>,
|
|
632
|
+
body?: unknown
|
|
633
|
+
}
|
|
631
634
|
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
+
But got: ${stringifyJSON(item)}
|
|
636
|
+
`);
|
|
637
|
+
if (!isObjectSchema(item)) {
|
|
638
|
+
throw error;
|
|
639
|
+
}
|
|
640
|
+
let schemaStatus;
|
|
641
|
+
let schemaDescription;
|
|
642
|
+
if (item.properties?.status !== void 0) {
|
|
643
|
+
const statusSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.status);
|
|
644
|
+
if (typeof statusSchema !== "object" || statusSchema.const === void 0 || typeof statusSchema.const !== "number" || !Number.isInteger(statusSchema.const) || isORPCErrorStatus(statusSchema.const)) {
|
|
635
645
|
throw error;
|
|
636
646
|
}
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
647
|
+
schemaStatus = statusSchema.const;
|
|
648
|
+
schemaDescription = statusSchema.description;
|
|
649
|
+
}
|
|
650
|
+
const itemStatus = schemaStatus ?? status;
|
|
651
|
+
const itemDescription = schemaDescription ?? description;
|
|
652
|
+
if (handledStatuses.has(itemStatus)) {
|
|
653
|
+
throw new OpenAPIGeneratorError(`
|
|
654
|
+
When output structure is "detailed", each success status must be unique.
|
|
655
|
+
But got status: ${itemStatus} used more than once.
|
|
656
|
+
`);
|
|
657
|
+
}
|
|
658
|
+
handledStatuses.add(itemStatus);
|
|
659
|
+
ref.responses ??= {};
|
|
660
|
+
ref.responses[itemStatus] = {
|
|
661
|
+
description: itemDescription
|
|
662
|
+
};
|
|
663
|
+
if (item.properties?.headers !== void 0) {
|
|
664
|
+
const headersSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.headers);
|
|
665
|
+
if (!isObjectSchema(headersSchema)) {
|
|
666
|
+
throw error;
|
|
654
667
|
}
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
throw error;
|
|
664
|
-
}
|
|
665
|
-
for (const key in headersSchema.properties) {
|
|
666
|
-
const headerSchema = headersSchema.properties[key];
|
|
667
|
-
if (headerSchema !== void 0) {
|
|
668
|
-
ref.responses[itemStatus].headers ??= {};
|
|
669
|
-
ref.responses[itemStatus].headers[key] = {
|
|
670
|
-
schema: toOpenAPISchema(headerSchema),
|
|
671
|
-
required: item.required?.includes("headers") && headersSchema.required?.includes(key)
|
|
672
|
-
};
|
|
673
|
-
}
|
|
668
|
+
for (const key in headersSchema.properties) {
|
|
669
|
+
const headerSchema = headersSchema.properties[key];
|
|
670
|
+
if (headerSchema !== void 0) {
|
|
671
|
+
ref.responses[itemStatus].headers ??= {};
|
|
672
|
+
ref.responses[itemStatus].headers[key] = {
|
|
673
|
+
schema: toOpenAPISchema(headerSchema),
|
|
674
|
+
required: item.required?.includes("headers") && headersSchema.required?.includes(key)
|
|
675
|
+
};
|
|
674
676
|
}
|
|
675
677
|
}
|
|
676
|
-
if (item.properties?.body !== void 0) {
|
|
677
|
-
ref.responses[itemStatus].content = toOpenAPIContent(
|
|
678
|
-
applySchemaOptionality(item.required?.includes("body") ?? false, item.properties.body)
|
|
679
|
-
);
|
|
680
|
-
}
|
|
681
678
|
}
|
|
679
|
+
if (item.properties?.body !== void 0) {
|
|
680
|
+
ref.responses[itemStatus].content = toOpenAPIContent(
|
|
681
|
+
applySchemaOptionality(item.required?.includes("body") ?? false, item.properties.body)
|
|
682
|
+
);
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
function authConfigToSecurityScheme(authConfig) {
|
|
687
|
+
switch (authConfig.type) {
|
|
688
|
+
case "basic":
|
|
689
|
+
return {
|
|
690
|
+
type: "http",
|
|
691
|
+
scheme: "basic",
|
|
692
|
+
description: authConfig.oasDescription
|
|
693
|
+
};
|
|
694
|
+
case "bearer":
|
|
695
|
+
return {
|
|
696
|
+
type: "http",
|
|
697
|
+
scheme: "bearer",
|
|
698
|
+
description: authConfig.oasDescription,
|
|
699
|
+
bearerFormat: authConfig.oasBearerFormat
|
|
700
|
+
};
|
|
701
|
+
case "header":
|
|
702
|
+
return {
|
|
703
|
+
type: "apiKey",
|
|
704
|
+
in: "header",
|
|
705
|
+
name: authConfig.name,
|
|
706
|
+
description: authConfig.oasDescription
|
|
707
|
+
};
|
|
708
|
+
case "query":
|
|
709
|
+
return {
|
|
710
|
+
type: "apiKey",
|
|
711
|
+
in: "query",
|
|
712
|
+
name: authConfig.name,
|
|
713
|
+
description: authConfig.oasDescription
|
|
714
|
+
};
|
|
715
|
+
case "cookie":
|
|
716
|
+
return {
|
|
717
|
+
type: "apiKey",
|
|
718
|
+
in: "cookie",
|
|
719
|
+
name: authConfig.name,
|
|
720
|
+
description: authConfig.oasDescription
|
|
721
|
+
};
|
|
722
|
+
default:
|
|
723
|
+
assertNever(authConfig, `Unsupported auth config type: ${authConfig.type}`);
|
|
682
724
|
}
|
|
683
725
|
}
|
|
684
726
|
|
|
@@ -686,4 +728,4 @@ const oo = {
|
|
|
686
728
|
spec: customOpenAPIOperation
|
|
687
729
|
};
|
|
688
730
|
|
|
689
|
-
export {
|
|
731
|
+
export { LOGIC_KEYWORDS, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, generateOpenApiSpec, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
|