openapi-to-xlsx 1.0.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.
- package/LICENSE +672 -0
- package/README.md +141 -0
- package/exporter.js +658 -0
- package/package.json +36 -0
package/README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
# OpenAPI to XLSX (Swagger Exporter)
|
|
2
|
+
|
|
3
|
+
A robust Node.js-based CLI utility that converts OpenAPI 3.x and Swagger 2.0 specifications into elegant, professionally styled, and fully hyperlinked Excel workbooks (`.xlsx`).
|
|
4
|
+
|
|
5
|
+
Whether you provide a local JSON/YAML file, a direct remote spec URL, or a Swagger UI webpage URL, the tool automatically resolves, parses, and exports a comprehensive API catalog.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🌟 Key Features
|
|
10
|
+
|
|
11
|
+
1. **Flexible Source Ingestion**:
|
|
12
|
+
- Parses local OpenAPI/Swagger files in both **JSON** and **YAML** formats.
|
|
13
|
+
- Fetches remote spec URLs.
|
|
14
|
+
- **Automated Swagger UI HTML Extraction**: Accepts a Swagger UI URL directly (e.g., `https://petstore.swagger.io/`). It automatically extracts the underlying specification URL by parsing the HTML, `swagger-initializer.js`, or the `swagger-config` endpoints.
|
|
15
|
+
2. **Interactive API Directory (`API List` Sheet)**:
|
|
16
|
+
- Generates a consolidated table of all API endpoints featuring HTTP methods, tags, summaries, and Operation IDs.
|
|
17
|
+
- Distinct HTTP method branding (GET in green, POST in blue, PUT in orange, PATCH in purple, DELETE in red) for rapid visual scanning.
|
|
18
|
+
- Embeds "Open" hyperlinks for instant jumping to the dedicated dedicated detailed worksheet.
|
|
19
|
+
3. **Granular Detail Sheets**:
|
|
20
|
+
- Generates an isolated worksheet for each API operation (names sanitized and truncated to meet the Excel 31-character limit).
|
|
21
|
+
- Includes full metadata: Method, Endpoint, Category, Operation ID, Summary, Description, Deprecated status, Security schemes, and Parameters.
|
|
22
|
+
- **Semantic Response Styling**: Color-codes API response documents and simulated payload examples based on HTTP status codes (2xx Success in green, 4xx Client Error in orange, 5xx Server Error in red).
|
|
23
|
+
- Back-navigation hyperlinks (`<< Back to API List`) at the bottom of every sheet.
|
|
24
|
+
4. **Robust Schema Resolution & Mocking**:
|
|
25
|
+
- Powered by `@apidevtools/swagger-parser` to handle complex schema dereferencing and circular dependencies.
|
|
26
|
+
- Dynamically generates representative mock JSON payloads for both requests and responses based on schema rules.
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## ⚙️ System Requirements
|
|
31
|
+
|
|
32
|
+
* **Node.js**: `v18` or higher.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## 📦 Installation
|
|
37
|
+
|
|
38
|
+
1. Clone or download this repository.
|
|
39
|
+
2. In the root directory of the project, run:
|
|
40
|
+
```bash
|
|
41
|
+
npm install
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## 🚀 Usage
|
|
47
|
+
|
|
48
|
+
Execute the tool directly with Node.js or run it via the pre-configured npm scripts.
|
|
49
|
+
|
|
50
|
+
### CLI Options
|
|
51
|
+
|
|
52
|
+
| Option | Description | Required | Default |
|
|
53
|
+
| :--- | :--- | :---: | :--- |
|
|
54
|
+
| `--url <url>` | Path to a local JSON/YAML file, a direct OpenAPI URL, or a Swagger UI webpage URL. | **Yes** | - |
|
|
55
|
+
| `--token <bearer>` | Bearer token to include in the Authorization header when fetching from a remote URL. | No | - |
|
|
56
|
+
| `--out <file>` | Custom file path for the output `.xlsx` file. | No | `archived/<api-title>-<version>.xlsx` |
|
|
57
|
+
| `--insecure` | Bypass TLS/SSL certificate validation (useful for self-signed development servers). | No | `false` |
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### 💻 Execution Examples
|
|
62
|
+
|
|
63
|
+
#### 1. Parse a Local OpenAPI YAML or JSON File
|
|
64
|
+
```bash
|
|
65
|
+
node exporter.js --url ./ly-v2-spec.yaml
|
|
66
|
+
```
|
|
67
|
+
*This exports the parsed workbook to the `archived/` directory by default, named after the API title.*
|
|
68
|
+
|
|
69
|
+
#### 2. Convert a Remote OpenAPI JSON/YAML Specification
|
|
70
|
+
```bash
|
|
71
|
+
node exporter.js --url https://petstore.swagger.io/v2/swagger.json
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### 3. Parse a Swagger UI Webpage URL Directly
|
|
75
|
+
```bash
|
|
76
|
+
node exporter.js --url https://petstore.swagger.io/
|
|
77
|
+
```
|
|
78
|
+
*The utility fetches the webpage HTML, dynamically extracts the spec URL from the UI bundle setup, downloads the schema, and executes the build.*
|
|
79
|
+
|
|
80
|
+
#### 4. Specify a Custom Output Path
|
|
81
|
+
```bash
|
|
82
|
+
node exporter.js --url ./ly-v2-spec.json --out ./exports/my_api_document.xlsx
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
#### 5. Authenticate via Bearer Token
|
|
86
|
+
For secured Swagger endpoints requiring authorization:
|
|
87
|
+
```bash
|
|
88
|
+
node exporter.js --url https://api.example.com/swagger/v1/swagger.json --token "your_bearer_token_here"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
#### 6. Skip SSL Verification (Self-Signed Certificates)
|
|
92
|
+
```bash
|
|
93
|
+
node exporter.js --url https://dev-server/swagger/v1/swagger.json --insecure
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### 7. Execute via npm Scripts
|
|
97
|
+
You can pass arguments to the npm script using the `--` separator:
|
|
98
|
+
```bash
|
|
99
|
+
npm run gen -- --url ./ly-v2-spec.yaml
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
## 📊 Excel Output Structure
|
|
105
|
+
|
|
106
|
+
### 1. The `API List` Sheet (Index)
|
|
107
|
+
* **No.**: Auto-incremented sequence number.
|
|
108
|
+
* **Method**: Styled badge representing the HTTP verb:
|
|
109
|
+
* **GET** (Green text on light green background)
|
|
110
|
+
* **POST** (Blue text on light blue background)
|
|
111
|
+
* **PUT** (Orange text on light orange background)
|
|
112
|
+
* **PATCH** (Purple text on light purple background)
|
|
113
|
+
* **DELETE** (Red text on light red background)
|
|
114
|
+
* **API Endpoint**: The endpoint path, styled with a monospaced `Consolas` font.
|
|
115
|
+
* **Category**: Category label derived from OpenAPI tags.
|
|
116
|
+
* **Summary**: Short description of the operation (styled with a strikethrough and gray text if the API is marked as `deprecated`).
|
|
117
|
+
* **Operation ID**: The unique API operation identifier.
|
|
118
|
+
* **Detail**: An interactive `Open` hyperlink that jumps directly to the operation's detailed sheet.
|
|
119
|
+
|
|
120
|
+
### 2. Operation Detail Sheets
|
|
121
|
+
Every API route is compiled into its own sheet, named according to its unique `METHOD /path` signature.
|
|
122
|
+
* **Metadata Fields**: Basic information including HTTP Method, Endpoint, Tag/Category, Operation ID, Summary, Description, and Deprecation flags.
|
|
123
|
+
* **Security & Authentication**: Lists the security schemes required to execute the API.
|
|
124
|
+
* **Parameters Table**: Formatted list of query, path, and header parameters, along with their schemas and descriptions.
|
|
125
|
+
* **Request & Response Schema Representation**: Displays the object properties and types.
|
|
126
|
+
* **Autogenerated Mock Payloads**: Valid mock JSON request/response objects (styled using monospaced Consolas) to assist developers in testing.
|
|
127
|
+
* **Semantic Status Groups**:
|
|
128
|
+
* **Success (2xx)**: Green highlight, with response documentation and mockup.
|
|
129
|
+
* **Client Error (4xx)**: Orange/yellow highlight, displaying validation or authorization schemas.
|
|
130
|
+
* **Server Error (5xx)**: Red highlight, showing error response structure.
|
|
131
|
+
* **Navigation Link**: A `<< Back to API List` link located at the bottom of the worksheet.
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
## 🛠️ Key Technical Modules
|
|
136
|
+
|
|
137
|
+
* **`loadSpec()`**: Resolves input sources. For local paths, it reads and parses YAML or JSON. For URLs, it fetches the content and attempts JSON/YAML parsing; if it receives HTML, it delegates to `extractSpecUrlFromHtml()` to locate the underlying spec URL.
|
|
138
|
+
* **`generateExample()`**: Recursively traverses OpenAPI schemas, utilizing `example`, `default`, or `enum` values when present, or generating logical placeholder data depending on data types (e.g., ISO date-times, mock emails, UUIDs).
|
|
139
|
+
* **`makeSheetNamer()`**: Dynamically filters characters invalid in Excel worksheet names, handles name collisions, and truncates names to a maximum of 31 characters.
|
|
140
|
+
|
|
141
|
+
#### TODO: electron app
|