Skip to content

Commit cc15ccb

Browse files
committed
docs: refine built-in docs try it out
1 parent 088b7e7 commit cc15ccb

17 files changed

Lines changed: 692 additions & 42 deletions

README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,7 @@ Projects can override or add source definitions with `openapi.docs.sources`; sou
646646

647647
The operation view includes parameters, request bodies, horizontal response status tabs without repeated status headings, resolved schema fields without artificial root rows, search entries, auth/deprecated/Try it out state badges, collapsed operation Metadata, a global Authorize control for OpenAPI security schemes, same-origin Try it out, and Code JSDoc usage recipes.
648648

649-
The Try it out console is organized as tabs for Params, Headers, Body, Auth, Samples, History, and Response. It includes server selection, OpenAPI `servers[].variables` controls, full resolved URL preview and Copy URL, structured query/header rows generated from OpenAPI parameters including `validate.header`, raw fallbacks, auth injection notes, optional browser-side request/response hooks through `openapi.docs.tryItOut.hookScript` / `hookGlobal`, diagnostics, cURL/browser fetch/Node fetch/Axios code samples, request history, and a fixed response viewer with pretty/raw body modes plus the actual request and response headers for the last send.
649+
The Try it out console is organized as tabs for Params, Headers, Body, Samples, History, and Response. It includes server selection that prefers OpenAPI `servers[]`, OpenAPI `servers[].variables` controls, optional same-origin fallback, an optional per-request Custom server input, full resolved URL preview and Copy URL, structured query/header rows generated from OpenAPI parameters including `validate.header`, raw fallbacks, auth status and effective header previews inside the Headers tab, optional browser-side request/response hooks through `openapi.docs.tryItOut.hookScript` / `hookGlobal`, diagnostics, cURL/browser fetch/Node fetch/Axios code samples, request history, and a fixed response viewer with pretty/raw body modes plus the actual request and response headers for the last send.
650650

651651
`hookGlobal` is only the browser lookup name; hook notes and sample diagnostics are shown only when a `hookScript` is configured or the runtime global exposes `beforeRequest` / `afterResponse`.
652652

