@scalar/cli 2.5.2 → 2.8.0

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 (79) hide show
  1. package/README.md +319 -55
  2. package/chunks/{action-XUQ7TKKJ.js → action-354TUG4H.js} +11 -7
  3. package/chunks/{action-PHLOE27S.js → action-43YBNBDR.js} +33 -26
  4. package/chunks/{action-DGD6Q6Y5.js → action-5SK5NE7E.js} +10 -4
  5. package/chunks/{action-Y6CEKYEK.js → action-6BYGBXRC.js} +40 -23
  6. package/chunks/{action-LUVBQEIQ.js → action-7PEQXDWT.js} +4 -4
  7. package/chunks/action-AQRPFQKI.js +231 -0
  8. package/chunks/{action-RBVPKCRI.js → action-CA4QYPI6.js} +6 -6
  9. package/chunks/{action-7H3XARJP.js → action-EOAVVL52.js} +11 -5
  10. package/chunks/action-F2ZJNURT.js +72 -0
  11. package/chunks/{action-AMNYOA4B.js → action-F7A2K74G.js} +4 -4
  12. package/chunks/{action-HIL5ZFNB.js → action-FCAYFPVR.js} +5 -5
  13. package/chunks/{action-42D2C47G.js → action-GWXLHL2Z.js} +3 -3
  14. package/chunks/{action-ZWQLQENM.js → action-H6OUJWWM.js} +4 -4
  15. package/chunks/{action-TWHLZW4V.js → action-HT2DJ34Z.js} +49 -26
  16. package/chunks/{action-PAA4NWUJ.js → action-JAHFRYWZ.js} +58 -9
  17. package/chunks/{action-HXHBU7XC.js → action-KTYOCA2V.js} +37 -12
  18. package/chunks/{action-LFL3ZZKN.js → action-LEUD5P2U.js} +17 -17
  19. package/chunks/{action-FF2OMGAS.js → action-LLH4QPXM.js} +34 -20
  20. package/chunks/{action-OILGZAMK.js → action-LXGXKXZZ.js} +20 -15
  21. package/chunks/{action-W62AIEBN.js → action-NVI5DWFP.js} +6 -6
  22. package/chunks/{action-EPNE5XCM.js → action-QQZLPI42.js} +17 -17
  23. package/chunks/{action-ZLTUMRO2.js → action-UIKH4SZX.js} +25 -21
  24. package/chunks/{action-6FAJNP6C.js → action-VOFDW3U2.js} +4 -4
  25. package/chunks/{action-OK55BFGM.js → action-W3C53GPH.js} +7 -7
  26. package/chunks/{action-P7RFXIC7.js → action-WFDNRA7D.js} +32 -23
  27. package/chunks/{action-V5KYG7XD.js → action-XIUO64C7.js} +10 -10
  28. package/chunks/{action-X7TZA3RE.js → action-Y6NXJQ4H.js} +89 -14
  29. package/chunks/{action-6MZZHPVQ.js → action-Y7OUGD56.js} +27 -14
  30. package/chunks/{action-DCINFQ57.js → action-YLF2G4G5.js} +13 -13
  31. package/chunks/{action-SJYAMXYI.js → action-YRX6SN5F.js} +10 -4
  32. package/chunks/actions-OGIVBQC7.js +158 -0
  33. package/chunks/{agent-JAXLLDPE.js → agent-ASPV3R5U.js} +4 -4
  34. package/chunks/{asyncapi-P6Y3L7RG.js → asyncapi-QNFKXHEI.js} +10 -11
  35. package/chunks/{build.action-AZ5ECU4B.js → build.action-NM6CAE5F.js} +37 -33
  36. package/chunks/{chunk-FOKFF4EP.js → chunk-22HYZ7LE.js} +3 -3
  37. package/chunks/{chunk-KEOCJ3NJ.js → chunk-2OCWX42S.js} +38 -87
  38. package/chunks/{chunk-RPVHJMQT.js → chunk-5DEU2DVL.js} +2 -2
  39. package/chunks/{chunk-OQKDBLOZ.js → chunk-5JLVQVKO.js} +8 -0
  40. package/chunks/{chunk-VNYE4R7N.js → chunk-5UHLAJQD.js} +2 -1
  41. package/chunks/{chunk-CX7ZRMTC.js → chunk-6XWCMJDB.js} +1 -1
  42. package/chunks/{chunk-6ZMT63IV.js → chunk-6YPQGVF4.js} +1 -1
  43. package/chunks/{chunk-HXIDUCSZ.js → chunk-BPGFSSUH.js} +1 -1
  44. package/chunks/{chunk-M622VXRQ.js → chunk-C2KAWRIX.js} +1 -1
  45. package/chunks/chunk-EGOXR5FB.js +15 -0
  46. package/chunks/{chunk-UB3XGOUW.js → chunk-EXY3ZTV4.js} +262 -9
  47. package/chunks/{chunk-3BWGTPPT.js → chunk-FDC2IESH.js} +1776 -1113
  48. package/chunks/{chunk-TYLWJ2UL.js → chunk-GTV2BVXV.js} +2 -2
  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-MNLXYOVF.js → chunk-KCCFN4F7.js} +2 -2
  52. package/chunks/{chunk-FQVVKQPU.js → chunk-KKRGBXCE.js} +137 -1
  53. package/chunks/{chunk-UMPODUJO.js → chunk-L3UXDCBI.js} +105 -15
  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-RAO7VUGM.js → chunk-PH3WFNXJ.js} +1 -1
  57. package/chunks/{chunk-NIXG4KDE.js → chunk-QVQ4PNVL.js} +170 -5
  58. package/chunks/{chunk-CIFOFSZ3.js → chunk-R5LK6VPY.js} +72 -7
  59. package/chunks/{chunk-T7B6WNZC.js → chunk-TSURUX4A.js} +12 -3
  60. package/chunks/{chunk-JV7TUEXQ.js → chunk-UXJ753NV.js} +14 -1
  61. package/chunks/{chunk-HUCR333E.js → chunk-W24BETFG.js} +2 -2
  62. package/chunks/{chunk-LQN4S62O.js → chunk-XEDGMZJD.js} +18 -4
  63. package/chunks/{chunk-NNMSZVAB.js → chunk-XXSQUBXS.js} +82 -6
  64. package/chunks/{chunk-M6Q3ARBV.js → chunk-YILQODZF.js} +2 -2
  65. package/chunks/{create.action-34OTO2SB.js → create.action-FUQ2BVJA.js} +29 -17
  66. package/chunks/{delete.action-ZYXFMIOW.js → delete.action-47E66R3I.js} +26 -17
  67. package/chunks/{delete.action-6LRT4M3S.js → delete.action-BTDFH7WY.js} +26 -17
  68. package/chunks/{get.action-XP36SA2J.js → get.action-XC7KC2JO.js} +10 -10
  69. package/chunks/{list.action-6LF6KSD5.js → list.action-LXKEUYKO.js} +13 -13
  70. package/chunks/{list.action-WVRVLX5E.js → list.action-OFGLMRE7.js} +17 -17
  71. package/chunks/{publish.action-AHFUBT5C.js → publish.action-OS27XOX4.js} +50 -24
  72. package/chunks/{update.action-YQTVUDYE.js → update.action-AEIBLCWD.js} +27 -18
  73. package/chunks/{update.action-ZREAFJVG.js → update.action-ZMS4CQ3T.js} +27 -18
  74. package/docs.html +679 -175
  75. package/index.js +492 -406
  76. package/package.json +14 -22
  77. package/skills/scalar-cli/SKILL.md +77 -0
  78. package/template.md +101 -3
  79. package/chunks/action-YRWHX2AE.js +0 -64
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "engines": {
6
6
  "node": ">=24"
7
7
  },
