@michaelmishin/speclens 0.2.0 → 0.4.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.4.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 with keyword suggestions, scope filtering (All / API Reference / Guides), and fuzzy matching
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, or copy the prompt to use with any AI agent
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,76 @@ 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
+ ## Search
98
+
99
+ The global search (triggered by the search icon or `Ctrl/Cmd+K`) indexes both API operations and guides. It supports:
100
+
101
+ - **Fuzzy matching** — typos and partial words still find results
102
+ - **Keyword suggestions** — common terms extracted from the spec and guides are shown as clickable chips before you start typing
103
+ - **Scope filtering** — when guides are configured, filter results by **All**, **API Reference**, or **Guides**
104
+
105
+ ## Ask AI
106
+
107
+ 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. A **Copy Prompt** option is also available for pasting into any AI tool of your choice.
108
+
109
+ To hide the button, add the `hide-ask-ai` attribute:
110
+
111
+ ```html
112
+ <spec-lens spec-url="/openapi.json" hide-ask-ai></spec-lens>
113
+ ```
114
+
115
+ Or via config:
116
+
117
+ ```js
118
+ SpecLens.init('#docs', { specUrl: '/openapi.json', hideAskAi: true });
119
+ ```
120
+
47
121
  ## Customization
48
122
 
49
123
  ### Layout Modes
@@ -118,7 +192,7 @@ npm run dev # Vite dev server → http://localhost:5173
118
192
  npm run build # Produces dist/speclens.js (ESM) + dist/speclens.iife.js (IIFE)
119
193
  ```
120
194
 
121
- The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json`.
195
+ The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json` and a guides manifest from `demo/guides.json`.
122
196
 
123
197
  ## Architecture
124
198
 
@@ -126,8 +200,11 @@ The demo page (`index.html`) loads the Petstore spec from `demo/petstore.json`.
126
200
  |------|---------|
127
201
  | `src/index.ts` | Entry point — registers `<spec-lens>`, exports `SpecLens.init()` |
128
202
  | `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) |
203
+ | `src/core/` | Parser, router (hash-based), full-text search, theme utilities, guides loader, AI prompt builder |
204
+ | `src/components/guides/` | `sl-guide-sidebar` and `sl-guide-view` Lit components |
205
+ | `src/components/layout/` | Header (with nav tabs and global search trigger), sidebar, search overlay |
206
+ | `src/components/operation/` | Operation detail, parameters, request body, responses, Try-It console, Ask AI |
207
+ | `src/components/` | Auth, code samples, schema renderer |
131
208
  | `src/styles/` | Design tokens, theme CSS, reset — authored as Lit `css` tagged templates |
132
209
  | `src/shims/` | Browser shims for Node.js `util`/`path` (required by swagger-parser) |
133
210