@@ -741,6 +741,32 @@ window.VextDocsHooks = {
741741

742742
Enable it with `openapi.docs.tryItOut.hookScript = "/docs-hook.js"` and optionally change the lookup name with `hookGlobal`.
743743

744+
Try it out server behavior can be tuned separately from the OpenAPI `servers[]` metadata:
745+
746+
```ts
747+
export default {
748+
openapi: {
749+
servers: [
750+
{
751+
url: "http://127.0.0.1:3000",
752+
description: "Local development server",
753+
},
754+
{ url: "https://api.example.com", description: "Production" },
755+
],
756+
docs: {
757+
tryItOut: {
758+
defaultServer: "first", // "first", "same-origin", "custom", or an exact server URL
759+
sameOrigin: "auto", // auto shows Same origin only when no OpenAPI servers exist
760+
customServer: true,
761+
customServerUrl: "http://127.0.0.1:3000",
762+
},
763+
},
764+
},
765+
};
766+
```
767+
768+
For fixed local or deployed endpoints, prefer a complete server URL including its port. Reserve OpenAPI `servers[].variables` for genuinely variable parts such as environment names, regions, tenants, or API versions.
769+
744770
## i18n
745771

746772
Put locale files in `src/locales/`:

changelogs/unreleased.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
- **Built-in docs renderer proxy paths** Added `openapi.docs.assetsPublicPath` for prefix-stripping reverse proxies, so browser-facing docs assets and source-aware data endpoints can differ from Vext's internal `docs.assetsPath`; validation now checks `source.access` field shapes and the docs clarify that `jsonPublicPath` is the public canonical OpenAPI spec URL rather than the built-in source-aware data endpoint.
1515
- **Built-in docs Try it out** Added OpenAPI server variable controls and browser-side request hooks. Try it out now resolves `servers[].variables` into URL previews, Copy URL, samples, and Send requests, validates enum/default values, can load an optional `openapi.docs.tryItOut.hookScript`, calls `window[hookGlobal].beforeRequest` / `afterResponse` around the browser fetch pipeline, and shows hook diagnostics without importing or executing backend project code.
1616
- **Built-in docs Try it out** Clarified hook UI behavior so `hookGlobal` alone is treated as a browser lookup name; hook notes and sample diagnostics are shown only when a hook script is configured or the runtime global actually exposes `beforeRequest` / `afterResponse`.
17+
- **Built-in docs Try it out** Refined server selection so OpenAPI `servers[]` are preferred by default, `Same origin` is configurable through `openapi.docs.tryItOut.sameOrigin`, users can temporarily enter a Custom server URL, server variable panels are hidden when empty, fixed local endpoints are documented and tested as complete server URLs instead of `{port}` variables, and `/docs` renders an inline critical loading shell during refresh/source loading instead of showing a blank page.
18+
- **Built-in docs Try it out** Removed the separate Auth tab and merged auth state into the Headers tab, where Authorize-injected credentials, manual header overrides, and the effective headers preview can be checked in one place.
1719
- **Built-in docs renderer UI** Fixed code-doc navigation indentation so plugin/middleware leaves align under their parent tree instead of the top-level caret, distinguishes default and named plugin/middleware symbols such as `stats.increment`, renders multi-line JSDoc descriptions as paragraphs/lists/code blocks in vanilla JS, and adds an inline favicon to keep `/docs` browser probes free of favicon 404 noise.
1820
- **Built-in docs renderer UI** Polished the default docs interaction model by rendering HTTP API / Pages operation cards directly without tag section headings such as `General`, reducing root navigation guide lines, keeping Try it out results in a fixed scrollable output area to avoid Send-time layout jumps, moving Try it out tabs before Send actions, stacking the header so the title, search box, filters, and global Authorize panel do not compete for one row, adding hover/focus feedback to API and code cards, flattening the Overview shell, using the outline only on wide screens, improving mobile navigation, and making the desktop sidebar auto-sized with persisted manual resize.
1921
- **Built-in docs renderer UI** Refined the default docs experience with `openapi.docs.ui.theme` / `density`, preserved middle dynamic path segments when they lead to stable child resources, added keyboard search shortcuts, category filters, highlighted matches, a desktop outline, copy buttons, deep links, and an Overview workspace with counts, OpenAPI source, access mode, and asset version metadata.
2022
- **Built-in docs renderer UI** Simplified the default documentation surface by hiding Locales / Config / Styles / Preload from the default top-level navigation unless explicitly enabled as static code sources, moving filters to their own header row, and adding package startup/build/verification commands to the Overview workspace.
21-
- **Built-in docs Try it out** Upgraded each operation console with server selection, full URL preview plus Copy URL, tabbed Params / Headers / Body / Auth / Samples / History / Response panels, structured query/header rows plus raw fallbacks, compact empty states, auth injection notes, cURL/browser fetch/Node fetch/Axios samples with copy actions, local request history that does not persist automatically injected Authorize tokens, and a fixed response viewer with pretty/raw body modes.
23+
- **Built-in docs Try it out** Upgraded each operation console with server selection, full URL preview plus Copy URL, tabbed Params / Headers / Body / Samples / History / Response panels, structured query/header rows plus raw fallbacks, compact empty states, auth status and effective header previews in the Headers tab, cURL/browser fetch/Node fetch/Axios samples with copy actions, local request history that does not persist automatically injected Authorize tokens, and a fixed response viewer with pretty/raw body modes.
2224
- **Built-in docs Try it out** Fixed request header usability by exporting `validate.header` as OpenAPI `parameters[in=header]`, pre-filling those headers in the console, showing the actual sent request headers alongside response headers, and keeping the Send status in a stable inline slot to avoid response-area flicker.
2325

2426
## 2026-06-23

src/lib/config-loader.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,18 @@ function validateDocsTryItOutConfig(value: unknown, pathName: string): void {
11471147
}
11481148
validateOptionalString(tryItOut.hookScript, `${pathName}.hookScript`);
11491149
validateOptionalString(tryItOut.hookGlobal, `${pathName}.hookGlobal`);
1150+
validateOptionalString(tryItOut.defaultServer, `${pathName}.defaultServer`);
1151+
validateOptionalBoolean(tryItOut.customServer, `${pathName}.customServer`);
1152+
validateOptionalString(tryItOut.customServerUrl, `${pathName}.customServerUrl`);
1153+
if (
1154+
tryItOut.sameOrigin !== undefined &&
1155+
typeof tryItOut.sameOrigin !== "boolean" &&
1156+
tryItOut.sameOrigin !== "auto"
1157+
) {
1158+
throw new Error(
1159+
`[vextjs] ${pathName}.sameOrigin must be a boolean or "auto".`,
1160+
);
1161+
}
11501162
}
11511163

11521164
function validateOpenAPIServers(value: unknown, pathName: string): void {

src/lib/docs/normalize-config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ export function normalizeDocsConfig(
172172
const tryItOut: ResolvedVextDocsTryItOutConfig = {
173173
hookScript: openapi.docs?.tryItOut?.hookScript,
174174
hookGlobal: openapi.docs?.tryItOut?.hookGlobal ?? "VextDocsHooks",
175+
defaultServer: openapi.docs?.tryItOut?.defaultServer,
176+
sameOrigin: openapi.docs?.tryItOut?.sameOrigin ?? "auto",
177+
customServer: openapi.docs?.tryItOut?.customServer ?? true,
178+
customServerUrl: openapi.docs?.tryItOut?.customServerUrl,
175179
};
176180
const renderer = openapi.docs?.renderer;
177181
if (renderer !== undefined && renderer !== DEFAULT_DOCS_RENDERER) {

0 commit comments

Comments
 (0)