8
- "version": "2.5.2",
8
+ "version": "2.8.0",
9
9
  "keywords": [
10
10
  "scalar",
11
11
  "openapi",
@@ -20,23 +20,19 @@
20
20
  "main": "./index.js",
21
21
  "dependencies": {
22
22
  "@clack/prompts": "0.7.0",
23
- "@fastify/static": "10.1.4",
24
- "@hono/node-server": "2.0.1",
23
+ "@hono/node-server": "2.1.1",
25
24
  "@quobix/vacuum": "0.30.1",
26
- "@scalar/asyncapi-upgrader": "0.1.10",
27
- "@scalar/asyncapi-validator": "0.1.2",
28
- "@scalar/json-magic": "0.14.0",
29
- "@scalar/mock-server": "0.14.2",
30
- "@scalar/oas-utils": "0.20.1",
31
- "@scalar/openapi-parser": "0.29.3",
32
- "@scalar/openapi-to-markdown": "1.0.0",
33
- "@scalar/openapi-types": "0.9.6",
34
- "@scalar/openapi-upgrader": "0.2.17",
35
- "@scalar/openapi-validator": "0.1.2",
36
- "@scalar/postman-to-openapi": "0.7.20",
37
- "@scalar/themes": "0.18.0",
38
- "@scalar/void-server": "2.5.10",
39
- "@scalar/workspace-store": "0.62.0",
25
+ "@scalar/asyncapi-upgrader": "0.1.13",
26
+ "@scalar/asyncapi-validator": "0.1.6",
27
+ "@scalar/json-magic": "0.15.2",
28
+ "@scalar/mock-server": "0.17.0",
29
+ "@scalar/openapi-parser": "0.29.7",
30
+ "@scalar/openapi-to-markdown": "1.3.0",
31
+ "@scalar/openapi-upgrader": "0.4.0",
32
+ "@scalar/openapi-validator": "0.1.6",
33
+ "@scalar/postman-to-openapi": "0.7.23",
34
+ "@scalar/void-server": "2.5.13",
35
+ "@scalar/workspace-store": "0.67.0",
40
36
  "@stoplight/spectral-core": "1.22.0",
41
37
  "@stoplight/spectral-ruleset-bundler": "1.7.0",
42
38
  "@stoplight/spectral-rulesets": "1.22.1",
@@ -44,8 +40,6 @@
44
40
  "chokidar": "4.0.3",
45
41
  "commander": "13.1.0",
46
42
  "console-table-printer": "2.16.1",
47
- "esbuild": "0.28.1",
48
- "fastify": "5.8.5",
49
43
  "get-port": "7.2.0",
50
44
  "hono": "^4.12.25",
51
45
  "ignore": "7.0.5",
@@ -55,9 +49,7 @@
55
49
  "prettyjson": "1.2.5",
56
50
  "semver": "7.6.3",
57
51
  "stdout-update": "4.0.1",
58
- "tailwindcss": "4.1.18",
59
52
  "tar-fs": "3.1.2",
60
- "undici": "8.10.2",
61
- "vite": "8.0.16"
53
+ "undici": "8.10.2"
62
54
  }
63
55
  }
