@visulima/jsdoc-open-api 3.0.9 → 3.0.11

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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## @visulima/jsdoc-open-api [3.0.11](https://github.com/visulima/visulima/compare/%40visulima%2Fjsdoc-open-api%403.0.10...%40visulima%2Fjsdoc-open-api%403.0.11) (2026-08-02)
2
+
3
+
4
+ ### Dependencies
5
+
6
+ * **@visulima/fs:** upgraded to 5.1.0
7
+
8
+ ## @visulima/jsdoc-open-api [3.0.10](https://github.com/visulima/visulima/compare/%40visulima%2Fjsdoc-open-api%403.0.9...%40visulima%2Fjsdoc-open-api%403.0.10) (2026-07-27)
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * **@visulima/fs:** upgraded to 5.0.11
14
+
1
15
  ## @visulima/jsdoc-open-api [3.0.9](https://github.com/visulima/visulima/compare/%40visulima%2Fjsdoc-open-api%403.0.8...%40visulima%2Fjsdoc-open-api%403.0.9) (2026-07-27)
2
16
 
3
17
 
@@ -21,7 +21,6 @@ declare class CommanderError extends Error {
21
21
  */
22
22
  constructor(exitCode: number, code: string, message: string);
23
23
  }
24
- // deprecated old name
25
24
  interface ErrorOptions {
26
25
  // optional parameter for error()
27
26
  /** an id string representing the error */
@@ -43,32 +42,26 @@ declare class Argument {
43
42
  * indicate this with <> around the name. Put [] around the name for an optional argument.
44
43
  */
45
44
  constructor(arg: string, description?: string);
46
-
47
45
  /**
48
46
  * Return argument name.
49
47
  */
50
48
  name(): string;
51
-
52
49
  /**
53
50
  * Set the default value, and optionally supply the description to be displayed in the help.
54
51
  */
55
52
  default(value: unknown, description?: string): this;
56
-
57
53
  /**
58
54
  * Set the custom handler for processing CLI command arguments into argument values.
59
55
  */
60
56
  argParser<T>(fn: (value: string, previous: T) => T): this;
61
-
62
57
  /**
63
58
  * Only allow argument value to be one of choices.
64
59
  */
65
60
  choices(values: readonly string[]): this;
66
-
67
61
  /**
68
62
  * Make argument required.
69
63
  */
70
64
  argRequired(): this;
71
-
72
65
  /**
73
66
  * Make argument optional.
74
67
  */
@@ -97,7 +90,6 @@ declare class Option {
97
90
  * Set the default value, and optionally supply the description to be displayed in the help.
98
91
  */
99
92
  default(value: unknown, description?: string): this;
100
-
101
93
  /**
102
94
  * Preset to use when option used without option-argument, especially optional but also boolean and negated.
103
95
  * The custom processing (parseArg) is called.
@@ -109,7 +101,6 @@ declare class Option {
109
101
  * ```
110
102
  */
111
103
  preset(arg: unknown): this;
112
-
113
104
  /**
114
105
  * Add option name(s) that conflict with this option.
115
106
  * An error will be displayed if conflicting options are found during parsing.
@@ -121,7 +112,6 @@ declare class Option {
121
112
  * ```
122
113
  */
123
114
  conflicts(names: string | string[]): this;
124
-
125
115
  /**
126
116
  * Specify implied option values for when this option is set and the implied options are not.
127
117
  *
@@ -133,7 +123,6 @@ declare class Option {
133
123
  * .addOption(new Option('--trace', 'log extra details').implies({ log: 'trace.txt' }));
134
124
  */
135
125
  implies(optionValues: OptionValues): this;
136
-
137
126
  /**
138
127
  * Set environment variable to check for option value.
139
128
  *
@@ -141,43 +130,35 @@ declare class Option {
141
130
  * undefined, or the source of the current value is 'default' or 'config' or 'env'.
142
131
  */
143
132
  env(name: string): this;
144
-
145
133
  /**
146
134
  * Set the custom handler for processing CLI option arguments into option values.
147
135
  */
148
136
  argParser<T>(fn: (value: string, previous: T) => T): this;
149
-
150
137
  /**
151
138
  * Whether the option is mandatory and must have a value after parsing.
152
139
  */
153
140
  makeOptionMandatory(mandatory?: boolean): this;
154
-
155
141
  /**
156
142
  * Hide option in help.
157
143
  */
158
144
  hideHelp(hide?: boolean): this;
159
-
160
145
  /**
161
146
  * Only allow option value to be one of choices.
162
147
  */
163
148
  choices(values: readonly string[]): this;
164
-
165
149
  /**
166
150
  * Return option name.
167
151
  */
168
152
  name(): string;
169
-
170
153
  /**
171
154
  * Return option name, in a camelcase format that can be used
172
155
  * as an object attribute key.
173
156
  */
174
157
  attributeName(): string;
175
-
176
158
  /**
177
159
  * Set the help group heading.
178
160
  */
179
161
  helpGroup(heading: string): this;
180
-
181
162
  /**
182
163
  * Return whether a boolean option.
183
164
  *
@@ -204,7 +185,6 @@ declare class Help {
204
185
  helpWidth?: number;
205
186
  outputHasColors?: boolean;
206
187
  }): void;
207
-
208
188
  /** Get the command term to show in the list of subcommands. */
209
189
  subcommandTerm(cmd: Command): string;
210
190
  /** Get the command summary to show in the list of subcommands. */
@@ -217,12 +197,10 @@ declare class Help {
217
197
  argumentTerm(argument: Argument): string;
218
198
  /** Get the argument description to show in the list of arguments. */
219
199
  argumentDescription(argument: Argument): string;
220
-
221
200
  /** Get the command usage to be displayed at the top of the built-in help. */
222
201
  commandUsage(cmd: Command): string;
223
202
  /** Get the description for the command. */
224
203
  commandDescription(cmd: Command): string;
225
-
226
204
  /** Get an array of the visible subcommands. Includes a placeholder for the implicit help command, if there is one. */
227
205
  visibleCommands(cmd: Command): Command[];
228
206
  /** Get an array of the visible options. Includes a placeholder for the implicit help option, if there is one. */
@@ -231,7 +209,6 @@ declare class Help {
231
209
  visibleGlobalOptions(cmd: Command): Option[];
232
210
  /** Get an array of the arguments which have descriptions. */
233
211
  visibleArguments(cmd: Command): Argument[];
234
-
235
212
  /** Get the longest command term length. */
236
213
  longestSubcommandTermLength(cmd: Command, helper: Help): number;
237
214
  /** Get the longest option term length. */
@@ -240,13 +217,10 @@ declare class Help {
240
217
  longestGlobalOptionTermLength(cmd: Command, helper: Help): number;
241
218
  /** Get the longest argument term length. */
242
219
  longestArgumentTermLength(cmd: Command, helper: Help): number;
243
-
244
220
  /** Return display width of string, ignoring ANSI escape sequences. Used in padding and wrapping calculations. */
245
221
  displayWidth(str: string): number;
246
-
247
222
  /** Style the titles. Called with 'Usage:', 'Options:', etc. */
248
223
  styleTitle(title: string): string;
249
-
250
224
  /** Usage: <str> */
251
225
  styleUsage(str: string): string;
252
226
  /** Style for command name in usage string. */
@@ -266,19 +240,15 @@ declare class Help {
266
240
  styleSubcommandText(str: string): string;
267
241
  /** Base style used in terms and usage for arguments. */
268
242
  styleArgumentText(str: string): string;
269
-
270
243
  /** Calculate the pad width from the maximum term length. */
271
244
  padWidth(cmd: Command, helper: Help): number;
272
-
273
245
  /**
274
246
  * Wrap a string at whitespace, preserving existing line breaks.
275
247
  * Wrapping is skipped if the width is less than `minWidthToWrap`.
276
248
  */
277
249
  boxWrap(str: string, width: number): string;
278
-
279
250
  /** Detect manually wrapped and indented strings by checking for line break followed by whitespace. */
280
251
  preformatted(str: string): boolean;
281
-
282
252
  /**
283
253
  * Format the "item", which consists of a term and description. Pad the term and wrap the description, indenting the following lines.
284
254
  *
@@ -287,17 +257,14 @@ declare class Help {
287
257
  * DD DDD
288
258
  */
289
259
  formatItem(term: string, termWidth: number, description: string, helper: Help): string;
290
-
291
260
  /**
292
261
  * Format a list of items, given a heading and an array of formatted items.
293
262
  */
294
263
  formatItemList(heading: string, items: string[], helper: Help): string[];
295
-
296
264
  /**
297
265
  * Group items by their help group heading.
298
266
  */
299
267
  groupItems<T extends Command | Option>(unsortedItems: T[], visibleItems: T[], getGroup: (item: T) => string): Map<string, T[]>;
300
-
301
268
  /** Generate the built-in help text. */
302
269
  formatHelp(cmd: Command, helper: Help): string;
303
270
  }
@@ -350,7 +317,6 @@ declare class Command {
350
317
  * Get the program version.
351
318
  */
352
319
  version(): string | undefined;
353
-
354
320
  /**
355
321
  * Define a command, implemented using an action handler.
356
322
  *
@@ -391,7 +357,6 @@ declare class Command {
391
357
  * @returns `this` command for chaining
392
358
  */
393
359
  command(nameAndArgs: string, description: string, opts?: ExecutableCommandOptions): this;
394
-
395
360
  /**
396
361
  * Factory routine to create a new unattached command.
397
362
  *
@@ -399,7 +364,6 @@ declare class Command {
399
364
  * create the command. You can override createCommand to customise subcommands.
400
365
  */
401
366
  createCommand(name?: string): Command;
402
-
403
367
  /**
404
368
  * Add a prepared subcommand.
405
369
  *
@@ -408,7 +372,6 @@ declare class Command {
408
372
  * @returns `this` command for chaining
409
373
  */
410
374
  addCommand(cmd: Command, opts?: CommandOptions): this;
411
-
412
375
  /**
413
376
  * Factory routine to create a new unattached argument.
414
377
  *
@@ -416,7 +379,6 @@ declare class Command {
416
379
  * create the argument. You can override createArgument to return a custom argument.
417
380
  */
418
381
  createArgument(name: string, description?: string): Argument;
419
-
420
382
  /**
421
383
  * Define argument syntax for command.
422
384
  *
@@ -439,7 +401,6 @@ declare class Command {
439
401
  * @returns `this` command for chaining
440
402
  */
441
403
  addArgument(arg: Argument): this;
442
-
443
404
  /**
444
405
  * Define argument syntax for command, adding multiple at once (without descriptions).
445
406
  *
@@ -453,7 +414,6 @@ declare class Command {
453
414
  * @returns `this` command for chaining
454
415
  */
455
416
  arguments(names: string): this;
456
-
457
417
  /**
458
418
  * Customise or override default help command. By default a help command is automatically added if your command has subcommands.
459
419
  *
@@ -475,28 +435,23 @@ declare class Command {
475
435
  addHelpCommand(nameAndArgs: string, description?: string): this;
476
436
  /** @deprecated since v12, instead use helpCommand */
477
437
  addHelpCommand(enable?: boolean): this;
478
-
479
438
  /**
480
439
  * Add hook for life cycle event.
481
440
  */
482
441
  hook(event: HookEvent, listener: (thisCommand: Command, actionCommand: Command) => void | Promise<void>): this;
483
-
484
442
  /**
485
443
  * Register callback to use as replacement for calling process.exit.
486
444
  */
487
445
  exitOverride(callback?: (err: CommanderError) => never | void): this;
488
-
489
446
  /**
490
447
  * Display error message and exit (or call exitOverride).
491
448
  */
492
449
  error(message: string, errorOptions?: ErrorOptions): never;
493
-
494
450
  /**
495
451
  * You can customise the help with a subclass of Help by overriding createHelp,
496
452
  * or by overriding Help properties using configureHelp().
497
453
  */
498
454
  createHelp(): Help;
499
-
500
455
  /**
501
456
  * You can customise the help by overriding Help properties using configureHelp(),
502
457
  * or with a subclass of Help by overriding createHelp().
@@ -504,7 +459,6 @@ declare class Command {
504
459
  configureHelp(configuration: HelpConfiguration): this;
505
460
  /** Get configuration */
506
461
  configureHelp(): HelpConfiguration;
507
-
508
462
  /**
509
463
  * The default output goes to stdout and stderr. You can customise this for special
510
464
  * applications. You can also customise the display of errors by overriding outputError.
@@ -524,24 +478,20 @@ declare class Command {
524
478
  configureOutput(configuration: OutputConfiguration): this;
525
479
  /** Get configuration */
526
480
  configureOutput(): OutputConfiguration;
527
-
528
481
  /**
529
482
  * Copy settings that are useful to have in common across root command and subcommands.
530
483
  *
531
484
  * (Used internally when adding a command using `.command()` so subcommands inherit parent settings.)
532
485
  */
533
486
  copyInheritedSettings(sourceCommand: Command): this;
534
-
535
487
  /**
536
488
  * Display the help or a custom message after an error occurs.
537
489
  */
538
490
  showHelpAfterError(displayHelp?: boolean | string): this;
539
-
540
491
  /**
541
492
  * Display suggestion of similar commands for unknown commands, or options for unknown options.
542
493
  */
543
494
  showSuggestionAfterError(displaySuggestion?: boolean): this;
544
-
545
495
  /**
546
496
  * Register callback `fn` for the command.
547
497
  *
@@ -558,7 +508,6 @@ declare class Command {
558
508
  * @returns `this` command for chaining
559
509
  */
560
510
  action(fn: (this: this, ...args: any[]) => void | Promise<void>): this;
561
-
562
511
  /**
563
512
  * Define option with `flags`, `description`, and optional argument parsing function or `defaultValue` or both.
564
513
  *
@@ -583,7 +532,6 @@ declare class Command {
583
532
  option<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
584
533
  /** @deprecated since v7, instead use choices or a custom function */
585
534
  option(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
586
-
587
535
  /**
588
536
  * Define a required option, which must have a value after parsing. This usually means
589
537
  * the option must be specified on the command line. (Otherwise the same as .option().)
@@ -594,23 +542,19 @@ declare class Command {
594
542
  requiredOption<T>(flags: string, description: string, parseArg: (value: string, previous: T) => T, defaultValue?: T): this;
595
543
  /** @deprecated since v7, instead use choices or a custom function */
596
544
  requiredOption(flags: string, description: string, regexp: RegExp, defaultValue?: string | boolean | string[]): this;
597
-
598
545
  /**
599
546
  * Factory routine to create a new unattached option.
600
547
  *
601
548
  * See .option() for creating an attached option, which uses this routine to
602
549
  * create the option. You can override createOption to return a custom option.
603
550
  */
604
-
605
551
  createOption(flags: string, description?: string): Option;
606
-
607
552
  /**
608
553
  * Add a prepared Option.
609
554
  *
610
555
  * See .option() and .requiredOption() for creating and attaching an option in a single call.
611
556
  */
612
557
  addOption(option: Option): this;
613
-
614
558
  /**
615
559
  * Whether to store option values as properties on command object,
616
560
  * or store separately (specify false). In both cases the option values can be accessed using .opts().
@@ -624,27 +568,22 @@ declare class Command {
624
568
  * Retrieve option value.
625
569
  */
626
570
  getOptionValue(key: string): any;
627
-
628
571
  /**
629
572
  * Store option value.
630
573
  */
631
574
  setOptionValue(key: string, value: unknown): this;
632
-
633
575
  /**
634
576
  * Store option value and where the value came from.
635
577
  */
636
578
  setOptionValueWithSource(key: string, value: unknown, source: OptionValueSource): this;
637
-
638
579
  /**
639
580
  * Get source of option value.
640
581
  */
641
582
  getOptionValueSource(key: string): OptionValueSource | undefined;
642
-
643
583
  /**
644
584
  * Get source of option value. See also .optsWithGlobals().
645
585
  */
646
586
  getOptionValueSourceWithGlobals(key: string): OptionValueSource | undefined;
647
-
648
587
  /**
649
588
  * Alter parsing of short flags with optional values.
650
589
  *
@@ -658,21 +597,18 @@ declare class Command {
658
597
  * @returns `this` command for chaining
659
598
  */
660
599
  combineFlagAndOptionalValue(combine?: boolean): this;
661
-
662
600
  /**
663
601
  * Allow unknown options on the command line.
664
602
  *
665
603
  * @returns `this` command for chaining
666
604
  */
667
605
  allowUnknownOption(allowUnknown?: boolean): this;
668
-
669
606
  /**
670
607
  * Allow excess command-arguments on the command line. Pass false to make excess arguments an error.
671
608
  *
672
609
  * @returns `this` command for chaining
673
610
  */
674
611
  allowExcessArguments(allowExcess?: boolean): this;
675
-
676
612
  /**
677
613
  * Enable positional options. Positional means global options are specified before subcommands which lets
678
614
  * subcommands reuse the same option names, and also enables subcommands to turn on passThroughOptions.
@@ -682,7 +618,6 @@ declare class Command {
682
618
  * @returns `this` command for chaining
683
619
  */
684
620
  enablePositionalOptions(positional?: boolean): this;
685
-
686
621
  /**
687
622
  * Pass through options that come after command-arguments rather than treat them as command-options,
688
623
  * so actual command-options come before command-arguments. Turning this on for a subcommand requires
@@ -693,7 +628,6 @@ declare class Command {
693
628
  * @returns `this` command for chaining
694
629
  */
695
630
  passThroughOptions(passThrough?: boolean): this;
696
-
697
631
  /**
698
632
  * Parse `argv`, setting options and invoking commands when defined.
699
633
  *
@@ -716,7 +650,6 @@ declare class Command {
716
650
  * @returns `this` command for chaining
717
651
  */
718
652
  parse(argv?: readonly string[], parseOptions?: ParseOptions): this;
719
-
720
653
  /**
721
654
  * Parse `argv`, setting options and invoking commands when defined.
722
655
  *
@@ -737,7 +670,6 @@ declare class Command {
737
670
  * @returns Promise
738
671
  */
739
672
  parseAsync(argv?: readonly string[], parseOptions?: ParseOptions): Promise<this>;
740
-
741
673
  /**
742
674
  * Called the first time parse is called to save state and allow a restore before subsequent calls to parse.
743
675
  * Not usually called directly, but available for subclasses to save their custom state.
@@ -745,7 +677,6 @@ declare class Command {
745
677
  * This is called in a lazy way. Only commands used in parsing chain will have state saved.
746
678
  */
747
679
  saveStateBeforeParse(): void;
748
-
749
680
  /**
750
681
  * Restore state before parse for calls after the first.
751
682
  * Not usually called directly, but available for subclasses to save their custom state.
@@ -753,7 +684,6 @@ declare class Command {
753
684
  * This is called in a lazy way. Only commands used in parsing chain will have state restored.
754
685
  */
755
686
  restoreStateBeforeParse(): void;
756
-
757
687
  /**
758
688
  * Parse options from `argv` removing known options,
759
689
  * and return argv split into operands and unknown arguments.
@@ -767,23 +697,19 @@ declare class Command {
767
697
  * sub -- --unknown uuu op => [sub --unknown uuu op], []
768
698
  */
769
699
  parseOptions(argv: string[]): ParseOptionsResult;
770
-
771
700
  /**
772
701
  * Return an object containing local option values as key-value pairs
773
702
  */
774
703
  opts<T extends OptionValues>(): T;
775
-
776
704
  /**
777
705
  * Return an object containing merged local and global option values as key-value pairs.
778
706
  */
779
707
  optsWithGlobals<T extends OptionValues>(): T;
780
-
781
708
  /**
782
709
  * Set the description.
783
710
  *
784
711
  * @returns `this` command for chaining
785
712
  */
786
-
787
713
  description(str: string): this;
788
714
  /** @deprecated since v8, instead use .argument to add command argument with description */
789
715
  description(str: string, argsDescription: Record<string, string>): this;
@@ -791,19 +717,16 @@ declare class Command {
791
717
  * Get the description.
792
718
  */
793
719
  description(): string;
794
-
795
720
  /**
796
721
  * Set the summary. Used when listed as subcommand of parent.
797
722
  *
798
723
  * @returns `this` command for chaining
799
724
  */
800
-
801
725
  summary(str: string): this;
802
726
  /**
803
727
  * Get the summary.
804
728
  */
805
729
  summary(): string;
806
-
807
730
  /**
808
731
  * Set an alias for the command.
809
732
  *
@@ -816,7 +739,6 @@ declare class Command {
816
739
  * Get alias for the command.
817
740
  */
818
741
  alias(): string;
819
-
820
742
  /**
821
743
  * Set aliases for the command.
822
744
  *
@@ -829,7 +751,6 @@ declare class Command {
829
751
  * Get aliases for the command.
830
752
  */
831
753
  aliases(): string[];
832
-
833
754
  /**
834
755
  * Set the command usage.
835
756
  *
@@ -840,7 +761,6 @@ declare class Command {
840
761
  * Get the command usage.
841
762
  */
842
763
  usage(): string;
843
-
844
764
  /**
845
765
  * Set the name of the command.
846
766
  *
@@ -851,7 +771,6 @@ declare class Command {
851
771
  * Get the name of the command.
852
772
  */
853
773
  name(): string;
854
-
855
774
  /**
856
775
  * Set the name of the command from script filename, such as process.argv[1],
857
776
  * or import.meta.filename.
@@ -866,7 +785,6 @@ declare class Command {
866
785
  * @returns `this` command for chaining
867
786
  */
868
787
  nameFromFilename(filename: string): this;
869
-
870
788
  /**
871
789
  * Set the directory for searching for executable subcommands of this command.
872
790
  *
@@ -884,7 +802,6 @@ declare class Command {
884
802
  * Get the executable search directory.
885
803
  */
886
804
  executableDir(): string | null;
887
-
888
805
  /**
889
806
  * Set the help group heading for this subcommand in parent command's help.
890
807
  *
@@ -895,7 +812,6 @@ declare class Command {
895
812
  * Get the help group heading for this subcommand in parent command's help.
896
813
  */
897
814
  helpGroup(): string;
898
-
899
815
  /**
900
816
  * Set the default help group heading for subcommands added to this command.
901
817
  * (This does not override a group set directly on the subcommand using .helpGroup().)
@@ -913,7 +829,6 @@ declare class Command {
913
829
  * Get the default help group heading for subcommands added to this command.
914
830
  */
915
831
  commandsGroup(): string;
916
-
917
832
  /**
918
833
  * Set the default help group heading for options added to this command.
919
834
  * (This does not override a group set directly on the option using .helpGroup().)
@@ -931,7 +846,6 @@ declare class Command {
931
846
  * Get the default help group heading for options added to this command.
932
847
  */
933
848
  optionsGroup(): string;
934
-
935
849
  /**
936
850
  * Output help information for this command.
937
851
  *
@@ -941,25 +855,21 @@ declare class Command {
941
855
  outputHelp(context?: HelpContext): void;
942
856
  /** @deprecated since v7 */
943
857
  outputHelp(cb: (str: string) => string): void;
944
-
945
858
  /**
946
859
  * Return command help documentation.
947
860
  */
948
861
  helpInformation(context?: HelpContext): string;
949
-
950
862
  /**
951
863
  * You can pass in flags and a description to override the help
952
864
  * flags and help description for your command. Pass in false
953
865
  * to disable the built-in help option.
954
866
  */
955
867
  helpOption(flags?: string | boolean, description?: string): this;
956
-
957
868
  /**
958
869
  * Supply your own option to use for the built-in help option.
959
870
  * This is an alternative to using helpOption() to customise the flags and description etc.
960
871
  */
961
872
  addHelpOption(option: Option): this;
962
-
963
873
  /**
964
874
  * Output help information and exit.
965
875
  *
@@ -968,7 +878,6 @@ declare class Command {
968
878
  help(context?: HelpContext): never;
969
879
  /** @deprecated since v7 */
970
880
  help(cb: (str: string) => string): never;
971
-
972
881
  /**
973
882
  * Add additional text to be displayed with the built-in help.
974
883
  *
@@ -1 +1 @@
1
- import{default as m}from"../../packem_shared/generateCommand-ClL9Mnc3.js";import{default as t}from"../../packem_shared/initCommand-TixxsVQU.js";export{m as generateCommand,t as initCommand};
1
+ import{default as m}from"../../packem_shared/generateCommand-D0Veh_ij.js";import{default as t}from"../../packem_shared/initCommand-TixxsVQU.js";export{m as generateCommand,t as initCommand};
package/dist/cli/index.js CHANGED
@@ -1 +1 @@
1
- import{default as m}from"../packem_shared/generateCommand-C_XPsbS6.js";import{default as t}from"../packem_shared/initCommand-Ca1hGdYS.js";export{m as generateCommand,t as initCommand};
1
+ import{default as m}from"../packem_shared/generateCommand-BWWxeINy.js";import{default as t}from"../packem_shared/initCommand-Ca1hGdYS.js";export{m as generateCommand,t as initCommand};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import{default as a}from"./packem_shared/jsDocumentCommentsToOpenApi-TjPhUj5G.js";import{default as r}from"./packem_shared/DEFAULT_OPTIONS-C7o6qjwP.js";import{default as l,parseFileMulti as m}from"./packem_shared/parseFile-RDlR4tEF.js";import{default as s}from"./packem_shared/SpecBuilder-Vbq42UbW.js";import{default as d}from"./packem_shared/swaggerJsDocumentCommentsToOpenApi-Bm9R1BnW.js";import{default as n}from"./packem_shared/loadDefinition-7r9qpfuE.js";import{default as g}from"./packem_shared/yamlLoc-DPq-xUM4.js";import{default as D}from"./packem_shared/validate-9Rwe2A3r.js";import{default as T}from"./packem_shared/SwaggerCompilerPlugin-PUOALp2i.js";export{r as DEFAULT_OPTIONS,s as SpecBuilder,T as SwaggerCompilerPlugin,a as jsDocumentCommentsToOpenApi,n as loadDefinition,l as parseFile,m as parseFileMulti,d as swaggerJsDocumentCommentsToOpenApi,D as validate,g as yamlLoc};
1
+ import{default as a}from"./packem_shared/jsDocumentCommentsToOpenApi-CuIbZppP.js";import{default as r}from"./packem_shared/DEFAULT_OPTIONS-QnOdktWv.js";import{default as l,parseFileMulti as m}from"./packem_shared/parseFile-RDlR4tEF.js";import{default as s}from"./packem_shared/SpecBuilder-Vbq42UbW.js";import{default as d}from"./packem_shared/swaggerJsDocumentCommentsToOpenApi-DOyTa91M.js";import{default as n}from"./packem_shared/loadDefinition-7r9qpfuE.js";import{default as g}from"./packem_shared/yamlLoc-DPq-xUM4.js";import{default as D}from"./packem_shared/validate-9Rwe2A3r.js";import{default as T}from"./packem_shared/SwaggerCompilerPlugin-CdaguiSi.js";export{r as DEFAULT_OPTIONS,s as SpecBuilder,T as SwaggerCompilerPlugin,a as jsDocumentCommentsToOpenApi,n as loadDefinition,l as parseFile,m as parseFileMulti,d as swaggerJsDocumentCommentsToOpenApi,D as validate,g as yamlLoc};
@@ -0,0 +1 @@
1
+ import{D as e}from"./constants-CdEv9ZcD.js";const o={cwd:void 0,exclude:[...e],excludeNodeModules:!0,extension:[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],include:["**"],verbose:!0};export{o as default};
@@ -1 +1 @@
1
- import{mkdir as c,writeFile as m}from"node:fs/promises";import{dirname as f}from"node:path";import{collect as p}from"@visulima/fs";import{D as u}from"./constants-CdEv9ZcD.js";import w from"./jsDocumentCommentsToOpenApi-TjPhUj5G.js";import{parseFileMulti as d}from"./parseFile-RDlR4tEF.js";import b from"./SpecBuilder-Vbq42UbW.js";import v from"./swaggerJsDocumentCommentsToOpenApi-Bm9R1BnW.js";import y from"./validate-9Rwe2A3r.js";const D=[w,v],E=r=>r instanceof Error?r:new Error(String(r));class J{assetsPath;ignore;silent;sources;swaggerDefinition;verbose;constructor(t,n,o,s){this.assetsPath=t,this.swaggerDefinition=o,this.sources=n,this.verbose=s.verbose??!1,this.silent=s.silent??!1,this.ignore=s.ignore??[]}apply(t){const n=new Set([...u,...this.ignore]);t.hooks.make.tapAsync("SwaggerCompilerPlugin",async(o,s)=>{this.log("Build paused, switching to swagger build");const e=new b(this.swaggerDefinition);try{for(const i of this.sources){const l=await p(i,{extensions:[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],includeDirs:!1,skip:[...n]});this.verbose&&(this.log(`Found ${String(l.length)} files in ${i}`),this.log(JSON.stringify(l))),l.forEach(g=>{this.verbose&&this.log(`Parsing file ${g}`),e.addData(d(g,D,this.verbose).map(h=>h.spec))})}this.verbose&&(this.log("Validating swagger spec"),this.log(JSON.stringify(e,void 0,2))),await y(structuredClone(e));const{assetsPath:a}=this;await c(f(a),{recursive:!0}),await m(a,JSON.stringify(e,void 0,2)),this.verbose&&this.log(`Written swagger spec to "${this.assetsPath}" file`)}catch(a){const i=E(a);Array.isArray(o.errors)&&o.errors.push(i),s(i);return}this.log("switching back to normal build"),s()})}log(t){this.silent||console.log(t)}}export{J as default};
1
+ import{mkdir as c,writeFile as m}from"node:fs/promises";import{dirname as f}from"node:path";import{collect as p}from"@visulima/fs";import{D as u}from"./constants-CdEv9ZcD.js";import w from"./jsDocumentCommentsToOpenApi-CuIbZppP.js";import{parseFileMulti as d}from"./parseFile-RDlR4tEF.js";import b from"./SpecBuilder-Vbq42UbW.js";import v from"./swaggerJsDocumentCommentsToOpenApi-DOyTa91M.js";import y from"./validate-9Rwe2A3r.js";const D=[w,v],S=r=>r instanceof Error?r:new Error(String(r));class J{assetsPath;ignore;silent;sources;swaggerDefinition;verbose;constructor(t,n,o,s){this.assetsPath=t,this.swaggerDefinition=o,this.sources=n,this.verbose=s.verbose??!1,this.silent=s.silent??!1,this.ignore=s.ignore??[]}apply(t){const n=new Set([...u,...this.ignore]);t.hooks.make.tapAsync("SwaggerCompilerPlugin",async(o,s)=>{this.log("Build paused, switching to swagger build");const e=new b(this.swaggerDefinition);try{for(const i of this.sources){const l=await p(i,{extensions:[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],includeDirs:!1,skip:[...n]});this.verbose&&(this.log(`Found ${String(l.length)} files in ${i}`),this.log(JSON.stringify(l))),l.forEach(g=>{this.verbose&&this.log(`Parsing file ${g}`),e.addData(d(g,D,this.verbose).map(h=>h.spec))})}this.verbose&&(this.log("Validating swagger spec"),this.log(JSON.stringify(e,void 0,2))),await y(structuredClone(e));const{assetsPath:a}=this;await c(f(a),{recursive:!0}),await m(a,JSON.stringify(e,void 0,2)),this.verbose&&this.log(`Written swagger spec to "${this.assetsPath}" file`)}catch(a){const i=S(a);Array.isArray(o.errors)&&o.errors.push(i),s(i);return}this.log("switching back to normal build"),s()})}log(t){this.silent||console.log(t)}}export{J as default};
@@ -0,0 +1,5 @@
1
+ import{mkdir as b,writeFile as D,stat as E,realpath as O}from"node:fs/promises";import{dirname as S,extname as $,normalize as _}from"node:path";import{stdout as j}from"node:process";import{pathToFileURL as F}from"node:url";import{collect as U}from"@visulima/fs";import{MultiBar as x,Presets as L}from"cli-progress";import N from"yaml";import{D as R}from"./constants-CdEv9ZcD.js";import k from"./jsDocumentCommentsToOpenApi-CuIbZppP.js";import{parseFileMulti as g}from"./parseFile-RDlR4tEF.js";import C from"./SpecBuilder-Vbq42UbW.js";import M from"./swaggerJsDocumentCommentsToOpenApi-DOyTa91M.js";import T from"./loadDefinition-7r9qpfuE.js";import V from"./validate-9Rwe2A3r.js";const A=new Set([".yaml",".yml"]),u="-",d=[k,M],J=async t=>{try{let e=await import(F(_(t)).href);return e?.default&&(e=e.default),e}catch(e){if(e?.code==="ERR_MODULE_NOT_FOUND"||e?.code==="MODULE_NOT_FOUND"||e?.code==="ERR_LOAD_URL")throw new Error(`No config file found, on: ${t}
2
+ `,{cause:e});const o=e instanceof Error?e.message:String(e);throw new Error(`Failed to load config file "${t}": ${o}`,{cause:e})}},P=async(t,e,o)=>{const r=await J(o.config??t),i=o.definition??r.definition;let{swaggerDefinition:n}=r;if(i&&(n={...T(i),...n}),n===null||typeof n!="object")throw new TypeError(`Invalid config "${o.config??t}": missing "swaggerDefinition" object. Provide it in the config or pass a base definition file via -d/--definition.`);const f=o.output===u?void 0:new x({clearOnComplete:!1,format:"{value}/{total} | {bar} | {filename}",hideCursor:!0},L.shades_grey),s=new C(n),w=new Set([...R,...r.exclude??[]]);try{for(const m of e){const y=(await E(m)).isDirectory(),a=await O(m);if(!y){s.addData(g(a,d,o.verbose).map(c=>c.spec));continue}const l=await U(a,{extensions:r.extensions??[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],followSymlinks:r.followSymlinks??!1,match:r.include,skip:[...w]});(o.verbose??o.veryVerbose)&&console.log(`
3
+ Found ${String(l.length)} files in ${a}`),o.veryVerbose&&console.log(l);const h=f?.create(l.length,0);l.forEach(c=>{o.verbose&&console.log(`Parsing file ${c}`),h?.increment(1,{filename:a}),s.addData(g(c,d,o.verbose).map(v=>v.spec))})}o.verbose&&console.log("Validating swagger spec"),o.veryVerbose&&console.log(JSON.stringify(s,void 0,2)),await V(structuredClone(s))}finally{f?.stop()}return s},p=(t,e)=>A.has($(e))?N.stringify(structuredClone(t)):JSON.stringify(t,void 0,2),te=async(t,e,o)=>{const r=await P(t,e,o),i=o.output??"swagger.json";if(i===u){j.write(`${p(r,"swagger.json")}
4
+ `);return}o.verbose&&console.log(`Written swagger spec to "${i}" file`),await b(S(i),{recursive:!0}),await D(i,p(r,i)),console.log(`
5
+ Swagger specification is ready, check the "${i}" file.`)};export{te as default};
@@ -0,0 +1 @@
1
+ import{watch as y}from"node:fs";import{resolve as f}from"node:path";import l,{exit as h}from"node:process";import m from"./generateCommand-BWWxeINy.js";const v=200,c=i=>{console.error(i)},S=async(i,s,r)=>{let t=!1,e=!1;const n=async()=>{if(t){e=!0;return}t=!0;try{await m(i,s,r)}catch(a){c(a)}finally{t=!1,e&&(e=!1,n().catch(c))}},g=f(r.output??"swagger.json");let o;const w=()=>{o&&clearTimeout(o),o=setTimeout(()=>{o=void 0,n().catch(c)},v)},d=s.map(a=>y(a,{recursive:!0},(b,u)=>{u!==null&&f(a,u)===g||w()})),p=()=>{o&&clearTimeout(o),d.forEach(a=>{a.close()}),h(0)};l.once("SIGINT",p),l.once("SIGTERM",p),await n(),console.log("Watching for changes... (press Ctrl+C to exit)")},G=(i,s="generate",r=".openapirc.js")=>{i.command(s).description("Generates OpenAPI (Swagger) documentation from JSDoc's").usage("[options] <path ...>").argument("[path ...]","Paths to files or directories to parse").option("-c, --config [.openapirc.js]","@visulima/jsdoc-open-api config file path.").option("-d, --definition [definition.yaml]","Base OpenAPI definition file (YAML/JSON) to seed info/servers/components.").option("-o, --output [swaggerSpec.json]",'Output swagger specification. Use "-" to write to stdout, or a .yaml/.yml path for YAML output.').option("-w, --watch","Re-generate the specification whenever a watched path changes.").option("-v, --verbose","Verbose output.").option("--very-verbose","Very verbose output.").action(async(t,e)=>{try{if(e.watch){await S(r,t,e);return}await m(r,t,e)}catch(n){c(n),h(1)}})};export{G as default};
@@ -0,0 +1 @@
1
+ import{parse as d}from"comment-parser";import{mergeWith as l}from"es-toolkit";import{u as y}from"./customizer-BXFVpImq.js";const f=/\[\]$/,b=/^- /u,$=/Param$/u,g=/^(GET|PUT|POST|DELETE|OPTIONS|HEAD|PATCH|TRACE) \/.*$/,h=t=>{t.security&&(t.security=Object.keys(t.security).map(o=>({[o]:t.security[o]})))},T=new Set(["array","boolean","integer","number","object","string"]),m={binary:"string",byte:"string",date:"string","date-time":"string",double:"number",float:"number",int32:"integer",int64:"integer",password:"string"},w=t=>{const o=t.type,c=o.endsWith("[]"),e=o.replace(f,""),a=T.has(e),s=Object.keys(m).includes(e);let r;if(t.default)switch(e){case"double":case"float":case"number":{r=Number.parseFloat(t.default);break}case"int32":case"int64":case"integer":{r=Number.parseInt(t.default,10);break}default:{r=t.default;break}}let n;a?n={default:r,type:e}:s?n={default:r,format:e,type:m[e]}:n={$ref:`#/components/schemas/${e}`};let i=c?{items:{...n},type:"array"}:{...n};e===""&&(i=void 0);let p=t.description.trim().replace(b,"");return p===""&&(p=void 0),{description:p,name:t.name,rawType:o,required:!t.optional,schema:i}},k=(t,o)=>t.map(c=>{const e=w(c);let a="";switch(e.name&&(a+=e.name),e.description&&(a+=` ${e.description.trim()}`),c.tag){case"bodyComponent":return{requestBody:{$ref:`#/components/requestBodies/${e.rawType}`}};case"bodyContent":return{requestBody:{content:{[e.name.replaceAll(String.raw`*\/*`,"*/*")]:{schema:e.schema}}}};case"bodyDescription":return{requestBody:{description:a}};case"bodyExample":{const s=e.name.split("."),r=s.at(-1);return{requestBody:{content:{[s.slice(0,-1).join(".")]:{examples:{[r]:{$ref:`#/components/examples/${e.rawType}`}}}}}}}case"bodyRequired":return{requestBody:{required:!0}};case"callback":return{callbacks:{[e.name]:{$ref:`#/components/callbacks/${e.rawType}`}}};case"cookieParam":case"headerParam":case"pathParam":case"queryParam":return{parameters:[{description:e.description,in:c.tag.replace($,""),name:e.name,required:e.required,schema:e.schema}]};case"deprecated":return{deprecated:!0};case"description":case"operationId":case"summary":return{[c.tag]:a};case"externalDocs":return{externalDocs:{description:e.description,url:e.name}};case"paramComponent":return{parameters:[{$ref:`#/components/parameters/${e.rawType}`}]};case"response":return{responses:{[e.name]:{description:e.description}}};case"responseComponent":return{responses:{[e.name]:{$ref:`#/components/responses/${e.rawType}`}}};case"responseContent":{const s=e.name.split("."),r=s[0],n=s.slice(1).join(".");return{responses:{[r]:{content:{[n]:{schema:e.schema}}}}}}case"responseExample":{const s=e.name.split("."),r=s[0],n=s.at(-1),i=s.slice(1,-1).join(".");return{responses:{[r]:{content:{[i]:{examples:{[n]:{$ref:`#/components/examples/${e.rawType}`}}}}}}}}case"responseHeader":{const[s,r]=e.name.split(".");return{responses:{[s]:{headers:{[r]:{description:e.description,schema:e.schema}}}}}}case"responseHeaderComponent":{const[s,r]=e.name.split(".");return{responses:{[s]:{headers:{[r]:{$ref:`#/components/headers/${e.rawType}`}}}}}}case"responseLink":{const[s,r]=e.name.split(".");return{responses:{[s]:{links:{[r]:{$ref:`#/components/links/${e.rawType}`}}}}}}case"security":{const[s,r]=e.name.split(".");let n=[];return r&&(n=[r]),{security:{[s]:n}}}case"server":return{servers:[{description:e.description,url:e.name}]};case"tag":return{tags:[a]};default:return{}}}),E=(t,o,c)=>(c??d(t,{spacing:"preserve"})).filter(e=>g.test(e.description.trim())).map(e=>{const a=e.tags.length+1,s={};for(const u of k(e.tags))l(s,u,y);h(s);const[r,n]=e.description.split(" "),i={[n.trim()]:{[r.toLowerCase().trim()]:{...s}}},p=JSON.parse(JSON.stringify({paths:i}));return{loc:a,spec:p}});export{E as default};
@@ -1,4 +1,4 @@
1
- import{parse as f}from"comment-parser";import{mergeWith as m}from"es-toolkit";import y from"yaml";import{u as l}from"./customizer-BXFVpImq.js";const g=(s,t)=>{if(t===null)return s},h=(s,t)=>{const e=m({},s??{},g);return m(e,t??{},g)},d=s=>Object.keys(s).map(t=>s[t]).every(t=>typeof t=="object"&&Object.keys(t).every(e=>!(e in t))),u=(s,t)=>t.some(e=>s.name===e.name),v=s=>{switch(s.tag){case"asyncapi":return"v4";case"openapi":return"v3";case"swagger":return"v2";default:return"v2"}},w=(s,t,e)=>{if(e==="x-webhooks"&&(s[e]=t[e]),!e.startsWith("x-"))if(["components","consumes","produces","paths","schemas","securityDefinitions","responses","parameters","definitions","channels"].includes(e))Object.keys(t[e]).forEach(r=>{s[e][r]=h(s[e][r],t[e][r])});else if(e==="tags"){const{tags:r}=t;Array.isArray(r)?r.forEach(n=>{u(n,s.tags)||s.tags.push(n)}):u(r,s.tags)||s.tags.push(r)}else if(e==="security"){const{security:r}=t;s.security=r}else e.startsWith("/")&&(s.paths[e]=h(s.paths[e],t[e]))},E={v2:["paths","definitions","responses","parameters","securityDefinitions"],v3:["paths","definitions","responses","parameters","securityDefinitions","components"],v4:["components","channels"]},S=(s,t)=>s.map(e=>{const r=e.description!==""||e.name.startsWith("/")||e.name.endsWith(":");if((e.tag==="openapi"||e.tag==="swagger"||e.tag==="asyncapi")&&r){let n=e.description;(e.name.startsWith("/")||e.name.endsWith(":"))&&(n=n.trim()===""?e.name:`${e.name}
1
+ import{parse as u}from"comment-parser";import{mergeWith as m}from"es-toolkit";import y from"yaml";import{u as l}from"./customizer-BXFVpImq.js";const g=(s,t)=>{if(t===null)return s},f=(s,t)=>{const e=m({},s??{},g);return m(e,t??{},g)},d=s=>Object.keys(s).map(t=>s[t]).every(t=>typeof t=="object"&&Object.keys(t).every(e=>!(e in t))),h=(s,t)=>t.some(e=>s.name===e.name),v=s=>{switch(s.tag){case"asyncapi":return"v4";case"openapi":return"v3";case"swagger":return"v2";default:return"v2"}},w=(s,t,e)=>{if(e==="x-webhooks"&&(s[e]=t[e]),!e.startsWith("x-"))if(["components","consumes","produces","paths","schemas","securityDefinitions","responses","parameters","definitions","channels"].includes(e)){const r=t[e];r!=null&&(s[e]??={},Object.keys(r).forEach(n=>{s[e][n]=f(s[e][n],r[n])}))}else if(e==="tags"){const{tags:r}=t;Array.isArray(r)?r.forEach(n=>{h(n,s.tags)||s.tags.push(n)}):h(r,s.tags)||s.tags.push(r)}else if(e==="security"){const{security:r}=t;s.security=r}else e.startsWith("/")&&(s.paths[e]=f(s.paths[e],t[e]))},E={v2:["paths","definitions","responses","parameters","securityDefinitions"],v3:["paths","definitions","responses","parameters","securityDefinitions","components"],v4:["components","channels"]},S=(s,t)=>s.map(e=>{const r=e.description!==""||e.name.startsWith("/")||e.name.endsWith(":");if((e.tag==="openapi"||e.tag==="swagger"||e.tag==="asyncapi")&&r){let n=e.description;(e.name.startsWith("/")||e.name.endsWith(":"))&&(n=n.trim()===""?e.name:`${e.name}
2
2
  ${n}`);const a=y.parseDocument(n);if(a.errors.length>0){a.errors.forEach(p=>{p.annotation=n});let i="Error parsing YAML in @openapi spec:";throw i+=t?a.errors.map(p=>`${p.toString()}
3
3
  Imbedded within:
4
4
  \`\`\`
@@ -7,4 +7,4 @@ Imbedded within:
7
7
  `)}
8
8
  \`\`\``).join(`
9
9
  `):a.errors.map(p=>p.toString()).join(`
10
- `),new Error(i)}const c=a.toJSON(),o={tags:[]};return E[v(e)].forEach(i=>{o[i]=o[i]??{}}),Object.keys(c).forEach(i=>{w(o,c,i)}),o}return{}}),O=new Set(["asyncapi","openapi","swagger"]),k=(s,t,e)=>(e??f(s,{spacing:"preserve"})).filter(r=>r.tags.some(n=>O.has(n.tag))).map(r=>{const n=r.tags.length+1,a={};for(const o of S(r.tags,t))m(a,o,l);["definitions","responses","parameters","securityDefinitions","components","tags"].forEach(o=>{a[o]!==void 0&&d(a[o])&&delete a[o]});const c=JSON.parse(JSON.stringify(a));return{loc:n,spec:c}});export{k as default};
10
+ `),new Error(i)}const c=a.toJSON(),o={tags:[]};return E[v(e)].forEach(i=>{o[i]=o[i]??{}}),Object.keys(c).forEach(i=>{w(o,c,i)}),o}return{}}),O=new Set(["asyncapi","openapi","swagger"]),k=(s,t,e)=>(e??u(s,{spacing:"preserve"})).filter(r=>r.tags.some(n=>O.has(n.tag))).map(r=>{const n=r.tags.length+1,a={};for(const o of S(r.tags,t))m(a,o,l);["definitions","responses","parameters","securityDefinitions","components","tags"].forEach(o=>{a[o]!==void 0&&d(a[o])&&delete a[o]});const c=JSON.parse(JSON.stringify(a));return{loc:n,spec:c}});export{k as default};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/jsdoc-open-api",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "description": "Generates swagger doc based on JSDoc.",
5
5
  "keywords": [
6
6
  "api",
@@ -90,7 +90,7 @@
90
90
  },
91
91
  "dependencies": {
92
92
  "@apidevtools/swagger-parser": "^12.1.0",
93
- "@visulima/fs": "5.0.10",
93
+ "@visulima/fs": "5.1.0",
94
94
  "comment-parser": "1.4.7",
95
95
  "es-toolkit": "^1.49.0",
96
96
  "yaml": "2.9.0"
@@ -1 +0,0 @@
1
- const s={cwd:void 0,exclude:["coverage/**","packages/*/test{,s}/**","**/*.d.ts","test{,s}/**","test{,-*}.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/*{.,-}test.{js,cjs,mjs,ts,tsx,jsx,yaml,yml}","**/__tests__/**","**/{ava,babel,nyc}.config.{js,cjs,mjs}","**/jest.config.{js,cjs,mjs,ts}","**/{karma,rollup,webpack}.config.js","**/.{eslint,mocha}rc.{js,cjs}","**/.{travis,yarnrc}.yml","**/{docker-compose}.yml"],excludeNodeModules:!0,extension:[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],include:["**"],verbose:!0};export{s as default};
@@ -1,5 +0,0 @@
1
- import{mkdir as D,writeFile as b,lstat as E,realpath as O}from"node:fs/promises";import{dirname as S,extname as _,normalize as F}from"node:path";import{stdout as U}from"node:process";import{pathToFileURL as x}from"node:url";import{collect as L}from"@visulima/fs";import{MultiBar as N,Presets as j}from"cli-progress";import R from"yaml";import{D as k}from"./constants-CdEv9ZcD.js";import C from"./jsDocumentCommentsToOpenApi-TjPhUj5G.js";import{parseFileMulti as g}from"./parseFile-RDlR4tEF.js";import M from"./SpecBuilder-Vbq42UbW.js";import V from"./swaggerJsDocumentCommentsToOpenApi-Bm9R1BnW.js";import P from"./loadDefinition-7r9qpfuE.js";import T from"./validate-9Rwe2A3r.js";const A=new Set([".yaml",".yml"]),u="-",p=[C,V],J=async t=>{try{let e=await import(x(F(t)).href);return e?.default&&(e=e.default),e}catch(e){if(e?.code==="ERR_MODULE_NOT_FOUND"||e?.code==="MODULE_NOT_FOUND"||e?.code==="ERR_LOAD_URL")throw new Error(`No config file found, on: ${t}
2
- `,{cause:e});const o=e instanceof Error?e.message:String(e);throw new Error(`Failed to load config file "${t}": ${o}`,{cause:e})}},z=async(t,e,o)=>{const r=await J(o.config??t),i=o.definition??r.definition;let{swaggerDefinition:c}=r;i&&(c={...P(i),...c});const f=o.output===u?void 0:new N({clearOnComplete:!1,format:"{value}/{total} | {bar} | {filename}",hideCursor:!0},j.shades_grey),s=new M(c),w=new Set([...k,...r.exclude]);for(const m of e){const y=(await E(m)).isDirectory(),a=await O(m);if(!y){s.addData(g(a,p,o.verbose).map(l=>l.spec));continue}const n=await L(a,{extensions:r.extensions??[".js",".cjs",".mjs",".ts",".tsx",".jsx",".yaml",".yml"],followSymlinks:r.followSymlinks??!1,match:r.include,skip:[...w]});(o.verbose??o.veryVerbose)&&console.log(`
3
- Found ${String(n.length)} files in ${a}`),o.veryVerbose&&console.log(n);const h=f?.create(n.length,0);n.forEach(l=>{o.verbose&&console.log(`Parsing file ${l}`),h?.increment(1,{filename:a}),s.addData(g(l,p,o.verbose).map(v=>v.spec))})}return o.verbose&&console.log("Validating swagger spec"),o.veryVerbose&&console.log(JSON.stringify(s,void 0,2)),await T(structuredClone(s)),f?.stop(),s},d=(t,e)=>A.has(_(e))?R.stringify(structuredClone(t)):JSON.stringify(t,void 0,2),te=async(t,e,o)=>{const r=await z(t,e,o),i=o.output??"swagger.json";if(i===u){U.write(`${d(r,"swagger.json")}
4
- `);return}o.verbose&&console.log(`Written swagger spec to "${i}" file`),await D(S(i),{recursive:!0}),await b(i,d(r,i)),console.log(`
5
- Swagger specification is ready, check the "${i}" file.`)};export{te as default};
@@ -1 +0,0 @@
1
- import{watch as u}from"node:fs";import s,{exit as p}from"node:process";import f from"./generateCommand-C_XPsbS6.js";const c=o=>{console.error(o)},h=async(o,a,r)=>{const e=async()=>{await f(o,a,r)},t=a.map(i=>u(i,{recursive:!0},()=>{e().catch(c)})),n=()=>{t.forEach(i=>{i.close()}),p(0)};s.once("SIGINT",n),s.once("SIGTERM",n);try{await e()}catch(i){c(i)}console.log("Watching for changes... (press Ctrl+C to exit)")},d=(o,a="generate",r=".openapirc.js")=>{o.command(a).description("Generates OpenAPI (Swagger) documentation from JSDoc's").usage("[options] <path ...>").argument("[path ...]","Paths to files or directories to parse").option("-c, --config [.openapirc.js]","@visulima/jsdoc-open-api config file path.").option("-d, --definition [definition.yaml]","Base OpenAPI definition file (YAML/JSON) to seed info/servers/components.").option("-o, --output [swaggerSpec.json]",'Output swagger specification. Use "-" to write to stdout, or a .yaml/.yml path for YAML output.').option("-w, --watch","Re-generate the specification whenever a watched path changes.").option("-v, --verbose","Verbose output.").option("--very-verbose","Very verbose output.").action(async(e,t)=>{if(t.watch){await h(r,e,t);return}try{await f(r,e,t)}catch(n){c(n),p(1)}})};export{d as default};
@@ -1 +0,0 @@
1
- import{parse as d}from"comment-parser";import{mergeWith as l}from"es-toolkit";import{u as y}from"./customizer-BXFVpImq.js";const f=/\[\]$/,b=/^- /u,$=/Param$/u,g=/^(GET|PUT|POST|DELETE|OPTIONS|HEAD|PATCH|TRACE) \/.*$/,h=t=>{t.security&&(t.security=Object.keys(t.security).map(o=>({[o]:t.security[o]})))},T=new Set(["array","boolean","integer","number","object","string"]),m={binary:"string",byte:"string",date:"string","date-time":"string",double:"number",float:"number",int32:"integer",int64:"integer",password:"string"},w=t=>{const o=t.type,c=o.endsWith("[]"),e=o.replace(f,""),n=T.has(e),r=Object.keys(m).includes(e);let s;if(t.default)switch(e){case"double":case"float":case"number":{s=Number.parseFloat(t.default);break}case"int32":case"int64":case"integer":{s=Number.parseInt(t.default,10);break}default:{s=t.default;break}}let a;n?a={default:s,type:e}:r?a={default:s,format:e,type:m[e]}:a={$ref:`#/components/schemas/${e}`};let p=c?{items:{...a},type:"array"}:{...a};e===""&&(p=void 0);let i=t.description.trim().replace(b,"");return i===""&&(i=void 0),{description:i,name:t.name,rawType:o,required:!t.optional,schema:p}},k=(t,o)=>t.map(c=>{const e=w(c);let n="";switch(e.name&&(n+=e.name),e.description&&(n+=` ${e.description.trim()}`),c.tag){case"bodyComponent":return{requestBody:{$ref:`#/components/requestBodies/${e.rawType}`}};case"bodyContent":return{requestBody:{content:{[e.name.replaceAll(String.raw`*\/*`,"*/*")]:{schema:e.schema}}}};case"bodyDescription":return{requestBody:{description:n}};case"bodyExample":{const[r,s]=e.name.split(".");return{requestBody:{content:{[r]:{examples:{[s]:{$ref:`#/components/examples/${e.rawType}`}}}}}}}case"bodyRequired":return{requestBody:{required:!0}};case"callback":return{callbacks:{[e.name]:{$ref:`#/components/callbacks/${e.rawType}`}}};case"cookieParam":case"headerParam":case"pathParam":case"queryParam":return{parameters:[{description:e.description,in:c.tag.replace($,""),name:e.name,required:e.required,schema:e.schema}]};case"deprecated":return{deprecated:!0};case"description":case"operationId":case"summary":return{[c.tag]:n};case"externalDocs":return{externalDocs:{description:e.description,url:e.name}};case"paramComponent":return{parameters:[{$ref:`#/components/parameters/${e.rawType}`}]};case"response":return{responses:{[e.name]:{description:e.description}}};case"responseComponent":return{responses:{[e.name]:{$ref:`#/components/responses/${e.rawType}`}}};case"responseContent":{const[r,s]=e.name.split(".");return{responses:{[r]:{content:{[s]:{schema:e.schema}}}}}}case"responseExample":{const[r,s,a]=e.name.split(".");return{responses:{[r]:{content:{[s]:{examples:{[a]:{$ref:`#/components/examples/${e.rawType}`}}}}}}}}case"responseHeader":{const[r,s]=e.name.split(".");return{responses:{[r]:{headers:{[s]:{description:e.description,schema:e.schema}}}}}}case"responseHeaderComponent":{const[r,s]=e.name.split(".");return{responses:{[r]:{headers:{[s]:{$ref:`#/components/headers/${e.rawType}`}}}}}}case"responseLink":{const[r,s]=e.name.split(".");return{responses:{[r]:{links:{[s]:{$ref:`#/components/links/${e.rawType}`}}}}}}case"security":{const[r,s]=e.name.split(".");let a=[];return s&&(a=[s]),{security:{[r]:a}}}case"server":return{servers:[{description:e.description,url:e.name}]};case"tag":return{tags:[n]};default:return{}}}),C=(t,o,c)=>(c??d(t,{spacing:"preserve"})).filter(e=>g.test(e.description.trim())).map(e=>{const n=e.tags.length+1,r={};for(const u of k(e.tags))l(r,u,y);h(r);const[s,a]=e.description.split(" "),p={[a.trim()]:{[s.toLowerCase().trim()]:{...r}}},i=JSON.parse(JSON.stringify({paths:p}));return{loc:n,spec:i}});export{C as default};