@scalar/cli 2.5.2 → 2.7.1

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 (78) hide show
  1. package/README.md +113 -28
  2. package/chunks/{action-Y6CEKYEK.js → action-4NGK5XMD.js} +38 -21
  3. package/chunks/{action-DGD6Q6Y5.js → action-5SK5NE7E.js} +10 -4
  4. package/chunks/{action-LUVBQEIQ.js → action-7PEQXDWT.js} +4 -4
  5. package/chunks/action-AQRPFQKI.js +231 -0
  6. package/chunks/{action-TWHLZW4V.js → action-ATGZOWSH.js} +49 -26
  7. package/chunks/{action-ZLTUMRO2.js → action-BAQYJ6UE.js} +25 -21
  8. package/chunks/{action-X7TZA3RE.js → action-BOZNBCNZ.js} +89 -14
  9. package/chunks/{action-OK55BFGM.js → action-BRSSC2SR.js} +7 -7
  10. package/chunks/{action-RBVPKCRI.js → action-CA4QYPI6.js} +6 -6
  11. package/chunks/{action-EPNE5XCM.js → action-CPLH2CQ5.js} +17 -17
  12. package/chunks/{action-FF2OMGAS.js → action-E4YSRFGT.js} +34 -20
  13. package/chunks/{action-7H3XARJP.js → action-EOAVVL52.js} +11 -5
  14. package/chunks/action-F2ZJNURT.js +72 -0
  15. package/chunks/{action-AMNYOA4B.js → action-F7A2K74G.js} +4 -4
  16. package/chunks/{action-ZWQLQENM.js → action-H6OUJWWM.js} +4 -4
  17. package/chunks/{action-HIL5ZFNB.js → action-HJYZCPUN.js} +5 -5
  18. package/chunks/{action-PAA4NWUJ.js → action-JAHFRYWZ.js} +58 -9
  19. package/chunks/{action-42D2C47G.js → action-LPVITMWA.js} +3 -3
  20. package/chunks/{action-P7RFXIC7.js → action-LVDU6YOI.js} +32 -23
  21. package/chunks/{action-HXHBU7XC.js → action-N7BA5I3E.js} +37 -12
  22. package/chunks/{action-W62AIEBN.js → action-NVI5DWFP.js} +6 -6
  23. package/chunks/{action-PHLOE27S.js → action-OX2566BE.js} +32 -25
  24. package/chunks/{action-DCINFQ57.js → action-QYGOPSTY.js} +13 -13
  25. package/chunks/{action-6MZZHPVQ.js → action-RBOLLIGX.js} +27 -14
  26. package/chunks/{action-LFL3ZZKN.js → action-SCOXTCPR.js} +15 -15
  27. package/chunks/{action-OILGZAMK.js → action-SNPOOW6S.js} +20 -15
  28. package/chunks/{action-V5KYG7XD.js → action-SRBN7N3R.js} +10 -10
  29. package/chunks/{action-XUQ7TKKJ.js → action-T5XMJXPO.js} +11 -7
  30. package/chunks/{action-6FAJNP6C.js → action-VOFDW3U2.js} +4 -4
  31. package/chunks/{action-SJYAMXYI.js → action-YRX6SN5F.js} +10 -4
  32. package/chunks/{agent-JAXLLDPE.js → agent-ASPV3R5U.js} +4 -4
  33. package/chunks/{asyncapi-P6Y3L7RG.js → asyncapi-H4FU6GPC.js} +10 -11
  34. package/chunks/{build.action-AZ5ECU4B.js → build.action-6V6GXI3X.js} +35 -31
  35. package/chunks/{chunk-FOKFF4EP.js → chunk-2DSVF5AD.js} +3 -3
  36. package/chunks/{chunk-HXIDUCSZ.js → chunk-2PPRO2QB.js} +1 -1
  37. package/chunks/{chunk-RPVHJMQT.js → chunk-4X47MN6Q.js} +2 -2
  38. package/chunks/{chunk-OQKDBLOZ.js → chunk-5JLVQVKO.js} +8 -0
  39. package/chunks/{chunk-VNYE4R7N.js → chunk-5UHLAJQD.js} +2 -1
  40. package/chunks/{chunk-CX7ZRMTC.js → chunk-6XWCMJDB.js} +1 -1
  41. package/chunks/{chunk-6ZMT63IV.js → chunk-6YPQGVF4.js} +1 -1
  42. package/chunks/{chunk-RAO7VUGM.js → chunk-BDEPNGTO.js} +1 -1
  43. package/chunks/{chunk-FQVVKQPU.js → chunk-BIKOD3SG.js} +134 -1
  44. package/chunks/{chunk-M622VXRQ.js → chunk-C2KAWRIX.js} +1 -1
  45. package/chunks/{chunk-NIXG4KDE.js → chunk-CWCETP6H.js} +170 -5
  46. package/chunks/chunk-EGOXR5FB.js +15 -0
  47. package/chunks/{chunk-3BWGTPPT.js → chunk-FDC2IESH.js} +1776 -1113
  48. package/chunks/{chunk-JV7TUEXQ.js → chunk-GPNB7ISG.js} +14 -1
  49. package/chunks/{chunk-SWWWYWHC.js → chunk-HGOD6THU.js} +27 -18
  50. package/chunks/{chunk-3DJ2GKEG.js → chunk-IMG35UXX.js} +1 -1
  51. package/chunks/{chunk-UB3XGOUW.js → chunk-ISXH6Q7I.js} +253 -9
  52. package/chunks/{chunk-MNLXYOVF.js → chunk-KCCFN4F7.js} +2 -2
  53. package/chunks/{chunk-KEOCJ3NJ.js → chunk-LG7IFACX.js} +38 -87
  54. package/chunks/{chunk-B2MHTD3R.js → chunk-MLSZVVTT.js} +1 -1
  55. package/chunks/{chunk-LCPFHE4Z.js → chunk-OJ2EWIJH.js} +21 -2
  56. package/chunks/{chunk-UMPODUJO.js → chunk-QXQZVEDC.js} +105 -15
  57. package/chunks/{chunk-CIFOFSZ3.js → chunk-R5LK6VPY.js} +72 -7
  58. package/chunks/{chunk-T7B6WNZC.js → chunk-TSURUX4A.js} +12 -3
  59. package/chunks/{chunk-HUCR333E.js → chunk-W24BETFG.js} +2 -2
  60. package/chunks/{chunk-LQN4S62O.js → chunk-XEDGMZJD.js} +18 -4
  61. package/chunks/{chunk-NNMSZVAB.js → chunk-XXSQUBXS.js} +82 -6
  62. package/chunks/{chunk-M6Q3ARBV.js → chunk-YILQODZF.js} +2 -2
  63. package/chunks/{chunk-TYLWJ2UL.js → chunk-ZJVYOZFB.js} +2 -2
  64. package/chunks/{create.action-34OTO2SB.js → create.action-P6DLCK4W.js} +27 -15
  65. package/chunks/{delete.action-6LRT4M3S.js → delete.action-HJKRRHE2.js} +24 -15
  66. package/chunks/{delete.action-ZYXFMIOW.js → delete.action-Z3GAA4ZN.js} +24 -15
  67. package/chunks/{get.action-XP36SA2J.js → get.action-IT4EHAV4.js} +10 -10
  68. package/chunks/{list.action-WVRVLX5E.js → list.action-2FU5UZNH.js} +15 -15
  69. package/chunks/{list.action-6LF6KSD5.js → list.action-WLIAO5UW.js} +13 -13
  70. package/chunks/{publish.action-AHFUBT5C.js → publish.action-T4J4DRXR.js} +48 -22
  71. package/chunks/{update.action-ZREAFJVG.js → update.action-3OVS3HWC.js} +25 -16
  72. package/chunks/{update.action-YQTVUDYE.js → update.action-MY7QPSSU.js} +25 -16
  73. package/docs.html +289 -96
  74. package/index.js +436 -401
  75. package/package.json +14 -22
  76. package/skills/scalar-cli/SKILL.md +71 -0
  77. package/template.md +81 -3
  78. package/chunks/action-YRWHX2AE.js +0 -64