@@ -0,0 +1,77 @@
1
+ ---
2
+ name: scalar-cli
3
+ description: "Operate the Scalar CLI (`scalar`, or `npx @scalar/cli`) to validate, lint, format, bundle, split, upgrade, mock, and preview OpenAPI documents, and to publish API references, docs projects, registry entries, schemas, and SDKs to Scalar. Use when a task involves the Scalar CLI or working with OpenAPI documents through Scalar."
4
+ ---
5
+
6
+ # Scalar CLI
7
+
8
+ CLI to work with your OpenAPI files (`@scalar/cli` 2.8.0).
9
+
10
+ ## Operating notes
11
+
12
+ - Run `scalar <command>` when the CLI is installed, or `npx @scalar/cli <command>` when it is not.
13
+ - Run `scalar context` for this command tree as JSON, or `scalar <command> --help` for a single command.
14
+ - Authenticate with a personal token: `scalar auth login --token <token>`, or set `SCALAR_API_KEY` and run `scalar auth login`. Both store the session on disk for later commands. Without a token, `scalar auth login` opens a browser and waits for a person to sign in, so do not run it that way. Check the session with `scalar auth whoami`.
15
+ - Many commands prompt when a value is left out, such as a slug, a team, or a confirmation before overwriting a file, and a prompt blocks a non-interactive run. Pass every value as an argument or flag: for example `--output` on `document bundle` and `document upgrade`, `--yes` on `project rollback`, and `--force` on `project init`.
16
+ - Results go to stdout. Errors go to stderr, prefixed with `[ERROR]`.
17
+
18
+ ## Exit codes
19
+
20
+ - `0`: Success
21
+ - `1`: Failure, including invalid arguments or options. The reason is printed to stderr.
22
+
23
+ ## Commands
24
+
25
+ Run `scalar context` for the arguments, options, defaults, and choices of each command.
26
+
27
+ - `scalar readme [options] [command]`: Open documentation for the CLI
28
+ - `scalar readme generate [options]`: Self generate documentation for the cli
29
+ - `scalar upgrade [options]`: Upgrade current version of your cli
30
+ - `scalar context [options]`: Print every command, argument, and option as JSON for AI agents
31
+ - `scalar auth login [options]`: Login to scalar
32
+ - `scalar auth whoami [options]`: Display the current user
33
+ - `scalar auth logout [options]`: Logout from scalar
34
+ - `scalar access-group create [options] <slug>`: Create an access group (Pro or above)
35
+ - `scalar access-group get [options] <slug>`: Get an access group and its allowlists
36
+ - `scalar access-group update [options] <slug>`: Update access group metadata
37
+ - `scalar access-group delete [options] <slug>`: Delete an access group and remove its project assignments
38
+ - `scalar access-group domain add [options] <slug> <domain>`: Add an exact email domain to an access group
39
+ - `scalar access-group domain remove [options] <slug> <domain>`: Remove an exact email domain from an access group
40
+ - `scalar document bundle [options] [file|url]`: Bundle an OpenAPI document by resolving all references and external dependencies
41
+ - `scalar document split [options] [file|url]`: Split OpenAPI or AsyncAPI documents into small chunks
42
+ - `scalar document join [options] <files...>`: Merge multiple OpenAPI or AsyncAPI documents into a single unified document
43
+ - `scalar document format [options] [file|url]`: Format an OpenAPI or AsyncAPI file
44
+ - `scalar document convert [options] [file|url]`: Convert a Postman collection to an OpenAPI document
45
+ - `scalar document markdown [options] [file|url]`: Generate Markdown from an OpenAPI file
46
+ - `scalar document mock [options] [file|url]`: Mock an OpenAPI API or AsyncAPI WebSocket and SSE channels
47
+ - `scalar document serve [options] [file|url]`: Serve an API Reference from an OpenAPI or AsyncAPI file
48
+ - `scalar document share [options] [file]`: Share an OpenAPI or AsyncAPI file
49
+ - `scalar document validate [options] [file|url]`: Validate an OpenAPI or AsyncAPI file
50
+ - `scalar document void [options]`: Boot a server to mirror HTTP requests
51
+ - `scalar document lint [options] [file|url]`: Lint your OpenAPI or AsyncAPI file using spectral rules
52
+ - `scalar document upgrade [options] [file|url]`: Upgrade an OpenAPI or AsyncAPI document to version 3.1
53
+ - `scalar project init [options]`: Create a new Scalar Docs project.
54
+ - `scalar project check-config [options] [file]`: Check a Scalar Configuration file
55
+ - `scalar project create [options]`: Create a new project that is not linked to a github project.
56
+ - `scalar project preview [options] [config]`: Preview scalar guides
57
+ - `scalar project publish [options]`: Publish new build for a github sync project that is not linked.
58
+ - `scalar project rollback [options]`: Roll the live deployment back to a previously deployed build.
59
+ - `scalar project deployments list [options]`: List the production deployment history for a project.
60
+ - `scalar project upgrade [options] [config]`: Upgrade scalar project
61
+ - `scalar registry publish [options] [file]`: Publish an OpenAPI document to the Scalar registry
62
+ - `scalar registry update [options] [namespace] [slug]`: Update document metadata on scalar registry
63
+ - `scalar registry delete [options] [namespace] [slug]`: Delete a document from scalar registry
64
+ - `scalar registry list [options]`: List all registry APIs for a team namespace
65
+ - `scalar registry get [options] [namespace] [slug]`: Get a document version from scalar registry
66
+ - `scalar team list [options]`: List all teams current user is part of
67
+ - `scalar team set [options]`: Set current active team for the user
68
+ - `scalar sdk list [options]`: List all SDKs for a team namespace
69
+ - `scalar sdk create [options]`: Create a new SDK. The SDK is created in the namespace of the API it is built from.
70
+ - `scalar sdk update [options]`: Update SDK metadata.
71
+ - `scalar sdk delete [options]`: Delete an SDK.
72
+ - `scalar sdk build [options]`: Build an SDK.
73
+ - `scalar schema delete [options]`: Delete a schema.
74
+ - `scalar schema update [options]`: Update schema metadata.
75
+ - `scalar schema list [options]`: List all schemas for a team namespace
76
+ - `scalar schema get [options] [namespace] [slug]`: Get a schema document version from the Scalar registry
77
+ - `scalar schema publish [options] [file]`: Publish a shared schema to the Scalar registry
package/template.md CHANGED
@@ -15,6 +15,26 @@ Command-line interface to work with OpenAPI files
15
15
  - Preview your API reference
