@michaelmishin/speclens 0.1.2 → 0.3.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/README.md +126 -5
- package/dist/speclens.iife.js +1323 -134
- package/dist/speclens.iife.js.map +1 -1
- package/dist/speclens.js +2058 -278
- package/dist/speclens.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A modern, lightweight OpenAPI documentation renderer built as a web component. Drop it into any page via CDN — no build step required.
|
|
4
4
|
|
|
5
|
-
> **Version:** 0.
|
|
5
|
+
> **Version:** 0.3.0
|
|
6
6
|
|
|
7
7
|
## Features
|
|
8
8
|
|
|
@@ -10,7 +10,10 @@ A modern, lightweight OpenAPI documentation renderer built as a web component. D
|
|
|
10
10
|
- **Web component** — `<spec-lens>` custom element with Shadow DOM style isolation
|
|
11
11
|
- **Try It console** — live API request execution with support for JSON, `multipart/form-data`, and `application/x-www-form-urlencoded` bodies
|
|
12
12
|
- **Code samples** — generated snippets for cURL, JavaScript, Python, Node.js, Go, Java, PHP, Ruby, and C#
|
|
13
|
-
- **Full-text search** — fast in-page search powered by MiniSearch
|
|
13
|
+
- **Full-text search** — fast in-page search powered by MiniSearch, covering both operations and guides
|
|
14
|
+
- **Guides** — built-in documentation tab with category sidebar; load guides from an external JSON manifest or inline via config
|
|
15
|
+
- **Ask AI** — one-click buttons on every operation to open a structured prompt in ChatGPT or Claude
|
|
16
|
+
- **Copy route** — hover a route header to copy its deeplink hash to the clipboard
|
|
14
17
|
- **Light & dark themes** — auto-detects system preference, overridable via CSS custom properties
|
|
15
18
|
- **OpenAPI 3.x support** — parsed and validated by `@apidevtools/swagger-parser`
|
|
16
19
|
|
|
@@ -35,6 +38,7 @@ import { SpecLens } from '@michaelmishin/speclens';
|
|
|
35
38
|
SpecLens.init('#docs', {
|
|
36
39
|
specUrl: '/openapi.json',
|
|
37
40
|
theme: 'auto', // 'light' | 'dark' | 'auto'
|
|
41
|
+
guidesUrl: '/guides.json', // optional guides manifest
|
|
38
42
|
});
|
|
39
43
|
```
|
|
40
44
|
|
|
@@ -44,6 +48,120 @@ SpecLens.init('#docs', {
|
|
|
44
48
|
npm install @michaelmishin/speclens
|
|
45
49
|
```
|
|
46
50
|
|
|
51
|
+
## Guides
|
|
52
|
+
|
|
53
|
+
SpecLens can render a **Guides** section alongside the API reference. When guides are configured, a top-level tab bar appears in the header to switch between _API Reference_ and _Guides_.
|
|
54
|
+
|
|
55
|
+
### External manifest (recommended)
|
|
56
|
+
|
|
57
|
+
Create a JSON file that is an array of guide objects and point `guides-url` (or `guidesUrl` in `SpecLens.init()`) at it:
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
<spec-lens spec-url="/openapi.json" guides-url="/guides.json"></spec-lens>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
```json
|
|
64
|
+
[
|
|
65
|
+
{ "title": "Getting Started", "slug": "getting-started", "url": "/docs/getting-started.md", "category": "Basics", "order": 1 },
|
|
66
|
+
{ "title": "Authentication", "slug": "authentication", "url": "/docs/authentication.md", "category": "Basics", "order": 2 },
|
|
67
|
+
{ "title": "Pagination", "slug": "pagination", "url": "/docs/pagination.md", "category": "Advanced", "order": 1 }
|
|
68
|
+
]
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Each guide is fetched and rendered from its `url` (a Markdown file). You can also embed content inline by omitting `url` and providing a `content` string.
|
|
72
|
+
|
|
73
|
+
### Guide object fields
|
|
74
|
+
|
|
75
|
+
| Field | Type | Description |
|
|
76
|
+
|-------|------|-------------|
|
|
77
|
+
| `title` | string | Display title shown in sidebar and page header |
|
|
78
|
+
| `slug` | string | URL-safe identifier — used in hash routing `#/guide/{slug}` |
|
|
79
|
+
| `url` | string | URL to a Markdown file to fetch |
|
|
80
|
+
| `content` | string | Inline Markdown content (takes precedence over `url`) |
|
|
81
|
+
| `category` | string | Sidebar group name (defaults to _General_) |
|
|
82
|
+
| `order` | number | Sort order within the category |
|
|
83
|
+
|
|
84
|
+
### Inline guides via config
|
|
85
|
+
|
|
86
|
+
```js
|
|
87
|
+
SpecLens.init('#docs', {
|
|
88
|
+
specUrl: '/openapi.json',
|
|
89
|
+
guides: [
|
|
90
|
+
{ title: 'Getting Started', slug: 'getting-started', content: '# Hello\nWelcome!', category: 'Basics' },
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Inline guides and an external manifest can be combined — inline guides override on slug collision.
|
|
96
|
+
|
|
97
|
+
## Ask AI
|
|
98
|
+
|
|
99
|
+
Every operation header includes an **Ask AI** button that generates a structured Markdown prompt describing the endpoint (method, path, parameters, request body, responses) and opens it in ChatGPT or Claude.
|
|
100
|
+
|
|
101
|
+
To hide the button, add the `hide-ask-ai` attribute:
|
|
102
|
+
|
|
103
|
+
```html
|
|
104
|
+
<spec-lens spec-url="/openapi.json" hide-ask-ai></spec-lens>
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Or via config:
|
|
108
|
+
|
|
109
|
+
```js
|
|
110
|
+
SpecLens.init('#docs', { specUrl: '/openapi.json', hideAskAi: true });
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
## Customization
|
|
114
|
+
|
|
115
|
+
### Layout Modes
|
|
116
|
+
|
|
117
|
+
Use the `layout` attribute to control how SpecLens integrates with the surrounding page.
|
|
118
|
+
|
|
119
|
+
| Value | Behavior |
|
|
120
|
+
|-------|----------|
|
|
121
|
+
| `page` (default) | Renders its own sticky header with title, Authorize, and theme toggle. Best for standalone CDN use. |
|
|
122
|
+
| `embed` | Suppresses the header entirely. The sidebar starts at the top of the container, and an Authorize button appears at the bottom of the sidebar when the API has security schemes. Use this when embedding inside an existing app that already has a navbar. |
|
|
123
|
+
|
|
124
|
+
```html
|
|
125
|
+
<!-- Standalone page -->
|
|
126
|
+
<spec-lens layout="page" spec-url="/openapi.json"></spec-lens>
|
|
127
|
+
|
|
128
|
+
<!-- Inside an existing app with its own navbar -->
|
|
129
|
+
<spec-lens layout="embed" spec-url="/openapi.json"></spec-lens>
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Named Slots (page mode)
|
|
133
|
+
|
|
134
|
+
In `layout="page"` mode, the header exposes two named slots for customization:
|
|
135
|
+
|
|
136
|
+
| Slot | Replaces |
|
|
137
|
+
|------|----------|
|
|
138
|
+
| `logo` | The API title + version badge in the header |
|
|
139
|
+
| `header-actions` | Additional items in the header action row, placed before the theme toggle |
|
|
140
|
+
|
|
141
|
+
```html
|
|
142
|
+
<spec-lens spec-url="/openapi.json">
|
|
143
|
+
<!-- Replace the title/version with your own logo -->
|
|
144
|
+
<img slot="logo" src="/my-logo.svg" alt="My API" height="28" />
|
|
145
|
+
|
|
146
|
+
<!-- Add extra nav items next to the theme toggle -->
|
|
147
|
+
<a slot="header-actions" href="/changelog">Changelog</a>
|
|
148
|
+
</spec-lens>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Programmatic Theme Control
|
|
152
|
+
|
|
153
|
+
In `layout="embed"` mode the theme toggle button is not visible. Use the `setTheme()` method or the `theme` attribute to control it from the host app:
|
|
154
|
+
|
|
155
|
+
```js
|
|
156
|
+
const docs = document.querySelector('spec-lens');
|
|
157
|
+
|
|
158
|
+
// Programmatic method
|
|
159
|
+
docs.setTheme('dark'); // 'light' | 'dark' | 'auto'
|
|
160
|
+
|
|
161
|
+
// Or set the attribute
|
|
162
|
+
docs.setAttribute('theme', 'dark');
|
|
163
|
+
```
|
|
164
|
+
|
|
47
165
|
## Theming
|
|
48
166
|
|
|
49
167
|
SpecLens exposes CSS custom properties for theming from outside the Shadow DOM:
|
|
@@ -66,7 +184,7 @@ npm run dev # Vite dev server → http://localhost:5173
|
|
|
66
184
|
npm run build # Produces dist/speclens.js (ESM) + dist/speclens.iife.js (IIFE)
|
|
67
185
|
```
|
|
68
186
|
|
|
69
|
-
The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json`.
|
|
187
|
+
The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json` and a guides manifest from `demo/guides.json`.
|
|
70
188
|
|
|
71
189
|
## Architecture
|
|
72
190
|
|
|
@@ -74,8 +192,11 @@ The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json`.
|
|
|
74
192
|
|------|---------|
|
|
75
193
|
| `src/index.ts` | Entry point — registers `<spec-lens>`, exports `SpecLens.init()` |
|
|
76
194
|
| `src/spec-lens.ts` | Root orchestrator Lit component |
|
|
77
|
-
| `src/core/` | Parser, router (hash-based), full-text search, theme utilities |
|
|
78
|
-
| `src/components/` |
|
|
195
|
+
| `src/core/` | Parser, router (hash-based), full-text search, theme utilities, guides loader, AI prompt builder |
|
|
196
|
+
| `src/components/guides/` | `sl-guide-sidebar` and `sl-guide-view` Lit components |
|
|
197
|
+
| `src/components/layout/` | Header (with nav tabs and global search trigger), sidebar, search overlay |
|
|
198
|
+
| `src/components/operation/` | Operation detail, parameters, request body, responses, Try-It console, Ask AI |
|
|
199
|
+
| `src/components/` | Auth, code samples, schema renderer |
|
|
79
200
|
| `src/styles/` | Design tokens, theme CSS, reset — authored as Lit `css` tagged templates |
|
|
80
201
|
| `src/shims/` | Browser shims for Node.js `util`/`path` (required by swagger-parser) |
|
|
81
202
|
|