@kubb/plugin-oas 2.18.4 → 2.18.6

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.
Files changed (68) hide show
  1. package/dist/{OperationGenerator-X6CTMfhG.d.cts → OperationGenerator-B6_KXF47.d.cts} +12 -11
  2. package/dist/{OperationGenerator-DvnXUUp4.d.ts → OperationGenerator-BL3W1CH2.d.ts} +12 -11
  3. package/dist/{Schema-DFZBfjF2.d.ts → Schema-ByMOp8RL.d.ts} +6 -12
  4. package/dist/{Schema-BWPWyiQO.d.cts → Schema-C9Wxng-Q.d.cts} +6 -12
  5. package/dist/{SchemaGenerator-hK5SHxTI.d.ts → SchemaMapper-DRlWYDvv.d.cts} +2 -74
  6. package/dist/{SchemaGenerator-z_7YrAAB.d.cts → SchemaMapper-DRlWYDvv.d.ts} +2 -74
  7. package/dist/{chunk-UMYKVV7G.js → chunk-37DRAF2Z.js} +49 -2
  8. package/dist/chunk-37DRAF2Z.js.map +1 -0
  9. package/dist/chunk-CTFUZW3D.cjs +682 -0
  10. package/dist/chunk-CTFUZW3D.cjs.map +1 -0
  11. package/dist/{chunk-XML4KQ5H.js → chunk-FL37EDQ2.js} +12 -30
  12. package/dist/{chunk-XML4KQ5H.js.map → chunk-FL37EDQ2.js.map} +1 -1
  13. package/dist/chunk-JWIFGIVZ.js +34 -0
  14. package/dist/chunk-JWIFGIVZ.js.map +1 -0
  15. package/dist/{chunk-YI3FIAD4.cjs → chunk-OUN5NRHC.cjs} +30 -48
  16. package/dist/chunk-OUN5NRHC.cjs.map +1 -0
  17. package/dist/chunk-QLNCBDLM.js +682 -0
  18. package/dist/chunk-QLNCBDLM.js.map +1 -0
  19. package/dist/chunk-R4EI2NRQ.cjs +34 -0
  20. package/dist/chunk-R4EI2NRQ.cjs.map +1 -0
  21. package/dist/{chunk-BDNSPC5Z.cjs → chunk-SSSTH6CP.cjs} +50 -3
  22. package/dist/chunk-SSSTH6CP.cjs.map +1 -0
  23. package/dist/components.cjs +5 -5
  24. package/dist/components.d.cts +5 -4
  25. package/dist/components.d.ts +5 -4
  26. package/dist/components.js +3 -3
  27. package/dist/hooks.cjs +13 -13
  28. package/dist/hooks.cjs.map +1 -1
  29. package/dist/hooks.d.cts +7 -8
  30. package/dist/hooks.d.ts +7 -8
  31. package/dist/hooks.js +3 -3
  32. package/dist/hooks.js.map +1 -1
  33. package/dist/index.cjs +69 -642
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +72 -6
  36. package/dist/index.d.ts +72 -6
  37. package/dist/index.js +50 -623
  38. package/dist/index.js.map +1 -1
  39. package/dist/{types-n5zV4Q3s.d.cts → types-BMBTfHxe.d.cts} +3 -2
  40. package/dist/{types-n5zV4Q3s.d.ts → types-BMBTfHxe.d.ts} +3 -2
  41. package/dist/utils.cjs +9 -9
  42. package/dist/utils.cjs.map +1 -1
  43. package/dist/utils.d.cts +5 -4
  44. package/dist/utils.d.ts +5 -4
  45. package/dist/utils.js +5 -5
  46. package/dist/utils.js.map +1 -1
  47. package/package.json +10 -9
  48. package/src/OperationGenerator.ts +27 -11
  49. package/src/SchemaGenerator.ts +30 -35
  50. package/src/SchemaMapper.ts +1 -1
  51. package/src/components/Schema.tsx +12 -42
  52. package/src/hooks/useOperationManager.ts +3 -2
  53. package/src/hooks/useSchema.ts +1 -8
  54. package/src/index.ts +1 -0
  55. package/src/plugin.ts +3 -3
  56. package/src/types.ts +3 -1
  57. package/src/utils/getGroupedByTagFiles.ts +4 -3
  58. package/dist/chunk-4OLWDMEK.cjs +0 -61
  59. package/dist/chunk-4OLWDMEK.cjs.map +0 -1
  60. package/dist/chunk-BDNSPC5Z.cjs.map +0 -1
  61. package/dist/chunk-BIJSTJCQ.js +0 -61
  62. package/dist/chunk-BIJSTJCQ.js.map +0 -1
  63. package/dist/chunk-I2JOGJIB.cjs +0 -81
  64. package/dist/chunk-I2JOGJIB.cjs.map +0 -1
  65. package/dist/chunk-UMYKVV7G.js.map +0 -1
  66. package/dist/chunk-XRPYJNPR.js +0 -81
  67. package/dist/chunk-XRPYJNPR.js.map +0 -1
  68. package/dist/chunk-YI3FIAD4.cjs.map +0 -1