package/README.md CHANGED
@@ -27,7 +27,31 @@ npx @scalar/cli help
27
27
 
28
28
  ## Installation
29
29
 
30
- If you really want to become friends you should install the CLI:
30
+ ### Standalone CLI (no Node.js required)
31
+
32
+ Install the latest stable release without Node.js, npm, or administrator access.
33
+
34
+ macOS and Linux (Bash):
35
+
36
+ ```bash
37
+ curl -fsSL https://cdn.scalar.com/cli/install.sh | bash
38
+ ```
39
+
40
+ Windows (PowerShell):
41
+
42
+ ```powershell
43
+ irm https://cdn.scalar.com/cli/install.ps1 | iex
44
+ ```
45
+
46
+ The installers choose the archive for your platform and verify its SHA-256 checksum before installing. macOS and Linux support x64 and ARM64; Linux requires glibc. Windows supports x64 and requires `tar.exe`, included in Windows 10 version 1803 and later.
47
+
48
+ On macOS and Linux, follow the printed PATH instructions if needed. On Windows, open a new terminal after installation. Then run `scalar --help`. Re-run the installer to upgrade.
49
+
50
+ See the [portable CLI guide](https://github.com/scalar/scalar-org/blob/main/projects/cli/portable/README.md) for installation locations, version selection, custom directories, and direct downloads. You can download and inspect either script before running it.
51
+
52
+ ### npm
53
+
54
+ If you already use Node.js, install the CLI with npm:
31
55
 
32
56
  ```bash
33
57
  npm -g install @scalar/cli
@@ -53,6 +77,35 @@ npx @scalar/cli help
53
77
  pnpm dlx @scalar/cli help
54
78
  ```
55
79
 
80
+ ## API Reference configuration
81
+
82
+ Pass API Reference options as a JSON object:
83
+
84
+ ```sh
85
+ scalar document serve openapi.yaml --config ./reference.config.json
86
+ ```
87
+
88
+ ```json
89
+ {
90
+ "orderRequiredPropertiesFirst": false,
91
+ "theme": "purple"
92
+ }
93
+ ```
94
+
95
+ The configuration path is relative to the current working directory. Configuration
96
+ is loaded at startup; restart the command after changing it. `--watch` continues
97
+ to watch the API document. Options requiring JavaScript functions are not supported
98
+ in a JSON file.
99
+
100
+ ## Authentication in automation
101
+
102
+ Use `scalar auth login --token <personal-token>` to authenticate without a browser.
103
+ Alternatively, set `SCALAR_API_KEY`. When both are provided, `SCALAR_API_KEY` takes
104
+ precedence over `--token`. Unset it to use a different explicit token.
105
+
106
+ Supply required options in automation instead of relying on interactive prompts.
107
+ For example, pass `--output` for document transformations.
108
+
56
109
  ## Commands
57
110
 
58
111
  ```
@@ -67,6 +120,7 @@ Options:
67
120
  Commands:
68
121
  readme Open documentation for the CLI
69
122
  upgrade Upgrade current version of your cli
123
+ context Print every command, argument, and option as JSON for AI agents
70
124
  auth Manage authorization on scalar platform
71
125
  document Manage local openapi file
72
126
  project Manage scalar project
@@ -111,6 +165,16 @@ Options:
111
165
  -h, --help display help for command
112
166
  ```
113
167
 
168
+ ### context
169
+ ```
170
+ Usage: scalar context [options]
171
+
172
+ Print every command, argument, and option as JSON for AI agents
173
+
174
+ Options:
175
+ -h, --help display help for command
176
+ ```
177
+
114
178
  ### auth
115
179
  ```
116
180
  Usage: scalar auth [options] [command]
@@ -204,9 +268,6 @@ Options:
204
268
  ```
205
269
 
206
270
  #### split
207
-
208
- Splits AsyncAPI channels, operations, messages, and reusable components (including payload schemas) into JSON chunks. AsyncAPI versions are preserved, including 2.6, 3.0, and 3.1; splitting does not upgrade the document or add Scalar navigation metadata. Use `scalar document upgrade` separately to normalize versions. Nested external references are bundled relative to their source files or URLs, and chunk references resolve relative to the generated files. Both relative and absolute output directories are supported. The entry point is `out.json`.
209
-
210
271
  ```
211
272
  Usage: scalar document split [options] [file|url]
212
273
 
@@ -301,13 +362,14 @@ Usage: scalar document serve [options] [file|url]
301
362
  Serve an API Reference from an OpenAPI or AsyncAPI file
302
363
 
303
364
  Arguments:
304
- file|url OpenAPI or AsyncAPI file or URL to show the reference for
365
+ file|url OpenAPI or AsyncAPI file or URL to show the reference for
305
366
 
306
367
  Options:
307
- -w, --watch watch the file for changes
308
- -o, --once run the server only once and exit after that
309
- -p, --port <port> set the HTTP port for the API reference server
310
- -h, --help display help for command
368
+ -c, --config <file> JSON file with API Reference configuration
369
+ -w, --watch watch the file for changes
370
+ -o, --once run the server only once and exit after that
371
+ -p, --port <port> set the HTTP port for the API reference server
372
+ -h, --help display help for command
311
373
  ```
312
374
 
313
375
  #### share
@@ -430,8 +492,8 @@ Usage: scalar project create [options]
430
492
  Create a new project that is not linked to a github project.
431
493
 
432
494
  Options:
433
- -n, --name [name] name of your project
434
- -s, --slug [slug] project slug
495
+ -n, --name <name> name of your project
496
+ -s, --slug <slug> project slug
435
497
  -h, --help display help for command
436
498
  ```
437
499
 
@@ -442,15 +504,14 @@ Usage: scalar project preview [options] [config]
442
504
  Preview scalar guides
443
505
 
444
506
  Arguments:
445
- config Path to the Scalar configuration file (usually `scalar.config.json5` or `scalar.config.json`)
507
+ config Path to the Scalar configuration file (usually `scalar.config.json5` or `scalar.config.json`)
446
508
 
447
509
  Options:
448
- -p, --port [port] port to run the server on. If the port is not available, it will select another one. (default: "7970")
449
- -h, --host [host] Specify which IP addresses the server should listen on.
450
- -L, --log-level <level> Set the log level (debug, info, warn, error, trace) (default: "info")
451
- -F, --log-formatting <formatting> Set the log formatting (pretty|none). Defaults to pretty formatting outside of CI. (default: "pretty")
452
- -N, --no-open Do not open the browser automatically
453
- --help display help for command
510
+ -p, --port [port] port to run the server on. If the port is not available, it will select another one. (default: "7970")
511
+ -H, --host [host] Specify which IP addresses the server should listen on.
512
+ -L, --log-level <level> Set the log level (choices: "debug", "info", default: "info")
513
+ -N, --no-open Do not open the browser automatically
514
+ -h, --help display help for command
454
515
  ```
455
516
 
456
517
  #### publish
@@ -664,10 +725,10 @@ Options:
664
725
 
665
726
  Commands:
666
727
  list [options] List all SDKs for a team namespace
667
- create [options] Create a new SDK.
728
+ create [options] Create a new SDK. The SDK is created in the namespace of the API it is built from.
668
729
  update [options] Update SDK metadata.
669
730
  delete [options] Delete an SDK.
670
- build [options] Create an SDK build.
731
+ build [options] Build an SDK.
671
732
  help [command] display help for command
672
733
  ```
673
734
 
@@ -686,11 +747,11 @@ Options:
686
747
  ```
687
748
  Usage: scalar sdk create [options]
688
749
 
689
- Create a new SDK.
750
+ Create a new SDK. The SDK is created in the namespace of the API it is built from.
690
751
 
691
752
  Options:
692
753
  -a, --api <api> Registry API slug
693
- -n, --namespace <namespace> Team namespace
754
+ -n, --namespace <namespace> Team namespace to look the API up in
694
755
  -l, --language <language> Language of your SDK (choices: "typescript", "python", "cli", "csharp", "java", "ruby", "php", "go", "rust", "kotlin", "swift", "cpp", "dart")
695
756
  -h, --help display help for command
696
757
  ```
@@ -705,7 +766,7 @@ Options:
705
766
  -s, --slug <slug> SDK slug
706
767
  -n, --namespace <namespace> Team namespace
707
768
  --title <title> Title
708
- --isPrivate <isPrivate> Privacy (public/private)
769
+ --isPrivate <isPrivate> Privacy (true/false or public/private)
709
770
  -h, --help display help for command
710
771
  ```
711
772
 
@@ -725,12 +786,11 @@ Options:
725
786
  ```
726
787
  Usage: scalar sdk build [options]
727
788
 
728
- Create an SDK build.
789
+ Build an SDK.
729
790
 
730
791
  Options:
731
792
  -s, --slug <slug> SDK slug
732
793
  -n, --namespace <namespace> Team namespace
733
- -v, --version <version> SDK Version
734
794
  -h, --help display help for command
735
795
  ```
736
796
 
@@ -775,7 +835,7 @@ Options:
775
835
  -n, --namespace <namespace> Team namespace
776
836
  --title <title> Title
777
837
  --description <description> Description
778
- --isPrivate <isPrivate> Privacy (public/private)
838
+ --isPrivate <isPrivate> Privacy (true/false or public/private)
779
839
  -h, --help display help for command
780
840
  ```
781
841
 
@@ -831,6 +891,28 @@ Options:
831
891
  ```
832
892
 
833
893
 
894
+ ## AI agents
895
+
896
+ `scalar context` prints the whole command tree as JSON: every command with its arguments, options, defaults, and choices, plus notes on running the CLI without prompts and what each exit code means. Point an agent at it instead of having it scrape `--help`:
897
+
898
+ ```bash
899
+ scalar context
900
+ ```
901
+
902
+ The CLI also ships an [Agent Skill](https://agentskills.io) at `skills/scalar-cli/SKILL.md`, in the npm package and in the `app` directory of the standalone archives. Copy it into your agent's skills directory to teach the agent how to use the CLI:
903
+
904
+ ```bash
905
+ mkdir -p .claude/skills
906
+
907
+ # npm (global install)
908
+ cp -r "$(npm root -g)/@scalar/cli/skills/scalar-cli" .claude/skills/
909
+
910
+ # Standalone CLI on macOS or Linux (the installer links `scalar` into its release directory)
911
+ cp -r "$(dirname "$(readlink "$(command -v scalar)")")/app/skills/scalar-cli" .claude/skills/
912
+ ```
913
+
914
+ With the standalone CLI on Windows, the skill is in `%LOCALAPPDATA%\Scalar\current\app\skills\scalar-cli`.
915
+
834
916
  ## GitHub Actions
835
917
 
836
918
  To validate your OpenAPI file in GitHub Actions, add this workflow:
@@ -859,8 +941,7 @@ jobs:
859
941
  node-version: 24
860
942
  - name: Validate OpenAPI File
861
943
  # Replace `./my-openapi-file.yaml` with the correct path and filename for your project.
862
- # Or: run `npx @scalar/cli init` and add the config file to your repository.
863
- run: npx @scalar/cli validate ./my-openapi-file.yaml
944
+ run: npx @scalar/cli document validate ./my-openapi-file.yaml
864
945
  ```
865
946
 
866
947
  ## Development
@@ -879,6 +960,10 @@ pnpm cli:link
879
960
  scalar --version
880
961
  ```
881
962
 
963
+ ### Docs preview from a local build
964
+
965
+ `scalar project preview` runs the docs in a preview server that the CLI downloads to `~/.scalar/isolate` on first use. Every CLI release publishes a matching archive to the CDN, so a released CLI always finds its own. A build from source has no archive until its version ships: the CLI then falls back to the newest published release with the same major version and says which one it used, and otherwise reports that the version is missing. To pin a specific published version instead, set `SSG_DOCS_ISOLATE_VERSION` to the version of a released CLI (`https://cdn.scalar.com/isolates/latest.json` names the newest one).
966
+
882
967
  ## Community
883
968
 
884
969
  We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
@@ -2,52 +2,55 @@ import { createRequire as $$cR } from "node:module"; const require = $$cR(import
2
2
  import {
3
3
  dashboardUrl,
4
4
  registryUrl
5
- } from "./chunk-TYLWJ2UL.js";
5
+ } from "./chunk-ZJVYOZFB.js";
6
6
  import {
7
7
  registry
8
- } from "./chunk-M6Q3ARBV.js";
8
+ } from "./chunk-YILQODZF.js";
9
9
  import {
10
10
  getFileOrUrl,
11
11
  isDocument,
12
12
  safeNormalize
13
- } from "./chunk-SWWWYWHC.js";
13
+ } from "./chunk-HGOD6THU.js";
14
14
  import {
15
15
  DEFAULT_FETCH_CONCURRENCY
16
- } from "./chunk-LCPFHE4Z.js";
16
+ } from "./chunk-OJ2EWIJH.js";
17
17
  import {
18
18
  apiService
19
- } from "./chunk-UB3XGOUW.js";
19
+ } from "./chunk-ISXH6Q7I.js";
20
20
  import {
21
21
  BaseCollections
22
- } from "./chunk-KEOCJ3NJ.js";
22
+ } from "./chunk-LG7IFACX.js";
23
23
  import {
24
24
  getDatabaseClient
25
- } from "./chunk-RPVHJMQT.js";
26
- import "./chunk-FQVVKQPU.js";
27
- import "./chunk-B2MHTD3R.js";
28
- import "./chunk-3BWGTPPT.js";
29
- import "./chunk-M622VXRQ.js";
30
- import "./chunk-CIFOFSZ3.js";
25
+ } from "./chunk-4X47MN6Q.js";
26
+ import "./chunk-BIKOD3SG.js";
27
+ import "./chunk-MLSZVVTT.js";
28
+ import "./chunk-FDC2IESH.js";
29
+ import "./chunk-C2KAWRIX.js";
30
+ import "./chunk-R5LK6VPY.js";
31
31
  import {
32
32
  getAuthData
33
- } from "./chunk-NIXG4KDE.js";
34
- import "./chunk-JV7TUEXQ.js";
33
+ } from "./chunk-CWCETP6H.js";
34
+ import "./chunk-GPNB7ISG.js";
35
35
  import {
36
36
  teamSchema
37
- } from "./chunk-VNYE4R7N.js";
38
- import "./chunk-OQKDBLOZ.js";
37
+ } from "./chunk-5UHLAJQD.js";
38
+ import "./chunk-5JLVQVKO.js";
39
+ import {
40
+ requireInteractive
41
+ } from "./chunk-EGOXR5FB.js";
39
42
  import "./chunk-K74E42RV.js";
