swagger-digest 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 swagger-digest contributors
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 CHANGED
@@ -1,3 +1,109 @@
1
- # Temporary Holding Version
1
+ # swagger-digest
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ `swagger-digest` is an interactive Node.js CLI that converts a Swagger UI page or raw OpenAPI/Swagger spec into a compact Markdown reference designed for AI coding agents and LLM context windows.
4
+
5
+ ## Quick start
6
+
7
+ ```bash
8
+ npx swagger-digest
9
+ ```
10
+
11
+ The CLI asks for a URL, a destination directory (Downloads by default), and an output filename such as `payments-api-digest.md`.
12
+
13
+ You can also provide arguments:
14
+
15
+ ```bash
16
+ npx swagger-digest \
17
+ --url https://petstore.swagger.io/ \
18
+ --out-dir ./docs \
19
+ --filename petstore-digest.md
20
+ ```
21
+
22
+ For a direct spec URL:
23
+
24
+ ```bash
25
+ npx swagger-digest --url https://example.com/openapi.yaml --out-dir ./docs
26
+ ```
27
+
28
+ Run `npx swagger-digest --help` for all CLI options. The package requires Node.js 20 or newer.
29
+
30
+ ## What it extracts
31
+
32
+ The retrieval strategy deliberately avoids scraping rendered operation accordions or simulating UI clicks:
33
+
34
+ 1. Fetch and parse a direct `.json`, `.yaml`, or `.yml` URL.
35
+ 2. Fetch the Swagger UI page and inspect script configuration for `url: "..."` or an inline `spec: { ... }` object.
36
+ 3. Try common spec endpoints on the same origin: `/v3/api-docs`, `/swagger/v1/swagger.json`, `/swagger.json`, `/openapi.json`, and `/api-docs`.
37
+ 4. Optionally launch a headless Chromium browser and read the parsed specification from Swagger UI's in-memory state.
38
+
39
+ The first three paths use ordinary HTTP requests. The browser fallback is optional so the normal install stays lightweight. To enable it for a difficult JavaScript-initialized Swagger UI deployment:
40
+
41
+ ```bash
42
+ npm install playwright
43
+ npx playwright install chromium
44
+ ```
45
+
46
+ Then run the CLI again. Use `--no-browser` to disable the fallback.
47
+
48
+ ### Troubleshooting access through a VPN
49
+
50
+ The ordinary HTTP fetches use Node.js networking; they do not automatically reuse a browser's VPN extension, cookies, or signed-in session. If the Swagger page works in Chrome but not in the CLI, first test the same URL from the terminal:
51
+
52
+ ```bash
53
+ curl -v -L 'https://your-host.example/path/to/swagger-ui' -o /tmp/swagger-page.html
54
+ ```
55
+
56
+ If `curl` cannot connect or receives `401`/`403`, connect a system-level VPN that also routes terminal applications, or configure the relevant corporate proxy/authentication for the terminal. Installing Playwright alone does not make a browser-only VPN extension available to its separate Chromium instance. If terminal access succeeds, the extractor now also reads same-origin Swagger UI initializer/config scripts and tries spec paths relative to the supplied page's context path.
57
+
58
+ ## Markdown format
59
+
60
+ The generated document includes:
61
+
62
+ - API title, OpenAPI/Swagger version, API version, base URL(s), and authentication schemes.
63
+ - A compact endpoint index (`Method`, `Path`, `Summary`, and `Tags`).
64
+ - Endpoint details grouped by tag, including auth requirements, path/query/header parameters, request bodies, success/error responses, and JSON example values.
65
+ - TypeScript-like interface/type declarations for schemas reachable from the documented operations, with local `$ref` dependencies expanded as named type references rather than copied JSON Schema trees.
66
+
67
+ OpenAPI 2.0, 3.0, and 3.1 documents are handled through format normalization in the transformer. Schema combinations (`allOf`, `oneOf`, `anyOf`), enums, arrays, nullable fields, and `additionalProperties` receive compact TypeScript-like representations. Unknown or unsupported schema constructs are represented as `unknown` rather than causing the entire digest to fail.
68
+
69
+ ## Development
70
+
71
+ ```bash
72
+ npm install
73
+ npm run build
74
+ npm test
75
+ npm run lint
76
+ npm link
77
+ swagger-digest
78
+ ```
79
+
80
+ Test against the public Petstore UI:
81
+
82
+ ```bash
83
+ npm run build
84
+ node dist/cli.js --url https://petstore.swagger.io/ --out-dir ./tmp --filename petstore-digest.md
85
+ ```
86
+
87
+ The test suite runs locally against fixtures and does not require a network connection. Network-based checks such as the Petstore example depend on that service being reachable from your environment.
88
+
89
+ ## Project layout
90
+
91
+ ```text
92
+ src/
93
+ cli.ts CLI entry point, prompts, options and progress spinners
94
+ fetcher.ts HTTP, HTML configuration parsing and optional browser fallback
95
+ transformer.ts OpenAPI/Swagger to compact Markdown and TypeScript-like types
96
+ writer.ts Output path, filename defaults and file writing
97
+ index.ts Public exports
98
+ ```
99
+
100
+ ## Limitations
101
+
102
+ - The tool downloads specs exposed by the supplied server. It does not bypass authentication, browser access controls, or network restrictions.
103
+ - External schema references are retained as named type references where possible; the tool does not currently fetch and bundle arbitrary external documents.
104
+ - Declared request/response examples are preserved. When an example is absent but a schema exists, a representative JSON example is generated from that schema and clearly marked as illustrative rather than spec-authored. The transformer includes the primary success response and applicable common error responses to balance useful payload context against digest size.
105
+ - A generated digest is a compact developer reference, not a replacement for the source OpenAPI contract.
106
+
107
+ ## License
108
+
109
+ MIT