package/dist/index.js CHANGED
@@ -1,19 +1,19 @@
1
1
  import {
2
- getSchemaFactory,
3
- getSchemas,
4
2
  parseFromConfig
5
- } from "./chunk-XRPYJNPR.js";
3
+ } from "./chunk-JWIFGIVZ.js";
6
4
  import {
5
+ SchemaGenerator,
7
6
  isKeyword,
8
7
  schemaKeywords
9
- } from "./chunk-BIJSTJCQ.js";
8
+ } from "./chunk-QLNCBDLM.js";
10
9
  import {
11
10
  __privateAdd,
12
11
  __privateGet,
13
12
  __privateMethod,
14
13
  __privateSet,
14
+ getSchemas,
15
15
  init_esm_shims
16
- } from "./chunk-UMYKVV7G.js";
16
+ } from "./chunk-37DRAF2Z.js";
17
17
 
18
18
  // src/index.ts
19
19
  init_esm_shims();
@@ -77,11 +77,11 @@ var pluginOas = createPlugin((options) => {
77
77
  resolveName(name, type) {
78
78
  return camelCase(name, { isFile: type === "file" });
79
79
  },
80
- async writeFile(source, writePath) {
81
- if (!writePath.endsWith(".json") || !source) {
80
+ async writeFile(path2, source) {
81
+ if (!path2.endsWith(".json") || !source) {
82
82
  return;
83
83
  }
84
- return this.fileManager.write(source, writePath, { sanity: false });
84
+ return this.fileManager.write(path2, source, { sanity: false });
85
85
  },
86
86
  async buildStart() {
87
87
  if (!output) {
@@ -280,6 +280,48 @@ var OperationGenerator = class extends Generator {
280
280
  const files = await Promise.all(promises);
281
281
  return files.flat().filter(Boolean);
282
282
  }
283
+ /**
284
+ * Operation
285
+ */
286
+ async operation(operation, options) {
287
+ return null;
288
+ }
289
+ /**
290
+ * GET
291
+ */
292
+ async get(operation, options) {
293
+ return null;
294
+ }
295
+ /**
296
+ * POST
297
+ */
298
+ async post(operation, options) {
299
+ return null;
300
+ }
301
+ /**
302
+ * PATCH
303
+ */
304
+ async patch(operation, options) {
305
+ return null;
306
+ }
307
+ /**
308
+ * PUT
309
+ */
310
+ async put(operation, options) {
311
+ return null;
312
+ }
313
+ /**
314
+ * DELETE
315
+ */
316
+ async delete(operation, options) {
317
+ return null;
318
+ }
319
+ /**
320
+ * Combination of GET, POST, PATCH, PUT, DELETE
321
+ */
322
+ async all(operations, paths) {
323
+ return null;
324
+ }
283
325
  };
284
326
  _operationsByMethod = new WeakMap();
285
327
  _getOptions = new WeakSet();
@@ -355,621 +397,6 @@ methods_get = function() {
355
397
  };
356
398
  };
357
399
 
358
- // src/SchemaGenerator.ts
359
- init_esm_shims();
360
- import { Generator as Generator2 } from "@kubb/core";
361
- import transformers2, { pascalCase } from "@kubb/core/transformers";
362
- import { getUniqueName } from "@kubb/core/utils";
363
- import { isReference } from "@kubb/oas";
364
- import { isDeepEqual, isNumber, uniqueWith } from "remeda";
365
- var _usedAliasNames, _getUsedEnumNames, getUsedEnumNames_fn, _getOptions2, getOptions_fn2, _getUnknownReturn, getUnknownReturn_fn, _parseProperties, parseProperties_fn, _getRefAlias, getRefAlias_fn, _getParsedSchemaObject, getParsedSchemaObject_fn, _parseSchemaObject, parseSchemaObject_fn;
366
- var _SchemaGenerator = class _SchemaGenerator extends Generator2 {
367
- constructor() {
368
- super(...arguments);
369
- __privateAdd(this, _getUsedEnumNames);
370
- __privateAdd(this, _getOptions2);
371
- __privateAdd(this, _getUnknownReturn);
372
- /**
373
- * Recursively creates a type literal with the given props.
374
- */
375
- __privateAdd(this, _parseProperties);
376
- /**
377
- * Create a type alias for the schema referenced by the given ReferenceObject
378
- */
379
- __privateAdd(this, _getRefAlias);
380
- __privateAdd(this, _getParsedSchemaObject);
381
- /**
382
- * This is the very core of the OpenAPI to TS conversion - it takes a
383
- * schema and returns the appropriate type.
384
- */
385
- __privateAdd(this, _parseSchemaObject);
386
- // Collect the types of all referenced schemas, so we can export them later
387
- this.refs = {};
388
- // Keep track of already used type aliases
389
- __privateAdd(this, _usedAliasNames, {});
390
- }
391
- /**
392
- * Creates a type node from a given schema.
393
- * Delegates to getBaseTypeFromSchema internally and
394
- * optionally adds a union with null.
395
- */
396
- buildSchemas(props) {
397
- const options = __privateMethod(this, _getOptions2, getOptions_fn2).call(this, props);
398
- const defaultSchemas = __privateMethod(this, _parseSchemaObject, parseSchemaObject_fn).call(this, props);
399
- const schemas = options.transformers?.schema?.(props, defaultSchemas) || defaultSchemas || [];
400
- return uniqueWith(schemas, isDeepEqual);
401
- }
402
- deepSearch(schemas, keyword) {
403
- return _SchemaGenerator.deepSearch(schemas, keyword);
404
- }
405
- find(schemas, keyword) {
406
- return _SchemaGenerator.find(schemas, keyword);
407
- }
408
- static deepSearch(schemas, keyword) {
409
- const foundItems = [];
410
- schemas?.forEach((schema) => {
411
- if (schema.keyword === keyword) {
412
- foundItems.push(schema);
413
- }
414
- if (schema.keyword === schemaKeywords.object) {
415
- const subItem = schema;
416
- Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
417
- foundItems.push(..._SchemaGenerator.deepSearch(entrySchema, keyword));
418
- });
419
- Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
420
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
421
- });
422
- }
423
- if (schema.keyword === schemaKeywords.array) {
424
- const subItem = schema;
425
- subItem.args.items.forEach((entrySchema) => {
426
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
427
- });
428
- }
429
- if (schema.keyword === schemaKeywords.and) {
430
- const subItem = schema;
431
- subItem.args.forEach((entrySchema) => {
432
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
433
- });
434
- }
435
- if (schema.keyword === schemaKeywords.tuple) {
436
- const subItem = schema;
437
- subItem.args.forEach((entrySchema) => {
438
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
439
- });
440
- }
441
- if (schema.keyword === schemaKeywords.union) {
442
- const subItem = schema;
443
- subItem.args.forEach((entrySchema) => {
444
- foundItems.push(..._SchemaGenerator.deepSearch([entrySchema], keyword));
445
- });
446
- }
447
- });
448
- return foundItems;
449
- }
450
- static findInObject(schemas, keyword) {
451
- let foundItem = void 0;
452
- schemas?.forEach((schema) => {
453
- if (!foundItem && schema.keyword === keyword) {
454
- foundItem = schema;
455
- }
456
- if (schema.keyword === schemaKeywords.object) {
457
- const subItem = schema;
458
- Object.values(subItem.args?.properties || {}).forEach((entrySchema) => {
459
- if (!foundItem) {
460
- foundItem = _SchemaGenerator.find(entrySchema, keyword);
461
- }
462
- });
463
- Object.values(subItem.args?.additionalProperties || {}).forEach((entrySchema) => {
464
- if (!foundItem) {
465
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
466
- }
467
- });
468
- }
469
- });
470
- return foundItem;
471
- }
472
- static find(schemas, keyword) {
473
- let foundItem = void 0;
474
- schemas?.forEach((schema) => {
475
- if (!foundItem && schema.keyword === keyword) {
476
- foundItem = schema;
477
- }
478
- if (schema.keyword === schemaKeywords.array) {
479
- const subItem = schema;
480
- subItem.args.items.forEach((entrySchema) => {
481
- if (!foundItem) {
482
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
483
- }
484
- });
485
- }
486
- if (schema.keyword === schemaKeywords.and) {
487
- const subItem = schema;
488
- subItem.args.forEach((entrySchema) => {
489
- if (!foundItem) {
490
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
491
- }
492
- });
493
- }
494
- if (schema.keyword === schemaKeywords.tuple) {
495
- const subItem = schema;
496
- subItem.args.forEach((entrySchema) => {
497
- if (!foundItem) {
498
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
499
- }
500
- });
501
- }
502
- if (schema.keyword === schemaKeywords.union) {
503
- const subItem = schema;
504
- subItem.args.forEach((entrySchema) => {
505
- if (!foundItem) {
506
- foundItem = _SchemaGenerator.find([entrySchema], keyword);
507
- }
508
- });
509
- }
510
- });
511
- return foundItem;
512
- }
513
- async build() {
514
- const { oas, contentType, include } = this.context;
515
- const schemas = getSchemas({ oas, contentType, includes: include });
516
- const promises = Object.entries(schemas).reduce((acc, [name, schema]) => {
517
- const promiseOperation = this.schema.call(this, name, schema);
518
- if (promiseOperation) {
519
- acc.push(promiseOperation);
520
- }
521
- return acc;
522
- }, []);
523
- const files = await Promise.all(promises);
524
- return files.flat().filter(Boolean);
525
- }
526
- };
527
- _usedAliasNames = new WeakMap();
528
- _getUsedEnumNames = new WeakSet();
529
- getUsedEnumNames_fn = function(props) {
530
- const options = __privateMethod(this, _getOptions2, getOptions_fn2).call(this, props);
531
- return options.usedEnumNames || {};
532
- };
533
- _getOptions2 = new WeakSet();
534
- getOptions_fn2 = function({ name }) {
535
- const { override = [] } = this.context;
536
- return {
537
- ...this.options,
538
- ...override.find(({ pattern, type }) => {
539
- if (name && type === "schemaName") {
540
- return !!name.match(pattern);
541
- }
542
- return false;
543
- })?.options || {}
544
- };
545
- };
546
- _getUnknownReturn = new WeakSet();
547
- getUnknownReturn_fn = function(props) {
548
- const options = __privateMethod(this, _getOptions2, getOptions_fn2).call(this, props);
549
- if (options.unknownType === "any") {
550
- return schemaKeywords.any;
551
- }
552
- return schemaKeywords.unknown;
553
- };
554
- _parseProperties = new WeakSet();
555
- parseProperties_fn = function({ schema, name }) {
556
- const properties = schema?.properties || {};
557
- const additionalProperties = schema?.additionalProperties;
558
- const required = schema?.required;
559
- const propertiesSchemas = Object.keys(properties).map((propertyName) => {
560
- const validationFunctions = [];
561
- const propertySchema = properties[propertyName];
562
- const isRequired = Array.isArray(required) ? required?.includes(propertyName) : !!required;
563
- const nullable = propertySchema.nullable ?? propertySchema["x-nullable"] ?? false;
564
- validationFunctions.push(...this.buildSchemas({ schema: propertySchema, name: propertyName, parentName: name }));
565
- validationFunctions.push({
566
- keyword: schemaKeywords.name,
567
- args: propertyName
568
- });
569
- if (!isRequired && nullable) {
570
- validationFunctions.push({ keyword: schemaKeywords.nullish });
571
- } else if (!isRequired) {
572
- validationFunctions.push({ keyword: schemaKeywords.optional });
573
- }
574
- return {
575
- [propertyName]: validationFunctions
576
- };
577
- }).reduce((acc, curr) => ({ ...acc, ...curr }), {});
578
- let additionalPropertiesSchemas = [];
579
- if (additionalProperties) {
580
- additionalPropertiesSchemas = additionalProperties === true ? [{ keyword: __privateMethod(this, _getUnknownReturn, getUnknownReturn_fn).call(this, { schema, name }) }] : this.buildSchemas({ schema: additionalProperties, parentName: name });
581
- }
582
- return [
583
- {
584
- keyword: schemaKeywords.object,
585
- args: {
586
- properties: propertiesSchemas,
587
- additionalProperties: additionalPropertiesSchemas
588
- }
589
- }
590
- ];
591
- };
592
- _getRefAlias = new WeakSet();
593
- getRefAlias_fn = function(obj) {
594
- const { $ref } = obj;
595
- let ref = this.refs[$ref];
596
- const originalName = getUniqueName($ref.replace(/.+\//, ""), __privateGet(this, _usedAliasNames));
597
- const propertyName = this.context.pluginManager.resolveName({
598
- name: originalName,
599
- pluginKey: this.context.plugin.key,
600
- type: "function"
601
- });
602
- if (ref) {
603
- return [
604
- {
605
- keyword: schemaKeywords.ref,
606
- args: { name: ref.propertyName, path: ref.path }
607
- }
608
- ];
609
- }
610
- const fileName = this.context.pluginManager.resolveName({
611
- name: originalName,
612
- pluginKey: this.context.plugin.key,
613
- type: "file"
614
- });
615
- const file = this.context.pluginManager.getFile({
616
- name: fileName,
617
- pluginKey: this.context.plugin.key,
618
- extName: ".ts"
619
- });
620
- ref = this.refs[$ref] = {
621
- propertyName,
622
- originalName,
623
- path: file.path
624
- };
625
- return [
626
- {
627
- keyword: schemaKeywords.ref,
628
- args: { name: ref.propertyName, path: ref?.path, isTypeOnly: false }
629
- }
630
- ];
631
- };
632
- _getParsedSchemaObject = new WeakSet();
633
- getParsedSchemaObject_fn = function(schema) {
634
- const parsedSchema = getSchemaFactory(this.context.oas)(schema);
635
- return parsedSchema;
636
- };
637
- _parseSchemaObject = new WeakSet();
638
- parseSchemaObject_fn = function({ schema: _schema, name, parentName }) {
639
- const options = __privateMethod(this, _getOptions2, getOptions_fn2).call(this, { schema: _schema, name });
640
- const unknownReturn = __privateMethod(this, _getUnknownReturn, getUnknownReturn_fn).call(this, { schema: _schema, name });
641
- const { schema, version } = __privateMethod(this, _getParsedSchemaObject, getParsedSchemaObject_fn).call(this, _schema);
642
- const resolvedName = this.context.pluginManager.resolveName({
643
- name: `${parentName || ""} ${name}`,
644
- pluginKey: this.context.plugin.key,
645
- type: "type"
646
- });
647
- if (!schema) {
648
- return [{ keyword: unknownReturn }];
649
- }
650
- const baseItems = [
651
- {
652
- keyword: schemaKeywords.schema,
653
- args: {
654
- type: schema.type,
655
- format: schema.format
656
- }
657
- }
658
- ];
659
- const min = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
660
- const max = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
661
- const nullable = schema.nullable ?? schema["x-nullable"] ?? false;
662
- if (schema.default !== void 0 && !Array.isArray(schema.default)) {
663
- if (typeof schema.default === "string") {
664
- baseItems.push({
665
- keyword: schemaKeywords.default,
666
- args: transformers2.stringify(schema.default)
667
- });
668
- }
669
- if (typeof schema.default === "boolean") {
670
- baseItems.push({
671
- keyword: schemaKeywords.default,
672
- args: schema.default ?? false
673
- });
674
- }
675
- }
676
- if (schema.description) {
677
- baseItems.push({
678
- keyword: schemaKeywords.describe,
679
- args: schema.description
680
- });
681
- }
682
- if (schema.pattern) {
683
- baseItems.unshift({
684
- keyword: schemaKeywords.matches,
685
- args: schema.pattern
686
- });
687
- }
688
- if (max !== void 0) {
689
- baseItems.unshift({ keyword: schemaKeywords.max, args: max });
690
- }
691
- if (min !== void 0) {
692
- baseItems.unshift({ keyword: schemaKeywords.min, args: min });
693
- }
694
- if (nullable) {
695
- baseItems.push({ keyword: schemaKeywords.nullable });
696
- }
697
- if (schema.type && Array.isArray(schema.type)) {
698
- const [_schema2, nullable2] = schema.type;
699
- if (nullable2 === "null") {
700
- baseItems.push({ keyword: schemaKeywords.nullable });
701
- }
702
- }
703
- if (schema.readOnly) {
704
- baseItems.push({ keyword: schemaKeywords.readOnly });
705
- }
706
- if (isReference(schema)) {
707
- return [...__privateMethod(this, _getRefAlias, getRefAlias_fn).call(this, schema), ...baseItems];
708
- }
709
- if (schema.oneOf) {
710
- const schemaWithoutOneOf = { ...schema, oneOf: void 0 };
711
- const union = {
712
- keyword: schemaKeywords.union,
713
- args: schema.oneOf.map((item) => {
714
- return item && this.buildSchemas({ schema: item, name, parentName })[0];
715
- }).filter(Boolean).filter((item) => {
716
- return item && item.keyword !== unknownReturn;
717
- })
718
- };
719
- if (schemaWithoutOneOf.properties) {
720
- return [...this.buildSchemas({ schema: schemaWithoutOneOf, name, parentName }), union, ...baseItems];
721
- }
722
- return [union, ...baseItems];
723
- }
724
- if (schema.anyOf) {
725
- const schemaWithoutAnyOf = { ...schema, anyOf: void 0 };
726
- const union = {
727
- keyword: schemaKeywords.union,
728
- args: schema.anyOf.map((item) => {
729
- return item && this.buildSchemas({ schema: item, name, parentName })[0];
730
- }).filter(Boolean).filter((item) => {
731
- return item && item.keyword !== unknownReturn;
732
- }).map((item) => {
733
- if (isKeyword(item, schemaKeywords.object)) {
734
- return {
735
- ...item,
736
- args: {
737
- ...item.args,
738
- strict: true
739
- }
740
- };
741
- }
742
- return item;
743
- })
744
- };
745
- if (schemaWithoutAnyOf.properties) {
746
- return [...this.buildSchemas({ schema: schemaWithoutAnyOf, name, parentName }), union, ...baseItems];
747
- }
748
- return [union, ...baseItems];
749
- }
750
- if (schema.allOf) {
751
- const schemaWithoutAllOf = { ...schema, allOf: void 0 };
752
- const and = {
753
- keyword: schemaKeywords.and,
754
- args: schema.allOf.map((item) => {
755
- return item && this.buildSchemas({ schema: item, name, parentName })[0];
756
- }).filter(Boolean).filter((item) => {
757
- return item && item.keyword !== unknownReturn;
758
- })
759
- };
760
- if (schemaWithoutAllOf.properties) {
761
- return [
762
- {
763
- ...and,
764
- args: [...and.args || [], ...this.buildSchemas({ schema: schemaWithoutAllOf, name, parentName })]
765
- },
766
- ...baseItems
767
- ];
768
- }
769
- return [and, ...baseItems];
770
- }
771
- if (schema.enum) {
772
- const enumName = getUniqueName(pascalCase([parentName, name, options.enumSuffix].join(" ")), __privateMethod(this, _getUsedEnumNames, getUsedEnumNames_fn).call(this, { schema, name }));
773
- const typeName = this.context.pluginManager.resolveName({
774
- name: enumName,
775
- pluginKey: this.context.plugin.key,
776
- type: "type"
777
- });
778
- const extensionEnums = ["x-enumNames", "x-enum-varnames"].filter((extensionKey) => extensionKey in schema).map((extensionKey) => {
779
- return [
780
- {
781
- keyword: schemaKeywords.enum,
782
- args: {
783
- name,
784
- typeName,
785
- asConst: false,
786
- items: [...new Set(schema[extensionKey])].map((name2, index) => ({
787
- name: transformers2.stringify(name2),
788
- value: schema.enum?.[index],
789
- format: isNumber(schema.enum?.[index]) ? "number" : "string"
790
- }))
791
- }
792
- },
793
- ...baseItems.filter(
794
- (item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches
795
- )
796
- ];
797
- });
798
- if (schema.type === "number" || schema.type === "integer") {
799
- const enumNames = extensionEnums[0]?.find((item) => isKeyword(item, schemaKeywords.enum));
800
- return [
801
- {
802
- keyword: schemaKeywords.enum,
803
- args: {
804
- name: enumName,
805
- typeName,
806
- asConst: true,
807
- items: enumNames?.args?.items ? [...new Set(enumNames.args.items)].map(({ name: name2, value }) => ({
808
- name: name2,
809
- value,
810
- format: "number"
811
- })) : [...new Set(schema.enum)].map((value) => {
812
- return {
813
- name: value,
814
- value,
815
- format: "number"
816
- };
817
- })
818
- }
819
- },
820
- ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
821
- ];
822
- }
823
- if (extensionEnums.length > 0 && extensionEnums[0]) {
824
- return extensionEnums[0];
825
- }
826
- return [
827
- {
828
- keyword: schemaKeywords.enum,
829
- args: {
830
- name: enumName,
831
- typeName,
832
- asConst: false,
833
- items: [...new Set(schema.enum)].map((value) => ({
834
- name: transformers2.stringify(value),
835
- value,
836
- format: isNumber(value) ? "number" : "string"
837
- }))
838
- }
839
- },
840
- ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max && item.keyword !== schemaKeywords.matches)
841
- ];
842
- }
843
- if ("prefixItems" in schema) {
844
- const prefixItems = schema.prefixItems;
845
- return [
846
- {
847
- keyword: schemaKeywords.tuple,
848
- args: prefixItems.map((item) => {
849
- return this.buildSchemas({ schema: item, name, parentName })[0];
850
- }).filter(Boolean)
851
- },
852
- ...baseItems
853
- ];
854
- }
855
- if (version === "3.1" && "const" in schema) {
856
- if (schema["const"]) {
857
- return [
858
- {
859
- keyword: schemaKeywords.const,
860
- args: {
861
- name: schema["const"],
862
- format: typeof schema["const"] === "number" ? "number" : "string",
863
- value: schema["const"]
864
- }
865
- },
866
- ...baseItems
867
- ];
868
- }
869
- return [{ keyword: schemaKeywords.null }];
870
- }
871
- if (schema.format) {
872
- switch (schema.format) {
873
- case "binary":
874
- baseItems.push({ keyword: schemaKeywords.blob });
875
- return baseItems;
876
- case "date-time":
877
- if (options.dateType) {
878
- if (options.dateType === "date") {
879
- baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
880
- return baseItems;
881
- }
882
- if (options.dateType === "stringOffset") {
883
- baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: true } });
884
- return baseItems;
885
- }
886
- if (options.dateType === "stringLocal") {
887
- baseItems.unshift({ keyword: schemaKeywords.datetime, args: { local: true } });
888
- return baseItems;
889
- }
890
- baseItems.unshift({ keyword: schemaKeywords.datetime, args: { offset: false } });
891
- return baseItems;
892
- }
893
- break;
894
- case "date":
895
- if (options.dateType) {
896
- if (options.dateType === "date") {
897
- baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "date" } });
898
- return baseItems;
899
- }
900
- baseItems.unshift({ keyword: schemaKeywords.date, args: { type: "string" } });
901
- return baseItems;
902
- }
903
- break;
904
- case "time":
905
- if (options.dateType) {
906
- if (options.dateType === "date") {
907
- baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "date" } });
908
- return baseItems;
909
- }
910
- baseItems.unshift({ keyword: schemaKeywords.time, args: { type: "string" } });
911
- return baseItems;
912
- }
913
- break;
914
- case "uuid":
915
- baseItems.unshift({ keyword: schemaKeywords.uuid });
916
- break;
917
- case "email":
918
- case "idn-email":
919
- baseItems.unshift({ keyword: schemaKeywords.email });
920
- break;
921
- case "uri":
922
- case "ipv4":
923
- case "ipv6":
924
- case "uri-reference":
925
- case "hostname":
926
- case "idn-hostname":
927
- baseItems.unshift({ keyword: schemaKeywords.url });
928
- break;
929
- default:
930
- break;
931
- }
932
- }
933
- if ("items" in schema || schema.type === "array") {
934
- const min2 = schema.minimum ?? schema.minLength ?? schema.minItems ?? void 0;
935
- const max2 = schema.maximum ?? schema.maxLength ?? schema.maxItems ?? void 0;
936
- const items = this.buildSchemas({ schema: "items" in schema ? schema.items : [], name, parentName });
937
- return [
938
- {
939
- keyword: schemaKeywords.array,
940
- args: {
941
- items,
942
- min: min2,
943
- max: max2
944
- }
945
- },
946
- ...baseItems.filter((item) => item.keyword !== schemaKeywords.min && item.keyword !== schemaKeywords.max)
947
- ];
948
- }
949
- if (schema.properties || schema.additionalProperties) {
950
- return [...__privateMethod(this, _parseProperties, parseProperties_fn).call(this, { schema, name }), ...baseItems];
951
- }
952
- if (schema.type) {
953
- if (Array.isArray(schema.type)) {
954
- const [type] = schema.type;
955
- return [
956
- ...this.buildSchemas({
957
- schema: {
958
- ...schema,
959
- type
960
- },
961
- name,
962
- parentName
963
- }),
964
- ...baseItems
965
- ].filter(Boolean);
966
- }
967
- return [{ keyword: schema.type }, ...baseItems];
968
- }
969
- return [{ keyword: unknownReturn }];
970
- };
971
- var SchemaGenerator = _SchemaGenerator;
972
-
973
400
  // src/index.ts
974
401
  var definePluginDefault = pluginOas;
975
402
  var src_default = definePluginDefault;