@michaelmishin/speclens 0.2.0 → 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 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.2.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,68 @@ 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
+
47
113
  ## Customization
48
114
 
49
115
  ### Layout Modes
@@ -118,7 +184,7 @@ npm run dev # Vite dev server → http://localhost:5173
118
184
  npm run build # Produces dist/speclens.js (ESM) + dist/speclens.iife.js (IIFE)
119
185
  ```
120
186
 
121
- 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`.
122
188
 
123
189
  ## Architecture
124
190
 
@@ -126,8 +192,11 @@ The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json`.
126
192
  |------|---------|
127
193
  | `src/index.ts` | Entry point — registers `<spec-lens>`, exports `SpecLens.init()` |
128
194
  | `src/spec-lens.ts` | Root orchestrator Lit component |
129
- | `src/core/` | Parser, router (hash-based), full-text search, theme utilities |
130
- | `src/components/` | Lit web components (layout, operation detail, schema, code samples, auth) |
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 |
131
200
  | `src/styles/` | Design tokens, theme CSS, reset — authored as Lit `css` tagged templates |
132
201
  | `src/shims/` | Browser shims for Node.js `util`/`path` (required by swagger-parser) |
133
202