@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.
@@ -1,4 +1,5 @@
1
- import { isObject, stringifyJSON, findDeepMatches, toArray, clone, value, fallbackContractConfig, toHttpPath, isORPCErrorStatus } from '@temporary-name/shared';
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 CompositeSchemaConverter {
359
- converters;
360
- constructor(converters) {
361
- this.converters = converters;
362
- }
363
- async convert(schema, options) {
364
- for (const converter of this.converters) {
365
- if (await converter.condition(schema, options)) {
366
- return converter.convert(schema, options);
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
- class OpenAPIGeneratorError extends Error {
374
- }
375
- class OpenAPIGenerator {
376
- converter;
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
- * Generates OpenAPI specifications from oRPC routers/contracts.
382
- *
383
- * @see {@link https://orpc.unnoq.com/docs/openapi/openapi-specification OpenAPI Specification Docs}
384
- */
385
- async generate(router, options = {}) {
386
- const filter = options.filter ?? (({ contract, path }) => {
387
- return !(options.exclude?.(contract, path) ?? false);
388
- });
389
- const doc = {
390
- ...clone(options),
391
- info: options.info ?? { title: "API Reference", version: "0.0.0" },
392
- openapi: "3.1.1",
393
- exclude: void 0,
394
- filter: void 0,
395
- commonSchemas: void 0
396
- };
397
- const { baseSchemaConvertOptions } = await this.#resolveCommonSchemas(doc, options.commonSchemas);
398
- const contracts = [];
399
- await resolveContractProcedures({ path: [], router }, (traverseOptions) => {
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
- if (errors.length) {
443
- throw new OpenAPIGeneratorError(
444
- `Some error occurred during OpenAPI generation:
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
- async #resolveCommonSchemas(doc, commonSchemas) {
452
- let undefinedErrorJsonSchema = {
453
- type: "object",
454
- properties: {
455
- defined: { const: false },
456
- code: { type: "string" },
457
- status: { type: "number" },
458
- message: { type: "string" },
459
- data: {}
460
- },
461
- required: ["defined", "code", "status", "message"]
462
- };
463
- const baseSchemaConvertOptions = {};
464
- if (commonSchemas) {
465
- baseSchemaConvertOptions.components = [];
466
- for (const key in commonSchemas) {
467
- const options = commonSchemas[key];
468
- if (options.schema === void 0) {
469
- continue;
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
- const { schema, strategy = "input" } = options;
472
- const [required, json] = await this.converter.convert(schema, { strategy });
473
- const allowedStrategies = [strategy];
474
- if (strategy === "input") {
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
- doc.components ??= {};
493
- doc.components.schemas ??= {};
494
- for (const key in commonSchemas) {
495
- const options = commonSchemas[key];
496
- if (options.schema === void 0) {
497
- if (options.error === "UndefinedError") {
498
- doc.components.schemas[key] = toOpenAPISchema(undefinedErrorJsonSchema);
499
- undefinedErrorJsonSchema = { $ref: `#/components/schemas/${key}` };
500
- }
501
- continue;
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
- const { schema, strategy = "input" } = options;
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
- async #request(doc, ref, def, baseSchemaConvertOptions) {
516
- const method = fallbackContractConfig("defaultMethod", def.route.method);
517
- const dynamicParams = getDynamicParams(def.route.path)?.map((v) => v.name);
518
- const [_pathRequired, pathSchema] = await this.converter.convert(def.schemas.pathSchema, {
519
- ...baseSchemaConvertOptions,
520
- strategy: "input",
521
- minStructureDepthForRef: 1
522
- });
523
- if (dynamicParams?.length) {
524
- const error = new OpenAPIGeneratorError(
525
- // TODO: fix this error
526
- 'When input structure is "compact", and path has dynamic params, input schema must be an object with all dynamic params as required.'
527
- );
528
- if (!isObjectSchema(pathSchema)) {
529
- throw error;
530
- }
531
- if (!checkParamsSchema(pathSchema, dynamicParams)) {
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
- const [_queryRequired, querySchema] = await this.converter.convert(def.schemas.querySchema, {
548
- ...baseSchemaConvertOptions,
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
- if (method !== "GET") {
561
- const details = getEventIteratorSchemaDetails(def.schemas.bodySchema);
562
- if (details) {
563
- ref.requestBody = {
564
- required: true,
565
- content: toOpenAPIEventIteratorContent(
566
- await this.converter.convert(details.yields, { ...baseSchemaConvertOptions, strategy: "input" }),
567
- await this.converter.convert(details.returns, { ...baseSchemaConvertOptions, strategy: "input" })
568
- )
569
- };
570
- } else {
571
- const [bodyRequired, bodySchema] = await this.converter.convert(def.schemas.bodySchema, {
572
- ...baseSchemaConvertOptions,
573
- strategy: "input",
574
- minStructureDepthForRef: 0
575
- });
576
- if (isAnySchema(bodySchema)) {
577
- return;
578
- }
579
- ref.requestBody = {
580
- required: bodyRequired,
581
- content: toOpenAPIContent(bodySchema)
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
- async #successResponse(doc, ref, def, baseSchemaConvertOptions) {
587
- const outputSchema = def.schemas.outputSchema;
588
- const status = fallbackContractConfig("defaultSuccessStatus", def.route.successStatus);
589
- const description = fallbackContractConfig("defaultSuccessDescription", def.route?.successDescription);
590
- const eventIteratorSchemaDetails = getEventIteratorSchemaDetails(outputSchema);
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 this.converter.convert(eventIteratorSchemaDetails.yields, {
598
- ...baseSchemaConvertOptions,
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
- return;
608
- }
609
- const [required, json] = await this.converter.convert(outputSchema, {
610
- ...baseSchemaConvertOptions,
611
- strategy: "output",
612
- minStructureDepthForRef: outputStructure === "detailed" ? 1 : 0
613
- });
614
- if (outputStructure === "compact") {
615
- ref.responses ??= {};
616
- ref.responses[status] = {
617
- description
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
- const handledStatuses = /* @__PURE__ */ new Set();
623
- for (const item of expandUnionSchema(json)) {
624
- const error = new OpenAPIGeneratorError(`
625
- When output structure is "detailed", output schema must satisfy:
626
- {
627
- status?: number, // must be a literal number and in the range of 200-399
628
- headers?: Record<string, unknown>,
629
- body?: unknown
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
- But got: ${stringifyJSON(item)}
633
- `);
634
- if (!isObjectSchema(item)) {
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
- let schemaStatus;
638
- let schemaDescription;
639
- if (item.properties?.status !== void 0) {
640
- const statusSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.status);
641
- if (typeof statusSchema !== "object" || statusSchema.const === void 0 || typeof statusSchema.const !== "number" || !Number.isInteger(statusSchema.const) || isORPCErrorStatus(statusSchema.const)) {
642
- throw error;
643
- }
644
- schemaStatus = statusSchema.const;
645
- schemaDescription = statusSchema.description;
646
- }
647
- const itemStatus = schemaStatus ?? status;
648
- const itemDescription = schemaDescription ?? description;
649
- if (handledStatuses.has(itemStatus)) {
650
- throw new OpenAPIGeneratorError(`
651
- When output structure is "detailed", each success status must be unique.
652
- But got status: ${itemStatus} used more than once.
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
- handledStatuses.add(itemStatus);
656
- ref.responses ??= {};
657
- ref.responses[itemStatus] = {
658
- description: itemDescription
659
- };
660
- if (item.properties?.headers !== void 0) {
661
- const headersSchema = resolveOpenAPIJsonSchemaRef(doc, item.properties.headers);
662
- if (!isObjectSchema(headersSchema)) {
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 { CompositeSchemaConverter, LOGIC_KEYWORDS, OpenAPIGenerator, applyCustomOpenAPIOperation, applySchemaOptionality, checkParamsSchema, customOpenAPIOperation, expandArrayableSchema, expandUnionSchema, filterSchemaBranches, getCustomOpenAPIOperation, isAnySchema, isFileSchema, isObjectSchema, isPrimitiveSchema, oo, resolveOpenAPIJsonSchemaRef, separateObjectSchema, toOpenAPIContent, toOpenAPIEventIteratorContent, toOpenAPIMethod, toOpenAPIParameters, toOpenAPIPath, toOpenAPISchema };
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 };