@quobix/vacuum 0.0.12

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Dave Shanley / Quobix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,269 @@
1
+ ![vacuum logo](logo.png)
2
+
3
+ # vacuum - The world's fastest OpenAPI & Swagger linter.
4
+
5
+ ![Pipeline](https://github.com/daveshanley/vacuum/workflows/vaccum%20pipeline/badge.svg)
6
+ [![codecov](https://codecov.io/gh/daveshanley/vacuum/branch/main/graph/badge.svg?)](https://codecov.io/gh/daveshanley/vacuum)
7
+ [![Go Report Card](https://goreportcard.com/badge/github.com/daveshanley/vacuum)](https://goreportcard.com/report/github.com/daveshanley/vacuum)
8
+
9
+ An **ultra-super-fast**, lightweight OpenAPI linter and quality checking tool, written in golang and inspired by [Spectral](https://github.com/stoplightio/spectral).
10
+
11
+ It's also compatible with existing [Spectral](https://github.com/stoplightio/spectral) rulesets.
12
+
13
+ ## Documentation
14
+
15
+ ### [Quick Start Guide 🚀](https://quobix.com/vacuum/start)
16
+
17
+ See all the documentation at https://quobix.com/vacuum
18
+
19
+ - [Installing vacuum](https://quobix.com/vacuum/installing/)
20
+ - [About vacuum](https://quobix.com/vacuum/about/)
21
+ - [Why should you care?](https://quobix.com/vacuum/why/)
22
+ - [Concepts](https://quobix.com/vacuum/concepts/)
23
+ - [CLI Commands](https://quobix.com/vacuum/cli/)
24
+ - [lint](https://quobix.com/vacuum/cli/lint)
25
+ - [vacuum report](https://quobix.com/vacuum/cli/report)
26
+ - [dashboard](https://quobix.com/vacuum/cli/dashboard)
27
+ - [html-report](https://quobix.com/vacuum/cli/html-report)
28
+ - [spectral-report](https://quobix.com/vacuum/cli/spectral-report)
29
+ - [Developer API](https://quobix.com/vacuum/api/getting-started/)
30
+ - [Using The Index](https://quobix.com/vacuum/api/spec-index/)
31
+ - [RuleResultSet](https://quobix.com/vacuum/api/rule-resultset/)
32
+ - [Loading a RuleSet](https://quobix.com/vacuum/api/loading-ruleset/)
33
+ - [Rules](https://quobix.com/vacuum/rules/)
34
+ - [Examples](https://quobix.com/vacuum/rules/examples/)
35
+ - [Tags](https://quobix.com/vacuum/rules/tags/)
36
+ - [Descriptions](https://quobix.com/vacuum/rules/descriptions/)
37
+ - [Schemas](https://quobix.com/vacuum/rules/schemas/)
38
+ - [Spec Information](https://quobix.com/vacuum/rules/information/)
39
+ - [Operations & Paths](https://quobix.com/vacuum/rules/operations/)
40
+ - [Validation](https://quobix.com/vacuum/rules/validation/)
41
+ - [Security](https://quobix.com/vacuum/rules/security/)
42
+ - [Functions](https://quobix.com/vacuum/functions/)
43
+ - [Core Functions](https://quobix.com/vacuum/functions/core/)
44
+ - [OpenAPI Functions](https://quobix.com/vacuum/functions/openapi/)
45
+ - [Understanding RuleSets](https://quobix.com/vacuum/rulesets/understanding/)
46
+ - [All Rules](https://quobix.com/vacuum/rulesets/all/)
47
+ - [No Rules](https://quobix.com/vacuum/rulesets/no-rules/)
48
+ - [Recommended Rules](https://quobix.com/vacuum/rulesets/recommended/)
49
+ - [Custom Rules](https://quobix.com/vacuum/rulesets/custom-rulesets/)
50
+
51
+
52
+ ---
53
+
54
+ > **vacuum can suck all the lint of a 5mb OpenAPI spec in about 250ms.**
55
+
56
+ Designed to reliably lint OpenAPI specifications, **very, very quickly**. Including _very large_ ones. Spectral can be quite slow
57
+ when used as an API and does not scale for enterprise applications.
58
+
59
+ vacuum will tell you what is wrong with your spec, why, where and how to fix it.
60
+
61
+ vacuum will work at scale and is designed as a CLI (with a UI) and a library to be consumed in other applications.
62
+
63
+ ### Dashboard
64
+
65
+ vacuum comes with an interactive dashboard (`vacuum dashboard <your-openapi-spec.yaml>`) allowing you to explore
66
+ rules and violations in a console, without having to scroll through thousands of results.
67
+
68
+ ![vacuum dashboard](dashboard-screenshot.png)
69
+
70
+ ### HTML Report
71
+
72
+ vacuum can generate an easy to navigate and understand HTML report. Like the dashboard
73
+ you can explore broken rules and violations, but in your browser.
74
+
75
+ No external dependencies, the HTML report will run completely offline.
76
+
77
+ ![vacuum html-report](html-report-screenshot.png)
78
+
79
+ ---
80
+
81
+ If you want to try out vacuum:
82
+
83
+ > Please be warned, this is _early_ code. I am actively working on it.
84
+ >> **_Supports OpenAPI Version 2 (Swagger) and Version 3+_**
85
+
86
+ You can use either **YAML** or **JSON** vacuum supports both.
87
+
88
+ ## Install using [homebrew](https://brew.sh) tap
89
+
90
+ ```
91
+ brew install daveshanley/vacuum/vacuum
92
+ ```
93
+
94
+ > This is the _recommended_ way to consume the binary version of vacuum.
95
+
96
+ ## Check out the code
97
+
98
+ ```
99
+ git clone https://github.com/daveshanley/vacuum.git
100
+ ```
101
+ ### Change directory into `vacuum`
102
+
103
+ ```
104
+ cd vacuum
105
+ ```
106
+
107
+ ## Build the code
108
+
109
+ ```
110
+ go build vacuum.go
111
+ ```
112
+
113
+ ## Run the code
114
+
115
+ ```
116
+ ./vacuum lint <your-openapi-spec.yaml>
117
+ ```
118
+
119
+ ## Running vacuum via Docker
120
+
121
+ vacuum is available as a container, you can pull the image from
122
+ [Docker Hub](https://hub.docker.com/repository/docker/dshanley/vacuum/general)
123
+
124
+ ```
125
+ docker pull dshanley/vacuum
126
+ ```
127
+
128
+ or you can pull it from [Github packages](https://github.com/daveshanley/vacuum/pkgs/container/vacuum).
129
+
130
+ ```
131
+ docker pull ghcr.io/daveshanley/vacuum:latest
132
+ ```
133
+
134
+ To run, just add `docker dshanley/vacuum` as your command, like so
135
+
136
+ ```
137
+ docker dshanley/vacuum lint <your-openapi-spec.yaml>
138
+ ```
139
+
140
+ ---
141
+ > 👉 **Please note, the flags and commands below will change as the experience is refined.** 👈
142
+ ---
143
+
144
+ ## Build an interactive HTML report
145
+
146
+ ```
147
+ ./vacuum html-report <your-openapi-spec.yaml | vacuum-report.json.gz> <report-name.html>
148
+ ```
149
+
150
+ You can replace `report-name.html` with your own choice of filename. Open the report
151
+ in your favorite browser and explore the results.
152
+
153
+
154
+ ## See full linting report
155
+
156
+ ```
157
+ ./vacuum lint -d <your-openapi-spec.yaml>
158
+ ```
159
+
160
+ ## See full linting report with inline code snippets
161
+
162
+ ```
163
+ ./vacuum lint -d -s <your-openapi-spec.yaml>
164
+ ```
165
+
166
+ ## See just the linting errors
167
+
168
+ ```
169
+ ./vacuum lint -d -e <your-openapi-spec.yaml>
170
+ ```
171
+
172
+ ## See just a specific category of report
173
+
174
+
175
+ ```
176
+ ./vacuum lint -d -c schemas <your-openapi-spec.yaml>
177
+ ```
178
+
179
+ The options here are:
180
+
181
+ - `examples`
182
+ - `operations`
183
+ - `information`
184
+ - `descriptions`
185
+ - `schemas`
186
+ - `security`
187
+ - `tags`
188
+ - `validation`
189
+
190
+ ## Generate a Spectral compatible report
191
+
192
+ If you're already using Spectral JSON reports, and you want to use vacuum instead, use the `spectral-report` command
193
+
194
+ ```
195
+ ./vacuum spectral-report <your-openapi-spec.yaml> <report-output-name.json>
196
+ ```
197
+
198
+ The report file name is _optional_. The default report output name is `vacuum-spectral-report.json`
199
+
200
+
201
+ ## Generate a `vacuum report`
202
+
203
+ Vacuum reports are complete snapshots in time of a linting report for a specification. These reports can be 'replayed'
204
+ back through vacuum. Use the `dashboard` or the `html-report` commands to 'replay' the report and explore the results
205
+ as they were when the report was generated.
206
+
207
+ ```
208
+ ./vacuum report -c <your-openapi-spec.yaml> <report-prefix>
209
+ ```
210
+
211
+ The default name of the report will be `vacuum-report-MM-DD-YY-HH_MM_SS.json`. You can change the prefix by supplying
212
+ it as the second argument to the `report` command.
213
+
214
+ Ideally, **you should compress the report using `-c`**. This shrinks down the size significantly. vacuum automatically
215
+ recognizes a compressed report file and will deal with it automatically when reading.
216
+
217
+ > When using compression, the file name will be `vacuum-report-MM-DD-YY-HH_MM_SS.json.gz`. vacuum uses gzip internally.
218
+
219
+ ---
220
+
221
+ ## Try out the dashboard
222
+
223
+ This is an early, but working console UI for vacuum. The code isn't great, it needs a lot of clean up, but
224
+ if you're interested in seeing how things are progressing, it's available.
225
+
226
+ ```
227
+ ./vacuum dashboard <your-openapi-spec.yaml | vacuum-report.json.gz>
228
+ ```
229
+
230
+ ---
231
+ ## Supply your own Spectral ruleset
232
+
233
+ If you're already using Spectral and you have your own [custom ruleset](https://meta.stoplight.io/docs/spectral/e5b9616d6d50c-custom-rulesets#custom-rulesets),
234
+ then you can use it with Vacuum!
235
+
236
+ The `lint`, `dashboard` and `spectral-report` commands all accept a `-r` or `--ruleset` flag, defining the path to your ruleset file.
237
+
238
+ ### Here are some examples you can try
239
+
240
+ **_All rules turned off_**
241
+ ```
242
+ ./vacuum lint -r rulesets/examples/norules-ruleset.yaml <your-openapi-spec.yaml>
243
+ ```
244
+
245
+ **_Only recommended rules_**
246
+ ```
247
+ ./vacuum lint -r rulesets/examples/recommended-ruleset.yaml <your-openapi-spec.yaml>
248
+ ```
249
+
250
+ **_Enable specific rules only_**
251
+ ```
252
+ ./vacuum lint -r rulesets/examples/specific-ruleset.yaml <your-openapi-spec.yaml>
253
+ ```
254
+
255
+ **_Custom rules_**
256
+ ```
257
+ ./vacuum lint -r rulesets/examples/custom-ruleset.yaml <your-openapi-spec.yaml>
258
+ ```
259
+
260
+ **_All rules, all of them!**
261
+ ```
262
+ ./vacuum lint -r rulesets/examples/all-ruleset.yaml <your-openapi-spec.yaml>
263
+ ```
264
+
265
+ ---
266
+
267
+ Let me know what you think.
268
+
269
+ > Logo gopher is modified, originally from [egonelbre](https://github.com/egonelbre/gophers)
package/bin/vacuum.js ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ import { execFileSync } from "child_process";
3
+ import path from "path";
4
+ import { exit } from "process";
5
+ import { fileURLToPath } from "url";
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+
10
+ try {
11
+ execFileSync(path.resolve(`${__dirname}/vacuum`), process.argv.slice(2), {
12
+ stdio: "inherit",
13
+ });
14
+ } catch (e) {
15
+ exit(1)
16
+ }
@@ -0,0 +1,15 @@
1
+ export const CONFIG = {
2
+ name: "vacuum",
3
+ path: "./bin",
4
+ url: "https://github.com/daveshanley/vacuum/releases/download/v{{version}}/{{bin_name}}_{{version}}_{{platform}}_{{arch}}.tar.gz",
5
+ };
6
+ export const ARCH_MAPPING = {
7
+ ia32: "386",
8
+ x64: "amd64",
9
+ arm64: "arm64",
10
+ };
11
+ export const PLATFORM_MAPPING = {
12
+ darwin: "darwin",
13
+ linux: "linux",
14
+ win32: "windows",
15
+ };
@@ -0,0 +1,55 @@
1
+ import { createWriteStream } from "fs";
2
+ import * as fs from "fs/promises";
3
+ import fetch from "node-fetch";
4
+ import { pipeline } from "stream/promises";
5
+ import tar from "tar";
6
+ import { execSync } from "child_process";
7
+
8
+ import { ARCH_MAPPING, CONFIG, PLATFORM_MAPPING } from "./config.js";
9
+
10
+ async function install() {
11
+ if (process.platform === "android") {
12
+ console.log("Installing, may take a moment...");
13
+ const cmd =
14
+ "pkg upgrade && pkg install golang git -y && git clone https://github.com/daveshanley/vacuum.git && cd cli/ && go build -o $PREFIX/bin/vacuum";
15
+ execSync(cmd, { encoding: "utf-8" });
16
+ console.log("Installation successful!");
17
+ return;
18
+ }
19
+ const packageJson = await fs.readFile("package.json").then(JSON.parse);
20
+ let version = packageJson.version;
21
+
22
+ if (typeof version !== "string") {
23
+ throw new Error("Missing version in package.json");
24
+ }
25
+
26
+ if (version[0] === "v") version = version.slice(1);
27
+
28
+ let { name: binName, path: binPath, url } = CONFIG;
29
+
30
+ url = url.replace(/{{arch}}/g, ARCH_MAPPING[process.arch]);
31
+ url = url.replace(/{{platform}}/g, PLATFORM_MAPPING[process.platform]);
32
+ url = url.replace(/{{version}}/g, version);
33
+ url = url.replace(/{{bin_name}}/g, binName);
34
+
35
+ const response = await fetch(url);
36
+ if (!response.ok) {
37
+ throw new Error("Failed fetching the binary: " + response.statusText);
38
+ }
39
+
40
+ const tarFile = "downloaded.tar.gz";
41
+
42
+ await fs.mkdir(binPath, { recursive: true });
43
+ await pipeline(response.body, createWriteStream(tarFile));
44
+ await tar.x({ file: tarFile, cwd: binPath });
45
+ await fs.rm(tarFile);
46
+ }
47
+
48
+ install()
49
+ .then(async () => {
50
+ process.exit(0);
51
+ })
52
+ .catch(async (err) => {
53
+ console.error(err);
54
+ process.exit(1);
55
+ });
package/package.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "name": "@quobix/vacuum",
3
+ "version": "0.0.12",
4
+ "description": "The world's fastest, most scalable and complete OpenAPI parser",
5
+ "type": "module",
6
+ "author": "Dave Shanley",
7
+ "license": "MIT",
8
+ "homepage": "https://quobix.com/vacuum",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/daveshanley/vacuum.git"
12
+ },
13
+ "engines": {
14
+ "node": ">=16.0.0"
15
+ },
16
+ "scripts": {
17
+ "postinstall": "node ./npm-install/postinstall.js"
18
+ },
19
+ "bin": {
20
+ "vacuum": "bin/vacuum.js"
21
+ },
22
+ "files": [
23
+ "npm-install"
24
+ ],
25
+ "dependencies": {
26
+ "node-fetch": "^3.1.0",
27
+ "tar": "^6.1.11",
28
+ "vacuum": "^0.1.3"
29
+ },
30
+ "bugs": {
31
+ "url": "https://github.com/daveshanley/vacuum/issues"
32
+ },
33
+ "main": "index.js"
34
+ }