16
16
  - Bundle multiple OpenAPI files
17
17
 
18
+ ## Access groups
19
+
20
+ Manage access groups and allowed email domains for your current team:
21
+
22
+ ```bash
23
+ scalar auth login
24
+ scalar access-group create partners --name Partners --domain example.com
25
+ scalar access-group get partners --json
26
+ scalar access-group update partners --name "Partner access"
27
+ scalar access-group domain add partners partner.com
28
+ scalar access-group domain remove partners partner.com
29
+ scalar access-group delete partners --yes
30
+ ```
31
+
32
+ Creation requires Pro or above, and mutations require docs edit permission. Commands use your existing login and selected team; CI can authenticate with `scalar auth login --token <personal-token>`. Group arguments are slugs, not UIDs. Rename with `update <slug> --new-slug <new-slug>`, then use the new slug in later commands.
33
+
34
+ Use `--json` for machine-readable output: create/get print the group object, while successful updates, deletions and domain mutations print `null`. Errors go to stderr and exit nonzero. Deletion prompts in a terminal; pass `--yes` for unattended deletion or when using `--json`.
35
+
36
+ Domains are exact email domains, with no wildcards or implicit subdomain matching. Matching preserves existing case-sensitive behavior. Groups support up to 1,000 domains; domain add/remove leaves other domains and individual email entries intact. Creating a group does not assign it to resources or change their privacy settings. Deleting a group removes its project assignments.
37
+
18
38
  ## Documentation