40
43
  import {
41
44
  RegistryAsset
42
- } from "./chunk-MNLXYOVF.js";
43
- import "./chunk-CX7ZRMTC.js";
45
+ } from "./chunk-KCCFN4F7.js";
46
+ import "./chunk-6XWCMJDB.js";
44
47
  import {
45
48
  isUrl
46
49
  } from "./chunk-4ORL4MST.js";
47
50
  import {
48
51
  output
49
52
  } from "./chunk-T5HJUAWB.js";
50
- import "./chunk-LQN4S62O.js";
53
+ import "./chunk-XEDGMZJD.js";
51
54
  import {
52
55
  docVersionSchema,
53
56
  external_exports,
@@ -58,6 +61,7 @@ import {
58
61
  import "./chunk-3MZYUBJ6.js";
59
62
 
60
63
  // src/domains/registry/publish/action.ts
64
+ import path from "node:path";
61
65
  import { text } from "@clack/prompts";
62
66
  import as from "ansis";
63
67
  import { bundle } from "@scalar/json-magic/bundle";
@@ -72,7 +76,7 @@ async function publishAction(file, args) {
72
76
  current: external_exports.coerce.boolean(),
73
77
  force: external_exports.coerce.boolean(),
74
78
  bundle: external_exports.coerce.boolean().optional(),
75
- fetchLimit: external_exports.coerce.number().optional(),
79
+ fetchLimit: external_exports.coerce.number().int().positive().optional(),
76
80
  urlMap: external_exports.coerce.boolean().default(false),
77
81
  treeShake: external_exports.coerce.boolean().default(false)
78
82
  }).safeParse({
@@ -82,7 +86,11 @@ async function publishAction(file, args) {
82
86
  version: args.version,
83
87
  private: args.private,
84
88
  current: args.current,
85
- force: args.force
89
+ force: args.force,
90
+ bundle: args.bundle,
91
+ treeShake: args.treeShake,
92
+ urlMap: args.urlMap,
93
+ fetchLimit: args.fetchLimit
86
94
  });
87
95
  if (error)
88
96
  return output.error().title("Invalid input").message(error.issues[0].message).exit("error");
@@ -108,6 +116,9 @@ async function publishAction(file, args) {
108
116
  const namespaceApisRes = await client.managedDocs.getApiDocs(namespace);
109
117
  if (namespaceApisRes.error)
110
118
  return output.error().title(namespaceApisRes.message).exit("error");
119
+ if (!data.file) {
120
+ requireInteractive("Please provide a file path or URL.");
121
+ }
111
122
  const apiFile = data.file || (await text({
112
123
  message: "Please enter a file path or URL for your document",
113
124
  placeholder: "./api.yaml",
@@ -131,6 +142,7 @@ async function publishAction(file, args) {
131
142
  );
132
143
  }
133
144
  const bundledDocument = await bundle(parsed, {
145
+ origin: isUrl(apiFile) ? apiFile : path.resolve(apiFile),
134
146
  plugins: bundlingPlugins,
135
147
  treeShake: data.treeShake,
136
148
  urlMap: data.urlMap
@@ -140,6 +152,11 @@ async function publishAction(file, args) {
140
152
  const parsedVersion = docVersionSchema.safeParse(
141
153
  data.version || specification.info?.version
142
154
  );
155
+ if (!parsedVersion.data) {
156
+ requireInteractive(
157
+ "Please provide --version or a document with a valid info.version."
158
+ );
159
+ }
143
160
  const version = parsedVersion.data || (await text({
144
161
  message: "What is the version of your document (e.g. 0.1.0)?",
145
162
  validate(value) {
@@ -7,12 +7,15 @@ import {
7
7
  isAsyncApiDocument,
8
8
  isDocument,
9
9
  safeNormalize
10
- } from "./chunk-SWWWYWHC.js";
10
+ } from "./chunk-HGOD6THU.js";
11
+ import {
12
+ requireInteractive
13
+ } from "./chunk-EGOXR5FB.js";
11
14
  import {
12
15
  require_dist
13
16
  } from "./chunk-K74E42RV.js";
14
- import "./chunk-MNLXYOVF.js";
15
- import "./chunk-CX7ZRMTC.js";
17
+ import "./chunk-KCCFN4F7.js";
18
+ import "./chunk-6XWCMJDB.js";
16
19
  import {
17
20
  isUrl,
18
21
  isYamlFileName
@@ -20,7 +23,7 @@ import {
20
23
  import {
21
24
  output
22
25
  } from "./chunk-T5HJUAWB.js";
23
- import "./chunk-LQN4S62O.js";
26
+ import "./chunk-XEDGMZJD.js";
24
27
  import "./chunk-IKT5F47M.js";
25
28
  import {
26
29
  __toESM
@@ -44,6 +47,9 @@ async function upgradeAction(input, { output: outputFilePath }) {
44
47
  "Please provide an output file using the -o flag when upgrading from a URL."
45
48
  ).exit("error");
46
49
  }
50
+ requireInteractive(
51
+ "Pass --output to upgrade a document in non-interactive mode."
52
+ );
47
53
  const shouldContinue = await confirm({
48
54
  message: "No output file specified - this will overwrite the input file. Continue?",
49
55
  initialValue: false
@@ -6,19 +6,19 @@ import {
6
6
  isAsyncApiDocument,
7
7
  isDocument,
8
8
  safeNormalize
9
- } from "./chunk-SWWWYWHC.js";
9
+ } from "./chunk-HGOD6THU.js";
10
10
  import {
11
11
  require_dist
12
12
  } from "./chunk-K74E42RV.js";
13
- import "./chunk-MNLXYOVF.js";
14
- import "./chunk-CX7ZRMTC.js";
13
+ import "./chunk-KCCFN4F7.js";
14
+ import "./chunk-6XWCMJDB.js";
15
15
  import {
16
16
  isYamlFileName
17
17
  } from "./chunk-4ORL4MST.js";
18
18
  import {
19
19
  output
20
20
  } from "./chunk-T5HJUAWB.js";
21
- import "./chunk-LQN4S62O.js";
21
+ import "./chunk-XEDGMZJD.js";
22
22
  import {
23
23
  external_exports
24
24
  } from "./chunk-IKT5F47M.js";
@@ -0,0 +1,231 @@
1
+ import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
+ import {
3
+ isAsyncApiDocument,
4
+ isDocument
5
+ } from "./chunk-HGOD6THU.js";
6
+ import {
7
+ err,
8
+ ok
9
+ } from "./chunk-C2KAWRIX.js";
10
+ import "./chunk-KCCFN4F7.js";
11
+ import "./chunk-6XWCMJDB.js";
12
+ import {
13
+ isUrl
14
+ } from "./chunk-4ORL4MST.js";
15
+ import {
16
+ output
17
+ } from "./chunk-T5HJUAWB.js";
18
+ import "./chunk-XEDGMZJD.js";
19
+ import "./chunk-IKT5F47M.js";
20
+ import "./chunk-3MZYUBJ6.js";
21
+
22
+ // src/domains/document/validate/action.ts
23
+ import path from "node:path";
24
+ import as from "ansis";
25
+ import prettyjson from "prettyjson";
26
+ import { validate as validateAsyncApi } from "@scalar/asyncapi-validator";
27
+ import { bundle } from "@scalar/json-magic/bundle";
28
+ import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
29
+ import { validate as validateOpenApi } from "@scalar/openapi-validator";
30
+
31
+ // src/domains/document/validate/resolve-for-validation.ts
32
+ import { createMagicProxy, getRaw } from "@scalar/json-magic/magic-proxy";
33
+ var childContext = (context, key, swagger) => {
34
+ if (context === "data") return "data";
35
+ if (context === "path-items") return "path-item";
36
+ if (context === "callbacks") return "callback";
37
+ if (context === "callback") return key.startsWith("x-") ? "data" : "path-item";
38
+ if (context === "schemas") return "schema";
39
+ if (context === "objects") return "object";
40
+ if (context === "responses") return "response";
41
+ if (context === "links") return "link";
42
+ if (context === "schema") {
43
+ if ([
44
+ "properties",
45
+ "patternProperties",
46
+ "dependentSchemas",
47
+ "$defs",
48
+ "definitions"
49
+ ].includes(key))
50
+ return "schemas";
51
+ if ([
52
+ "items",
53
+ "additionalProperties",
54
+ "unevaluatedProperties",
55
+ "unevaluatedItems",
56
+ "contains",
57
+ "contentSchema",
58
+ "propertyNames",
59
+ "not",
60
+ "if",
61
+ "then",
62
+ "else",
63
+ "allOf",
64
+ "anyOf",
65
+ "oneOf",
66
+ "prefixItems"
67
+ ].includes(key))
68
+ return "schema";
69
+ return "data";
70
+ }
71
+ if (context === "link" && ["parameters", "requestBody"].includes(key))
72
+ return "data";
73
+ if (context === "response" && swagger && key === "examples") return "data";
74
+ if (["paths", "webhooks", "pathItems"].includes(key)) return "path-items";
75
+ if (key === "callbacks") return "callbacks";
76
+ if (key === "responses") return "responses";
77
+ if (key === "links") return "links";
78
+ if (key.startsWith("x-")) return "data";
79
+ if (["example", "default", "enum", "const", "value"].includes(key))
80
+ return "data";
81
+ if (key === "examples") return "objects";
82
+ if (["schemas", "definitions", "$defs"].includes(key)) return "schemas";
83
+ if (key === "schema") return "schema";
84
+ if ([
85
+ "content",
86
+ "parameters",
87
+ "headers",
88
+ "requestBodies",
89
+ "securitySchemes",
90
+ "channels",
91
+ "messages",
92
+ "operations"
93
+ ].includes(key))
94
+ return "objects";
95
+ return "object";
96
+ };
97
+ var resolveForValidation = (document) => {
98
+ const errors = /* @__PURE__ */ new Set();
99
+ const schemaSiblingsApply = typeof document.openapi === "string" && /^3\.[1-9]/.test(document.openapi);
100
+ const cache = /* @__PURE__ */ new WeakMap();
101
+ const visit = (value, ancestors, context, referenceAncestors = /* @__PURE__ */ new Set()) => {
102
+ if (context === "data") return getRaw(value);
103
+ if (value === null || typeof value !== "object") {
104
+ return value;
105
+ }
106
+ const raw = getRaw(value);
107
+ if (ancestors.has(raw)) {
108
+ if (referenceAncestors.has(raw) && "$ref" in value) {
109
+ errors.add(`Circular reference has no concrete target: ${value.$ref}`);
110
+ }
111
+ return {};
112
+ }
113
+ const cached = cache.get(raw);
114
+ if (cached?.has(context)) return cached.get(context);
115
+ const remember = (result2) => {
116
+ const contexts = cache.get(raw) ?? /* @__PURE__ */ new Map();
117
+ contexts.set(context, result2);
118
+ cache.set(raw, contexts);
119
+ return result2;
120
+ };
121
+ const next = new Set(ancestors).add(raw);
122
+ if (Array.isArray(value)) {
123
+ return remember(
124
+ value.map(
125
+ (entry) => visit(
126
+ entry,
127
+ next,
128
+ context === "objects" ? "object" : context === "schemas" ? "schema" : context
129
+ )
130
+ )
131
+ );
132
+ }
133
+ const node = value;
134
+ const siblings = Object.fromEntries(
135
+ Object.entries(node).filter(
136
+ ([key]) => (typeof node.$ref !== "string" || context === "path-item" || context === "schema" && schemaSiblingsApply) && key !== "$ref-value" && (key !== "$ref" || typeof node.$ref !== "string")
137
+ ).map(([key, entry]) => [
138
+ key,
139
+ visit(
140
+ entry,
141
+ next,
142
+ childContext(context, key, document.swagger === "2.0")
143
+ )
144
+ ])
145
+ );
146
+ if (typeof node.$ref !== "string") {
147
+ return remember(siblings);
148
+ }
149
+ const target = node["$ref-value"];
150
+ if (target === void 0) {
151
+ errors.add(`Could not resolve reference: ${node.$ref}`);
152
+ return remember(siblings);
153
+ }
154
+ const resolved = visit(
155
+ target,
156
+ next,
157
+ context,
158
+ new Set(referenceAncestors).add(raw)
159
+ );
160
+ if (context === "schema" && schemaSiblingsApply) {
161
+ return remember({ allOf: [siblings, resolved] });
162
+ }
163
+ if (context === "path-item" && resolved !== null && typeof resolved === "object" && !Array.isArray(resolved)) {
164
+ return remember({ ...resolved, ...siblings });
165
+ }
166
+ return remember(resolved);
167
+ };
168
+ const result = visit(createMagicProxy(document), /* @__PURE__ */ new Set(), "object");
169
+ if (errors.size) return err([...errors].join("\n"));
170
+ if (!result || typeof result !== "object" || Array.isArray(result)) {
171
+ return err("The resolved document must be an object.");
172
+ }
173
+ return ok(result);
174
+ };
175
+
176
+ // src/domains/document/validate/action.ts
177
+ async function validateAction(inputArgument) {
178
+ const startTime = performance.now();
179
+ if (!inputArgument) {
180
+ return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
181
+ }
182
+ const document = await bundle(
183
+ isUrl(inputArgument) ? inputArgument : path.resolve(inputArgument),
184
+ {
185
+ plugins: [readFiles(), fetchUrls()],
186
+ treeShake: false
187
+ }
188
+ ).catch((error) => {
189
+ return output.error().title("Invalid input").message(error instanceof Error ? error.message : String(error)).exit("error");
190
+ });
191
+ if (!isDocument(document)) {
192
+ return output.error().title("Invalid input").message("Please provide a valid JSON or YAML document.").exit("error");
193
+ }
194
+ const resolved = resolveForValidation(document);
195
+ if (!resolved.ok) {
196
+ return output.error().title("Invalid reference").message(resolved.error).exit("error");
197
+ }
198
+ const isAsyncApi = isAsyncApiDocument(document);
199
+ const specification = isAsyncApi ? "AsyncAPI" : "OpenAPI";
200
+ const initialResult = isAsyncApi ? validateAsyncApi(document) : validateOpenApi(document);
201
+ const result = isAsyncApi || !initialResult.valid ? initialResult : validateOpenApi(resolved.data, { checkPathParameters: true });
202
+ if (result.valid && result.version) {
203
+ const endTime = performance.now();
204
+ output.info().line(
205
+ as.green(
206
+ `Matches the ${specification} specification${as.white(` (${specification} ${as.bold(result.version)})`)}
207
+ `
208
+ )
209
+ ).line(
210
+ `${as.green("File validated")} ${as.grey(
211
+ `in ${as.white(`${as.bold(`${Math.round(endTime - startTime)}`)} ms`)}
212
+ `
213
+ )}`
214
+ ).print();
215
+ } else {
216
+ output.error().message(prettyjson.render(result.errors)).message(
217
+ as.red(
218
+ `File does not match the ${specification} ${result.version ? `${result.version} ` : ""}specification.`
219
+ )
220
+ ).message(
221
+ as.red(
222
+ `${as.bold(
223
+ `${result.errors?.length} error${result.errors && result.errors.length > 1 ? "s" : ""}`
224
+ )} found.`
225
+ )
226
+ ).exit("error");
227
+ }
228
+ }
229
+ export {
230
+ validateAction
231
+ };