19
39
 
20
40
  This is an overview + API Reference of the CLI, if you want guides on how to use the CLI in more detail go to our [Docs](https://guides.scalar.com/scalar/scalar-cli)
@@ -27,7 +47,31 @@ npx @scalar/cli help
27
47
 
28
48
  ## Installation
29
49
 
30
- If you really want to become friends you should install the CLI:
50
+ ### Standalone CLI (no Node.js required)
51
+
52
+ Install the latest stable release without Node.js, npm, or administrator access.
53
+
54
+ macOS and Linux (Bash):
55
+
56
+ ```bash
57
+ curl -fsSL https://cdn.scalar.com/cli/install.sh | bash
58
+ ```
59
+
60
+ Windows (PowerShell):
61
+
62
+ ```powershell
63
+ irm https://cdn.scalar.com/cli/install.ps1 | iex
64
+ ```
65
+
66
+ 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.
67
+
68
+ 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.
69
+
70
+ 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.
71
+
72
+ ### npm
73
+
74
+ If you already use Node.js, install the CLI with npm:
31
75
 
32
76
  ```bash
33
77
  npm -g install @scalar/cli
@@ -53,10 +97,61 @@ npx @scalar/cli help
53
97
  pnpm dlx @scalar/cli help
54
98
  ```
55
99
 
100
+ ## API Reference configuration
101
+
102
+ Pass API Reference options as a JSON object:
103
+
104
+ ```sh
105
+ scalar document serve openapi.yaml --config ./reference.config.json
106
+ ```
107
+
108
+ ```json
109
+ {
110
+ "orderRequiredPropertiesFirst": false,
111
+ "theme": "purple"
112
+ }
113
+ ```
114
+
115
+ The configuration path is relative to the current working directory. Configuration
116
+ is loaded at startup; restart the command after changing it. `--watch` continues
117
+ to watch the API document. Options requiring JavaScript functions are not supported
118
+ in a JSON file.
119
+
120
+ ## Authentication in automation
121
+
122
+ Use `scalar auth login --token <personal-token>` to authenticate without a browser.
123
+ Alternatively, set `SCALAR_API_KEY`. When both are provided, `SCALAR_API_KEY` takes
124
+ precedence over `--token`. Unset it to use a different explicit token.
125
+
126
+ Supply required options in automation instead of relying on interactive prompts.
127
+ For example, pass `--output` for document transformations.
128
+
56
129
  ## Commands
57
130
 
58
131
  <COMMANDS>
59
132
 
133
+ ## AI agents
134
+
135
+ `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`:
136
+
137
+ ```bash
138
+ scalar context
139
+ ```
140
+
141
+ 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:
142
+
143
+ ```bash
144
+ mkdir -p .claude/skills
145
+
146
+ # npm (global install)
147
+ cp -r "$(npm root -g)/@scalar/cli/skills/scalar-cli" .claude/skills/
148
+
149
+ # Standalone CLI on macOS or Linux (the installer links `scalar` into its release directory)
150
+ cp -r "$(dirname "$(readlink "$(command -v scalar)")")/app/skills/scalar-cli" .claude/skills/
151
+ ```
152
+
153
+ With the standalone CLI on Windows, the skill is in `%LOCALAPPDATA%\Scalar\current\app\skills\scalar-cli`.
154
+
60
155
  ## GitHub Actions
61
156
 
62
157
  To validate your OpenAPI file in GitHub Actions, add this workflow:
@@ -85,8 +180,7 @@ jobs:
85
180
  node-version: 24
86
181
  - name: Validate OpenAPI File
87
182
  # Replace `./my-openapi-file.yaml` with the correct path and filename for your project.
88
- # Or: run `npx @scalar/cli init` and add the config file to your repository.
89
- run: npx @scalar/cli validate ./my-openapi-file.yaml
183
+ run: npx @scalar/cli document validate ./my-openapi-file.yaml
90
184
  ```
91
185
 
92
186
  ## Development
@@ -105,6 +199,10 @@ pnpm cli:link
105
199
  scalar --version
106
200
  ```
107
201
 
202
+ ### Docs preview from a local build
203
+
204
+ `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).
205
+
108
206
  ## Community
109
207
 
110
208
  We are API nerds. You too? Let’s chat on Discord: <https://discord.gg/scalar>
@@ -1,64 +0,0 @@
1
- import { createRequire as $$cR } from "node:module"; const require = $$cR(import.meta.url);
2
- import {
3
- isAsyncApiDocument
4
- } from "./chunk-SWWWYWHC.js";
5
- import "./chunk-MNLXYOVF.js";
6
- import "./chunk-CX7ZRMTC.js";
7
- import "./chunk-4ORL4MST.js";
8
- import {
9
- output
10
- } from "./chunk-T5HJUAWB.js";
11
- import "./chunk-LQN4S62O.js";
12
- import "./chunk-IKT5F47M.js";
13
- import "./chunk-3MZYUBJ6.js";
14
-
15
- // src/domains/document/validate/action.ts
16
- import as from "ansis";
17
- import prettyjson from "prettyjson";
18
- import { validate as validateAsyncApi } from "@scalar/asyncapi-validator";
19
- import { bundle } from "@scalar/json-magic/bundle";
20
- import { fetchUrls, readFiles } from "@scalar/json-magic/bundle/plugins/node";
21
- import { validate as validateOpenApi } from "@scalar/openapi-validator";
22
- async function validateAction(inputArgument) {
23
- const startTime = performance.now();
24
- if (!inputArgument) {
25
- return output.error().title("Invalid argument").message("Please provide a file path").exit("error");
26
- }
27
- const document = await bundle(inputArgument, {
28
- plugins: [readFiles(), fetchUrls()],
29
- treeShake: false,
30
- depth: -1
31
- });
32
- const isAsyncApi = isAsyncApiDocument(document);
33
- const specification = isAsyncApi ? "AsyncAPI" : "OpenAPI";
34
- const result = isAsyncApi ? validateAsyncApi(document) : validateOpenApi(document);
35
- if (result.valid && result.version) {
36
- const endTime = performance.now();
37
- output.info().line(
38
- as.green(
39
- `Matches the ${specification} specification${as.white(` (${specification} ${as.bold(result.version)})`)}
40
- `
41
- )
42
- ).line(
43
- `${as.green("File validated")} ${as.grey(
44
- `in ${as.white(`${as.bold(`${Math.round(endTime - startTime)}`)} ms`)}
45
- `
46
- )}`
47
- ).print();
48
- } else {
49
- output.error().message(prettyjson.render(result.errors)).message(
50
- as.red(
51
- `File does not match the ${specification} ${result.version ? `${result.version} ` : ""}specification.`
52
- )
53
- ).message(
54
- as.red(
55
- `${as.bold(
56
- `${result.errors?.length} error${result.errors && result.errors.length > 1 ? "s" : ""}`
57
- )} found.`
58
- )
59
- ).exit("error");
60
- }
61
- }
62
- export {
63
- validateAction
64
- };