@webpieces/docs-site 0.4.938 → 0.4.940
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 +10 -0
- package/package.json +1 -1
- package/src/assets/SiteStyles.d.ts +1 -1
- package/src/assets/SiteStyles.js +1 -0
- package/src/assets/SiteStyles.js.map +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.js +5 -2
- package/src/index.js.map +1 -1
- package/src/markdown/CodeLinks.d.ts +36 -0
- package/src/markdown/CodeLinks.js +64 -0
- package/src/markdown/CodeLinks.js.map +1 -0
- package/src/markdown/Markdown.d.ts +15 -0
- package/src/markdown/Markdown.js +24 -1
- package/src/markdown/Markdown.js.map +1 -1
- package/src/render/FieldTreeRenderer.js +1 -1
- package/src/render/FieldTreeRenderer.js.map +1 -1
- package/src/render/HeaderListRenderer.d.ts +5 -2
- package/src/render/HeaderListRenderer.js +8 -5
- package/src/render/HeaderListRenderer.js.map +1 -1
- package/src/render/OperationPageRenderer.d.ts +7 -1
- package/src/render/OperationPageRenderer.js +26 -5
- package/src/render/OperationPageRenderer.js.map +1 -1
- package/src/render/SiteRenderer.d.ts +0 -1
- package/src/render/SiteRenderer.js +18 -15
- package/src/render/SiteRenderer.js.map +1 -1
- package/src/spec/FieldTree.d.ts +23 -0
- package/src/spec/FieldTree.js +36 -1
- package/src/spec/FieldTree.js.map +1 -1
package/README.md
CHANGED
|
@@ -21,6 +21,10 @@ site/
|
|
|
21
21
|
schemas/<kebab-name>/index.html one per named OBJECT dto
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
+
An operation's request or response body written INLINE — as `@webpieces/openapi-generator` writes a
|
|
25
|
+
single-use `…Request` / `…Response` wrapper (#1303) — has no schema page: the operation page heads the
|
|
26
|
+
body with its `title` (the name a generated client gives the model) and `description`, then its fields.
|
|
27
|
+
|
|
24
28
|
Each operation page is HEADED, and its sidebar link LABELLED, with the operation's `summary` — its short
|
|
25
29
|
human title (#1296) — and shows the `operationId` beside the method and path as the code identifier a
|
|
26
30
|
generated client names the method by. The page's URL is kebabed from the `operationId`, so rewording a
|
|
@@ -54,6 +58,12 @@ The markdown is a documented SUBSET of CommonMark — headings, fenced code, tab
|
|
|
54
58
|
blockquotes, rules, paragraphs, and inline `code` / `**bold**` / `*italic*` / `[links](url)` — over
|
|
55
59
|
trusted, PR-reviewed input. Everything is HTML-escaped before any mark is applied.
|
|
56
60
|
|
|
61
|
+
A code span that exactly names an `operationId`, or a schema that has its own page (or a member of
|
|
62
|
+
one, `` `Menu.items` ``), renders as a LINK to that page (#1284) — which is how a JSDoc `{@link}`, published
|
|
63
|
+
by `wp-openapi` as a code span of its target's published name, becomes a hyperlink. A name that is both
|
|
64
|
+
an operationId and a schema, an inlined request/response wrapper (it has no page), and every other
|
|
65
|
+
code span stays plain code.
|
|
66
|
+
|
|
57
67
|
## Reading the reference
|
|
58
68
|
|
|
59
69
|
- **Every tag is its own nav section.** A tag missing from the sidebar is an operation a partner
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/docs-site",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.940",
|
|
4
4
|
"description": "Render a static, three-pane API reference site from any OpenAPI 3.0-or-3.1 document plus a directory of markdown prose. Node builtins only. Ships the wp-docs-site bin.",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./src/index.js",
|
|
@@ -9,5 +9,5 @@
|
|
|
9
9
|
* one attribute on `<html>` and nothing else in the site knows about it.
|
|
10
10
|
*/
|
|
11
11
|
export declare class SiteStyles {
|
|
12
|
-
static readonly CSS = "\n:root {\n --bg: #ffffff;\n --bg-soft: #f6f7f9;\n --fg: #1d2129;\n --fg-soft: #5b6472;\n --line: #e2e5ea;\n --accent: #2f5cff;\n --code-bg: #f2f3f6;\n --badge-fg: #ffffff;\n}\n:root[data-theme='dark'] {\n --bg: #14171c;\n --bg-soft: #1b1f26;\n --fg: #e7eaf0;\n --fg-soft: #9aa4b2;\n --line: #2a2f38;\n --accent: #7f9bff;\n --code-bg: #10131a;\n --badge-fg: #14171c;\n}\n* { box-sizing: border-box; }\nbody {\n margin: 0;\n background: var(--bg);\n color: var(--fg);\n font: 15px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n}\na { color: var(--accent); text-decoration: none; }\na:hover { text-decoration: underline; }\ncode, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }\ncode { background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }\npre { background: var(--code-bg); padding: 12px; border-radius: 6px; overflow-x: auto; }\npre code { background: none; padding: 0; }\ntable { border-collapse: collapse; width: 100%; margin: 12px 0; }\nth, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }\nth { background: var(--bg-soft); }\nhr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }\nblockquote { margin: 12px 0; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--fg-soft); }\n\n.site { display: grid; grid-template-columns: 260px minmax(0, 1fr) 360px; gap: 0; min-height: 100vh; }\n.pane-nav { border-right: 1px solid var(--line); padding: 20px 16px; background: var(--bg-soft); }\n.pane-body { padding: 28px 32px; min-width: 0; }\n.pane-cards { border-left: 1px solid var(--line); padding: 20px 16px; background: var(--bg-soft); }\n.pane-cards-inner { position: sticky; top: 20px; }\n\n.site-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; display: block; color: var(--fg); }\n.site-version { color: var(--fg-soft); font-size: 12px; margin-bottom: 16px; }\n.nav-group { margin-bottom: 10px; }\n.nav-group > summary { cursor: pointer; font-weight: 600; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-soft); }\n.nav-group ul { list-style: none; margin: 6px 0 0; padding: 0 0 0 4px; }\n.nav-group li { margin: 2px 0; }\n.nav-group a { display: flex; gap: 6px; align-items: center; padding: 3px 6px; border-radius: 4px; color: var(--fg); }\n.nav-group a.current { background: var(--accent); color: var(--badge-fg); }\n.nav-group a.current .badge { background: var(--badge-fg); color: var(--accent); }\n\n.badge { font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 1px 5px; border-radius: 3px; background: var(--accent); color: var(--badge-fg); }\n.op-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }\n.op-path { background: var(--code-bg); padding: 3px 8px; border-radius: 4px; }\n.op-id { color: var(--fg-soft); font-size: 12px; }\n.api-summary { font-size: 1.1em; color: var(--fg-soft); margin-top: -4px; }\n\n.card { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-bottom: 16px; }\n.card-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-soft); }\n.card-body { padding: 12px; }\n.card-body pre { margin: 0; }\nbutton { font: inherit; font-size: 11px; cursor: pointer; background: none; border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; color: var(--fg-soft); }\nbutton:hover { color: var(--fg); }\n.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px 0; }\n.tab[aria-selected='true'] { border-color: var(--accent); color: var(--accent); }\n.sample[hidden] { display: none; }\n\n.field { border-top: 1px solid var(--line); padding: 10px 0; }\n.field-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }\n.field-name { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }\n.field-type { color: var(--fg-soft); font-size: 12px; }\n.field-required { color: #c0392b; font-size: 11px; font-weight: 700; letter-spacing: .04em; }\n.field-optional { color: var(--fg-soft); font-size: 11px; font-weight: 700; letter-spacing: .04em; }\n.headers { margin: 8px 0 12px; }\n.headers-head { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--fg-soft); text-transform: uppercase; }\n.field-doc { margin: 4px 0 0; color: var(--fg-soft); }\n.field-children { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 12px; }\n.chips { margin-top: 6px; font-size: 12px; color: var(--fg-soft); }\n.chip { display: inline-block; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin: 2px 4px 2px 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }\n.variant { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 12px 0; }\n.variant-head { font-weight: 600; }\ndetails.disclosure > summary { cursor: pointer; color: var(--fg-soft); font-size: 12px; }\n\n@media (max-width: 1100px) {\n .site { grid-template-columns: 1fr; }\n .pane-nav, .pane-cards { border: 0; }\n .pane-cards-inner { position: static; }\n}\n";
|
|
12
|
+
static readonly CSS = "\n:root {\n --bg: #ffffff;\n --bg-soft: #f6f7f9;\n --fg: #1d2129;\n --fg-soft: #5b6472;\n --line: #e2e5ea;\n --accent: #2f5cff;\n --code-bg: #f2f3f6;\n --badge-fg: #ffffff;\n}\n:root[data-theme='dark'] {\n --bg: #14171c;\n --bg-soft: #1b1f26;\n --fg: #e7eaf0;\n --fg-soft: #9aa4b2;\n --line: #2a2f38;\n --accent: #7f9bff;\n --code-bg: #10131a;\n --badge-fg: #14171c;\n}\n* { box-sizing: border-box; }\nbody {\n margin: 0;\n background: var(--bg);\n color: var(--fg);\n font: 15px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n}\na { color: var(--accent); text-decoration: none; }\na:hover { text-decoration: underline; }\ncode, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }\ncode { background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }\npre { background: var(--code-bg); padding: 12px; border-radius: 6px; overflow-x: auto; }\npre code { background: none; padding: 0; }\ntable { border-collapse: collapse; width: 100%; margin: 12px 0; }\nth, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }\nth { background: var(--bg-soft); }\nhr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }\nblockquote { margin: 12px 0; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--fg-soft); }\n\n.site { display: grid; grid-template-columns: 260px minmax(0, 1fr) 360px; gap: 0; min-height: 100vh; }\n.pane-nav { border-right: 1px solid var(--line); padding: 20px 16px; background: var(--bg-soft); }\n.pane-body { padding: 28px 32px; min-width: 0; }\n.pane-cards { border-left: 1px solid var(--line); padding: 20px 16px; background: var(--bg-soft); }\n.pane-cards-inner { position: sticky; top: 20px; }\n\n.site-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; display: block; color: var(--fg); }\n.site-version { color: var(--fg-soft); font-size: 12px; margin-bottom: 16px; }\n.nav-group { margin-bottom: 10px; }\n.nav-group > summary { cursor: pointer; font-weight: 600; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-soft); }\n.nav-group ul { list-style: none; margin: 6px 0 0; padding: 0 0 0 4px; }\n.nav-group li { margin: 2px 0; }\n.nav-group a { display: flex; gap: 6px; align-items: center; padding: 3px 6px; border-radius: 4px; color: var(--fg); }\n.nav-group a.current { background: var(--accent); color: var(--badge-fg); }\n.nav-group a.current .badge { background: var(--badge-fg); color: var(--accent); }\n\n.badge { font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 1px 5px; border-radius: 3px; background: var(--accent); color: var(--badge-fg); }\n.op-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }\n.op-path { background: var(--code-bg); padding: 3px 8px; border-radius: 4px; }\n.op-id { color: var(--fg-soft); font-size: 12px; }\n.api-summary { font-size: 1.1em; color: var(--fg-soft); margin-top: -4px; }\n\n.card { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-bottom: 16px; }\n.card-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-soft); }\n.card-body { padding: 12px; }\n.card-body pre { margin: 0; }\nbutton { font: inherit; font-size: 11px; cursor: pointer; background: none; border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; color: var(--fg-soft); }\nbutton:hover { color: var(--fg); }\n.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px 0; }\n.tab[aria-selected='true'] { border-color: var(--accent); color: var(--accent); }\n.sample[hidden] { display: none; }\n\n.field { border-top: 1px solid var(--line); padding: 10px 0; }\n.field-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }\n.field-name { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }\n.field-type { color: var(--fg-soft); font-size: 12px; }\n.field-required { color: #c0392b; font-size: 11px; font-weight: 700; letter-spacing: .04em; }\n.field-optional { color: var(--fg-soft); font-size: 11px; font-weight: 700; letter-spacing: .04em; }\n.headers { margin: 8px 0 12px; }\n.headers-head { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--fg-soft); text-transform: uppercase; }\n.field-doc { margin: 4px 0 0; color: var(--fg-soft); }\n.body-type { margin: 4px 0; }\n.field-children { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 12px; }\n.chips { margin-top: 6px; font-size: 12px; color: var(--fg-soft); }\n.chip { display: inline-block; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin: 2px 4px 2px 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }\n.variant { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 12px 0; }\n.variant-head { font-weight: 600; }\ndetails.disclosure > summary { cursor: pointer; color: var(--fg-soft); font-size: 12px; }\n\n@media (max-width: 1100px) {\n .site { grid-template-columns: 1fr; }\n .pane-nav, .pane-cards { border: 0; }\n .pane-cards-inner { position: static; }\n}\n";
|
|
13
13
|
}
|
package/src/assets/SiteStyles.js
CHANGED
|
@@ -93,6 +93,7 @@ button:hover { color: var(--fg); }
|
|
|
93
93
|
.headers { margin: 8px 0 12px; }
|
|
94
94
|
.headers-head { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--fg-soft); text-transform: uppercase; }
|
|
95
95
|
.field-doc { margin: 4px 0 0; color: var(--fg-soft); }
|
|
96
|
+
.body-type { margin: 4px 0; }
|
|
96
97
|
.field-children { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 12px; }
|
|
97
98
|
.chips { margin-top: 6px; font-size: 12px; color: var(--fg-soft); }
|
|
98
99
|
.chip { display: inline-block; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin: 2px 4px 2px 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SiteStyles.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/assets/SiteStyles.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,UAAU;IACnB,MAAM,CAAU,GAAG,GAAG
|
|
1
|
+
{"version":3,"file":"SiteStyles.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/assets/SiteStyles.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACH,MAAa,UAAU;IACnB,MAAM,CAAU,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA8FzB,CAAC;;AA/FF,gCAgGC","sourcesContent":["/**\n * The whole stylesheet, as one string written to `styles.css` beside the pages.\n *\n * It is hand-written rather than generated by a framework because #985 puts the framework, the\n * bundler and the markdown library out of scope: adding an API reference to an upstream project must\n * not grow that project's dependency surface, and this package's own build has to stay `tsc`.\n *\n * Colours are declared once as custom properties and redefined for dark mode, so a theme toggle is\n * one attribute on `<html>` and nothing else in the site knows about it.\n */\nexport class SiteStyles {\n static readonly CSS = `\n:root {\n --bg: #ffffff;\n --bg-soft: #f6f7f9;\n --fg: #1d2129;\n --fg-soft: #5b6472;\n --line: #e2e5ea;\n --accent: #2f5cff;\n --code-bg: #f2f3f6;\n --badge-fg: #ffffff;\n}\n:root[data-theme='dark'] {\n --bg: #14171c;\n --bg-soft: #1b1f26;\n --fg: #e7eaf0;\n --fg-soft: #9aa4b2;\n --line: #2a2f38;\n --accent: #7f9bff;\n --code-bg: #10131a;\n --badge-fg: #14171c;\n}\n* { box-sizing: border-box; }\nbody {\n margin: 0;\n background: var(--bg);\n color: var(--fg);\n font: 15px/1.6 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;\n}\na { color: var(--accent); text-decoration: none; }\na:hover { text-decoration: underline; }\ncode, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }\ncode { background: var(--code-bg); padding: 1px 4px; border-radius: 3px; }\npre { background: var(--code-bg); padding: 12px; border-radius: 6px; overflow-x: auto; }\npre code { background: none; padding: 0; }\ntable { border-collapse: collapse; width: 100%; margin: 12px 0; }\nth, td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; vertical-align: top; }\nth { background: var(--bg-soft); }\nhr { border: 0; border-top: 1px solid var(--line); margin: 24px 0; }\nblockquote { margin: 12px 0; padding: 4px 14px; border-left: 3px solid var(--line); color: var(--fg-soft); }\n\n.site { display: grid; grid-template-columns: 260px minmax(0, 1fr) 360px; gap: 0; min-height: 100vh; }\n.pane-nav { border-right: 1px solid var(--line); padding: 20px 16px; background: var(--bg-soft); }\n.pane-body { padding: 28px 32px; min-width: 0; }\n.pane-cards { border-left: 1px solid var(--line); padding: 20px 16px; background: var(--bg-soft); }\n.pane-cards-inner { position: sticky; top: 20px; }\n\n.site-title { font-weight: 700; font-size: 15px; margin-bottom: 4px; display: block; color: var(--fg); }\n.site-version { color: var(--fg-soft); font-size: 12px; margin-bottom: 16px; }\n.nav-group { margin-bottom: 10px; }\n.nav-group > summary { cursor: pointer; font-weight: 600; font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--fg-soft); }\n.nav-group ul { list-style: none; margin: 6px 0 0; padding: 0 0 0 4px; }\n.nav-group li { margin: 2px 0; }\n.nav-group a { display: flex; gap: 6px; align-items: center; padding: 3px 6px; border-radius: 4px; color: var(--fg); }\n.nav-group a.current { background: var(--accent); color: var(--badge-fg); }\n.nav-group a.current .badge { background: var(--badge-fg); color: var(--accent); }\n\n.badge { font-size: 10px; font-weight: 700; letter-spacing: .04em; padding: 1px 5px; border-radius: 3px; background: var(--accent); color: var(--badge-fg); }\n.op-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 4px; }\n.op-path { background: var(--code-bg); padding: 3px 8px; border-radius: 4px; }\n.op-id { color: var(--fg-soft); font-size: 12px; }\n.api-summary { font-size: 1.1em; color: var(--fg-soft); margin-top: -4px; }\n\n.card { border: 1px solid var(--line); border-radius: 8px; background: var(--bg); margin-bottom: 16px; }\n.card-head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--fg-soft); }\n.card-body { padding: 12px; }\n.card-body pre { margin: 0; }\nbutton { font: inherit; font-size: 11px; cursor: pointer; background: none; border: 1px solid var(--line); border-radius: 4px; padding: 2px 8px; color: var(--fg-soft); }\nbutton:hover { color: var(--fg); }\n.tabs { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 12px 0; }\n.tab[aria-selected='true'] { border-color: var(--accent); color: var(--accent); }\n.sample[hidden] { display: none; }\n\n.field { border-top: 1px solid var(--line); padding: 10px 0; }\n.field-head { display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }\n.field-name { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }\n.field-type { color: var(--fg-soft); font-size: 12px; }\n.field-required { color: #c0392b; font-size: 11px; font-weight: 700; letter-spacing: .04em; }\n.field-optional { color: var(--fg-soft); font-size: 11px; font-weight: 700; letter-spacing: .04em; }\n.headers { margin: 8px 0 12px; }\n.headers-head { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--fg-soft); text-transform: uppercase; }\n.field-doc { margin: 4px 0 0; color: var(--fg-soft); }\n.body-type { margin: 4px 0; }\n.field-children { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 12px; }\n.chips { margin-top: 6px; font-size: 12px; color: var(--fg-soft); }\n.chip { display: inline-block; background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 0 8px; margin: 2px 4px 2px 0; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }\n.variant { border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; margin: 12px 0; }\n.variant-head { font-weight: 600; }\ndetails.disclosure > summary { cursor: pointer; color: var(--fg-soft); font-size: 12px; }\n\n@media (max-width: 1100px) {\n .site { grid-template-columns: 1fr; }\n .pane-nav, .pane-cards { border: 0; }\n .pane-cards-inner { position: static; }\n}\n`;\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -18,11 +18,12 @@ export { SchemaShape } from './spec/SchemaShape';
|
|
|
18
18
|
export { Slug } from './spec/Slug';
|
|
19
19
|
export { SpecLoader } from './spec/SpecLoader';
|
|
20
20
|
export { SpecReader, UNTAGGED_SECTION } from './spec/SpecReader';
|
|
21
|
-
export { FieldNode, FieldTreeBuilder, SchemaVariant } from './spec/FieldTree';
|
|
21
|
+
export { FieldNode, FieldTreeBuilder, InlineBodyHead, SchemaVariant } from './spec/FieldTree';
|
|
22
22
|
export { ExampleBuilder } from './spec/ExampleBuilder';
|
|
23
23
|
export { DocsManifest, ProsePage, ProsePageEntry } from './manifest/DocsManifest';
|
|
24
24
|
export { MANIFEST_FILE, ProseLoader } from './manifest/ProseLoader';
|
|
25
25
|
export { Markdown } from './markdown/Markdown';
|
|
26
|
+
export { CodeLinks } from './markdown/CodeLinks';
|
|
26
27
|
export { CodeSample, CodeSampleBuilder, SampleHeader } from './samples/CodeSamples';
|
|
27
28
|
export { Html } from './render/Html';
|
|
28
29
|
export { GUIDES_GROUP, NavBuilder, NavGroup, NavLink, NavModel, SCHEMAS_GROUP, } from './render/NavModel';
|
package/src/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.WpDocsSiteMain = exports.USAGE = exports.DocsSiteCli = exports.CliResult = exports.LOOPBACK = exports.DevServer = exports.SiteWriter = exports.SiteScript = exports.SiteStyles = exports.SiteRenderer = exports.OVERVIEW_TITLE = exports.SitePage = exports.SiteAsset = void 0;
|
|
3
|
+
exports.OperationPageRenderer = exports.HeaderListRenderer = exports.HEADERS_HEADING = exports.POSSIBLE_VALUES = exports.FieldTreeRenderer = exports.REQUEST_LABEL = exports.CardRenderer = exports.COLLAPSE_ALL_LABEL = exports.Layout = exports.SiteUrls = exports.SCHEMAS_GROUP = exports.NavModel = exports.NavLink = exports.NavGroup = exports.NavBuilder = exports.GUIDES_GROUP = exports.Html = exports.SampleHeader = exports.CodeSampleBuilder = exports.CodeSample = exports.CodeLinks = exports.Markdown = exports.ProseLoader = exports.MANIFEST_FILE = exports.ProsePageEntry = exports.ProsePage = exports.DocsManifest = exports.ExampleBuilder = exports.SchemaVariant = exports.InlineBodyHead = exports.FieldTreeBuilder = exports.FieldNode = exports.UNTAGGED_SECTION = exports.SpecReader = exports.SpecLoader = exports.Slug = exports.SchemaShape = exports.SchemaLens = exports.RefTarget = exports.TagSection = exports.ServerInfo = exports.SecuritySchemeInfo = exports.ResponseInfo = exports.HeaderInfo = exports.OperationInfo = exports.NamedSchema = exports.ApiSpec = exports.JsonNode = exports.JsonEntry = exports.DocsSiteError = void 0;
|
|
4
|
+
exports.WpDocsSiteMain = exports.USAGE = exports.DocsSiteCli = exports.CliResult = exports.LOOPBACK = exports.DevServer = exports.SiteWriter = exports.SiteScript = exports.SiteStyles = exports.SiteRenderer = exports.OVERVIEW_TITLE = exports.SitePage = exports.SiteAsset = exports.RenderedSite = exports.WEBHOOK_BADGE = void 0;
|
|
5
5
|
/**
|
|
6
6
|
* `@webpieces/docs-site` — a static, three-pane API reference site from any OpenAPI 3.0-or-3.1
|
|
7
7
|
* document plus a directory of markdown prose.
|
|
@@ -42,6 +42,7 @@ Object.defineProperty(exports, "UNTAGGED_SECTION", { enumerable: true, get: func
|
|
|
42
42
|
var FieldTree_1 = require("./spec/FieldTree");
|
|
43
43
|
Object.defineProperty(exports, "FieldNode", { enumerable: true, get: function () { return FieldTree_1.FieldNode; } });
|
|
44
44
|
Object.defineProperty(exports, "FieldTreeBuilder", { enumerable: true, get: function () { return FieldTree_1.FieldTreeBuilder; } });
|
|
45
|
+
Object.defineProperty(exports, "InlineBodyHead", { enumerable: true, get: function () { return FieldTree_1.InlineBodyHead; } });
|
|
45
46
|
Object.defineProperty(exports, "SchemaVariant", { enumerable: true, get: function () { return FieldTree_1.SchemaVariant; } });
|
|
46
47
|
var ExampleBuilder_1 = require("./spec/ExampleBuilder");
|
|
47
48
|
Object.defineProperty(exports, "ExampleBuilder", { enumerable: true, get: function () { return ExampleBuilder_1.ExampleBuilder; } });
|
|
@@ -54,6 +55,8 @@ Object.defineProperty(exports, "MANIFEST_FILE", { enumerable: true, get: functio
|
|
|
54
55
|
Object.defineProperty(exports, "ProseLoader", { enumerable: true, get: function () { return ProseLoader_1.ProseLoader; } });
|
|
55
56
|
var Markdown_1 = require("./markdown/Markdown");
|
|
56
57
|
Object.defineProperty(exports, "Markdown", { enumerable: true, get: function () { return Markdown_1.Markdown; } });
|
|
58
|
+
var CodeLinks_1 = require("./markdown/CodeLinks");
|
|
59
|
+
Object.defineProperty(exports, "CodeLinks", { enumerable: true, get: function () { return CodeLinks_1.CodeLinks; } });
|
|
57
60
|
var CodeSamples_1 = require("./samples/CodeSamples");
|
|
58
61
|
Object.defineProperty(exports, "CodeSample", { enumerable: true, get: function () { return CodeSamples_1.CodeSample; } });
|
|
59
62
|
Object.defineProperty(exports, "CodeSampleBuilder", { enumerable: true, get: function () { return CodeSamples_1.CodeSampleBuilder; } });
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/docs-site/src/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;GAUG;AACH,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,4CAAsD;AAA7C,qGAAA,SAAS,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAE5B,0CASwB;AARpB,kGAAA,OAAO,OAAA;AACP,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AACb,qGAAA,UAAU,OAAA;AACV,uGAAA,YAAY,OAAA;AACZ,6GAAA,kBAAkB,OAAA;AAClB,qGAAA,UAAU,OAAA;AACV,qGAAA,UAAU,OAAA;AAEd,gDAA0D;AAAjD,uGAAA,SAAS,OAAA;AAAE,wGAAA,UAAU,OAAA;AAC9B,kDAAiD;AAAxC,0GAAA,WAAW,OAAA;AACpB,oCAAmC;AAA1B,4FAAA,IAAI,OAAA;AACb,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,gDAAiE;AAAxD,wGAAA,UAAU,OAAA;AAAE,8GAAA,gBAAgB,OAAA;AACrC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/docs/docs-site/src/index.ts"],"names":[],"mappings":";;;;AAAA;;;;;;;;;;GAUG;AACH,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,4CAAsD;AAA7C,qGAAA,SAAS,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAE5B,0CASwB;AARpB,kGAAA,OAAO,OAAA;AACP,sGAAA,WAAW,OAAA;AACX,wGAAA,aAAa,OAAA;AACb,qGAAA,UAAU,OAAA;AACV,uGAAA,YAAY,OAAA;AACZ,6GAAA,kBAAkB,OAAA;AAClB,qGAAA,UAAU,OAAA;AACV,qGAAA,UAAU,OAAA;AAEd,gDAA0D;AAA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AA,kBAAkB,OAAA;AAC5C,wEAAsF;AAA7E,8HAAA,qBAAqB,OAAA;AAAE,sHAAA,aAAa,OAAA;AAC7C,8CAAsE;AAA7D,wGAAA,YAAY,OAAA;AAAE,qGAAA,SAAS,OAAA;AAAE,oGAAA,QAAQ,OAAA;AAC1C,sDAAqE;AAA5D,8GAAA,cAAc,OAAA;AAAE,4GAAA,YAAY,OAAA;AACrC,kDAAiD;AAAxC,wGAAA,UAAU,OAAA;AACnB,kDAAiD;AAAxC,wGAAA,UAAU,OAAA;AACnB,gDAA+C;AAAtC,wGAAA,UAAU,OAAA;AACnB,+CAAwD;AAA/C,sGAAA,SAAS,OAAA;AAAE,qGAAA,QAAQ,OAAA;AAC5B,iDAAkE;AAAzD,wGAAA,SAAS,OAAA;AAAE,0GAAA,WAAW,OAAA;AAAE,oGAAA,KAAK,OAAA;AACtC,uDAAsD;AAA7C,gHAAA,cAAc,OAAA","sourcesContent":["/**\n * `@webpieces/docs-site` — a static, three-pane API reference site from any OpenAPI 3.0-or-3.1\n * document plus a directory of markdown prose.\n *\n * **Node builtins only.** No framework, no markdown library, no bundler, so adding docs to an\n * upstream project never grows that project's dependency surface and this package's own build stays\n * `tsc`. It also does NOT depend on `@webpieces/openapi-generator`, deliberately: the document is\n * read structurally, so \"generated by us\" is not a precondition for \"renderable by us\".\n *\n * It ships the `wp-docs-site` bin.\n */\nexport { DocsSiteError } from './DocsSiteError';\nexport { JsonEntry, JsonNode } from './spec/JsonNode';\nexport type { JsonMap, JsonValue } from './spec/JsonNode';\nexport {\n ApiSpec,\n NamedSchema,\n OperationInfo,\n HeaderInfo,\n ResponseInfo,\n SecuritySchemeInfo,\n ServerInfo,\n TagSection,\n} from './spec/ApiSpec';\nexport { RefTarget, SchemaLens } from './spec/SchemaLens';\nexport { SchemaShape } from './spec/SchemaShape';\nexport { Slug } from './spec/Slug';\nexport { SpecLoader } from './spec/SpecLoader';\nexport { SpecReader, UNTAGGED_SECTION } from './spec/SpecReader';\nexport { FieldNode, FieldTreeBuilder, InlineBodyHead, SchemaVariant } from './spec/FieldTree';\nexport { ExampleBuilder } from './spec/ExampleBuilder';\nexport { DocsManifest, ProsePage, ProsePageEntry } from './manifest/DocsManifest';\nexport { MANIFEST_FILE, ProseLoader } from './manifest/ProseLoader';\nexport { Markdown } from './markdown/Markdown';\nexport { CodeLinks } from './markdown/CodeLinks';\nexport { CodeSample, CodeSampleBuilder, SampleHeader } from './samples/CodeSamples';\nexport { Html } from './render/Html';\nexport {\n GUIDES_GROUP,\n NavBuilder,\n NavGroup,\n NavLink,\n NavModel,\n SCHEMAS_GROUP,\n} from './render/NavModel';\nexport { SiteUrls } from './render/SiteUrls';\nexport { Layout } from './render/Layout';\nexport { COLLAPSE_ALL_LABEL, CardRenderer, REQUEST_LABEL } from './render/CardRenderer';\nexport { FieldTreeRenderer, POSSIBLE_VALUES } from './render/FieldTreeRenderer';\nexport { HEADERS_HEADING, HeaderListRenderer } from './render/HeaderListRenderer';\nexport { OperationPageRenderer, WEBHOOK_BADGE } from './render/OperationPageRenderer';\nexport { RenderedSite, SiteAsset, SitePage } from './render/SitePage';\nexport { OVERVIEW_TITLE, SiteRenderer } from './render/SiteRenderer';\nexport { SiteStyles } from './assets/SiteStyles';\nexport { SiteScript } from './assets/SiteScript';\nexport { SiteWriter } from './emit/SiteWriter';\nexport { DevServer, LOOPBACK } from './serve/DevServer';\nexport { CliResult, DocsSiteCli, USAGE } from './cli/DocsSiteCli';\nexport { WpDocsSiteMain } from './cli/WpDocsSiteMain';\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { ApiSpec } from '../spec/ApiSpec';
|
|
2
|
+
import { SiteUrls } from '../render/SiteUrls';
|
|
3
|
+
/**
|
|
4
|
+
* Which code spans in the document's prose are REFERENCES, and the page each one names (#1284).
|
|
5
|
+
*
|
|
6
|
+
* `@webpieces/openapi-generator` publishes every JSDoc `{@link X}` as a markdown code span holding X's
|
|
7
|
+
* PUBLISHED identity — `` `fetchOrders` `` for an operation (its operationId), `` `Menu` `` for a
|
|
8
|
+
* schema, `` `Menu.items` `` for one of its members. OpenAPI descriptions are CommonMark, so any
|
|
9
|
+
* renderer shows that as code; this site goes one step further and makes it a hyperlink:
|
|
10
|
+
*
|
|
11
|
+
* | code span | links to |
|
|
12
|
+
* |---|---|
|
|
13
|
+
* | exactly an operation's `operationId` | that operation's page |
|
|
14
|
+
* | exactly a schema that has its own page | that schema's page |
|
|
15
|
+
* | `<schema>.<member>` of such a schema | that schema's page |
|
|
16
|
+
* | anything else | nothing — it stays plain code |
|
|
17
|
+
*
|
|
18
|
+
* A name that is BOTH an operationId and a schema links to neither: a guess would be a link that is
|
|
19
|
+
* wrong half the time, and plain code is never wrong. A code span an author wrote by hand that happens
|
|
20
|
+
* to spell a known name links too, which is the point — it names the same thing.
|
|
21
|
+
*/
|
|
22
|
+
export declare class CodeLinks {
|
|
23
|
+
/** Operation id -> its page's URL, relative to the site root. */
|
|
24
|
+
private readonly operations;
|
|
25
|
+
/** Schema name -> its page's URL, relative to the site root. */
|
|
26
|
+
private readonly schemas;
|
|
27
|
+
constructor(
|
|
28
|
+
/** Operation id -> its page's URL, relative to the site root. */
|
|
29
|
+
operations: ReadonlyMap<string, string>,
|
|
30
|
+
/** Schema name -> its page's URL, relative to the site root. */
|
|
31
|
+
schemas: ReadonlyMap<string, string>);
|
|
32
|
+
/** Every operation and every schema with its own page in `spec`, at the URLs `urls` builds. */
|
|
33
|
+
static of(spec: ApiSpec, urls: SiteUrls): CodeLinks;
|
|
34
|
+
/** The site-relative URL `code` names, or undefined when it names no page (or two). */
|
|
35
|
+
hrefFor(code: string): string | undefined;
|
|
36
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CodeLinks = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Which code spans in the document's prose are REFERENCES, and the page each one names (#1284).
|
|
6
|
+
*
|
|
7
|
+
* `@webpieces/openapi-generator` publishes every JSDoc `{@link X}` as a markdown code span holding X's
|
|
8
|
+
* PUBLISHED identity — `` `fetchOrders` `` for an operation (its operationId), `` `Menu` `` for a
|
|
9
|
+
* schema, `` `Menu.items` `` for one of its members. OpenAPI descriptions are CommonMark, so any
|
|
10
|
+
* renderer shows that as code; this site goes one step further and makes it a hyperlink:
|
|
11
|
+
*
|
|
12
|
+
* | code span | links to |
|
|
13
|
+
* |---|---|
|
|
14
|
+
* | exactly an operation's `operationId` | that operation's page |
|
|
15
|
+
* | exactly a schema that has its own page | that schema's page |
|
|
16
|
+
* | `<schema>.<member>` of such a schema | that schema's page |
|
|
17
|
+
* | anything else | nothing — it stays plain code |
|
|
18
|
+
*
|
|
19
|
+
* A name that is BOTH an operationId and a schema links to neither: a guess would be a link that is
|
|
20
|
+
* wrong half the time, and plain code is never wrong. A code span an author wrote by hand that happens
|
|
21
|
+
* to spell a known name links too, which is the point — it names the same thing.
|
|
22
|
+
*/
|
|
23
|
+
class CodeLinks {
|
|
24
|
+
operations;
|
|
25
|
+
schemas;
|
|
26
|
+
constructor(
|
|
27
|
+
/** Operation id -> its page's URL, relative to the site root. */
|
|
28
|
+
operations,
|
|
29
|
+
/** Schema name -> its page's URL, relative to the site root. */
|
|
30
|
+
schemas) {
|
|
31
|
+
this.operations = operations;
|
|
32
|
+
this.schemas = schemas;
|
|
33
|
+
}
|
|
34
|
+
/** Every operation and every schema with its own page in `spec`, at the URLs `urls` builds. */
|
|
35
|
+
// webpieces-disable no-function-outside-class -- static factory of this class
|
|
36
|
+
static of(spec, urls) {
|
|
37
|
+
const operations = new Map();
|
|
38
|
+
for (const operation of spec.operations()) {
|
|
39
|
+
if (operation.operationId !== '') {
|
|
40
|
+
operations.set(operation.operationId, urls.operation(operation));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const schemas = new Map();
|
|
44
|
+
for (const schema of spec.schemas) {
|
|
45
|
+
if (schema.hasOwnPage) {
|
|
46
|
+
schemas.set(schema.name, urls.schema(schema));
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return new CodeLinks(operations, schemas);
|
|
50
|
+
}
|
|
51
|
+
/** The site-relative URL `code` names, or undefined when it names no page (or two). */
|
|
52
|
+
hrefFor(code) {
|
|
53
|
+
const operation = this.operations.get(code);
|
|
54
|
+
const schema = this.schemas.get(code);
|
|
55
|
+
if (operation !== undefined || schema !== undefined) {
|
|
56
|
+
return operation !== undefined && schema !== undefined ? undefined : (operation ?? schema);
|
|
57
|
+
}
|
|
58
|
+
// A member tail (`Menu.items`) names its schema's page; an operation has no members.
|
|
59
|
+
const dot = code.indexOf('.');
|
|
60
|
+
return dot > 0 ? this.schemas.get(code.slice(0, dot)) : undefined;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.CodeLinks = CodeLinks;
|
|
64
|
+
//# sourceMappingURL=CodeLinks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CodeLinks.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/markdown/CodeLinks.ts"],"names":[],"mappings":";;;AAGA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAa,SAAS;IAGG;IAEA;IAJrB;IACI,iEAAiE;IAChD,UAAuC;IACxD,gEAAgE;IAC/C,OAAoC;QAFpC,eAAU,GAAV,UAAU,CAA6B;QAEvC,YAAO,GAAP,OAAO,CAA6B;IACtD,CAAC;IAEJ,+FAA+F;IAC/F,8EAA8E;IAC9E,MAAM,CAAC,EAAE,CAAC,IAAa,EAAE,IAAc;QACnC,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC7C,KAAK,MAAM,SAAS,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACxC,IAAI,SAAS,CAAC,WAAW,KAAK,EAAE,EAAE,CAAC;gBAC/B,UAAU,CAAC,GAAG,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC;YACrE,CAAC;QACL,CAAC;QACD,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC1C,KAAK,MAAM,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YAChC,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;gBACpB,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;YAClD,CAAC;QACL,CAAC;QACD,OAAO,IAAI,SAAS,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,uFAAuF;IACvF,OAAO,CAAC,IAAY;QAChB,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5C,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,SAAS,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;YAClD,OAAO,SAAS,KAAK,SAAS,IAAI,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,IAAI,MAAM,CAAC,CAAC;QAC/F,CAAC;QACD,qFAAqF;QACrF,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC9B,OAAO,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,CAAC;CACJ;AArCD,8BAqCC","sourcesContent":["import { ApiSpec } from '../spec/ApiSpec';\nimport { SiteUrls } from '../render/SiteUrls';\n\n/**\n * Which code spans in the document's prose are REFERENCES, and the page each one names (#1284).\n *\n * `@webpieces/openapi-generator` publishes every JSDoc `{@link X}` as a markdown code span holding X's\n * PUBLISHED identity — `` `fetchOrders` `` for an operation (its operationId), `` `Menu` `` for a\n * schema, `` `Menu.items` `` for one of its members. OpenAPI descriptions are CommonMark, so any\n * renderer shows that as code; this site goes one step further and makes it a hyperlink:\n *\n * | code span | links to |\n * |---|---|\n * | exactly an operation's `operationId` | that operation's page |\n * | exactly a schema that has its own page | that schema's page |\n * | `<schema>.<member>` of such a schema | that schema's page |\n * | anything else | nothing — it stays plain code |\n *\n * A name that is BOTH an operationId and a schema links to neither: a guess would be a link that is\n * wrong half the time, and plain code is never wrong. A code span an author wrote by hand that happens\n * to spell a known name links too, which is the point — it names the same thing.\n */\nexport class CodeLinks {\n constructor(\n /** Operation id -> its page's URL, relative to the site root. */\n private readonly operations: ReadonlyMap<string, string>,\n /** Schema name -> its page's URL, relative to the site root. */\n private readonly schemas: ReadonlyMap<string, string>,\n ) {}\n\n /** Every operation and every schema with its own page in `spec`, at the URLs `urls` builds. */\n // webpieces-disable no-function-outside-class -- static factory of this class\n static of(spec: ApiSpec, urls: SiteUrls): CodeLinks {\n const operations = new Map<string, string>();\n for (const operation of spec.operations()) {\n if (operation.operationId !== '') {\n operations.set(operation.operationId, urls.operation(operation));\n }\n }\n const schemas = new Map<string, string>();\n for (const schema of spec.schemas) {\n if (schema.hasOwnPage) {\n schemas.set(schema.name, urls.schema(schema));\n }\n }\n return new CodeLinks(operations, schemas);\n }\n\n /** The site-relative URL `code` names, or undefined when it names no page (or two). */\n hrefFor(code: string): string | undefined {\n const operation = this.operations.get(code);\n const schema = this.schemas.get(code);\n if (operation !== undefined || schema !== undefined) {\n return operation !== undefined && schema !== undefined ? undefined : (operation ?? schema);\n }\n // A member tail (`Menu.items`) names its schema's page; an operation has no members.\n const dot = code.indexOf('.');\n return dot > 0 ? this.schemas.get(code.slice(0, dot)) : undefined;\n }\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CodeLinks } from './CodeLinks';
|
|
1
2
|
/**
|
|
2
3
|
* A DOCUMENTED SUBSET of CommonMark, over trusted, PR-reviewed input — the JSDoc a developer wrote
|
|
3
4
|
* and the markdown files a manifest names. It is not a CommonMark implementation and does not try to
|
|
@@ -18,17 +19,31 @@
|
|
|
18
19
|
*
|
|
19
20
|
* and inline: `` `code` ``, `**bold**`, `*italic*`, `[text](url)`.
|
|
20
21
|
*
|
|
22
|
+
* A code span that names a known operation or schema is rendered as a LINK to its page (#1284) — see
|
|
23
|
+
* {@link CodeLinks}. That is how a JSDoc `{@link}`, which the generator publishes as a code span of
|
|
24
|
+
* the target's published name, becomes a hyperlink here and plain code everywhere else.
|
|
25
|
+
*
|
|
21
26
|
* **Everything is HTML-escaped first**, before any inline pattern runs, so a `<` in a JSDoc body is
|
|
22
27
|
* text rather than the start of a tag. That ordering is the whole safety argument: escape-then-mark
|
|
23
28
|
* cannot produce a tag the source did not ask for, while mark-then-escape would escape the tags this
|
|
24
29
|
* renderer just wrote.
|
|
25
30
|
*/
|
|
26
31
|
export declare class Markdown {
|
|
32
|
+
private readonly links;
|
|
33
|
+
/** The rendering page's `../` prefix, so a code-span link resolves at any hosting path. */
|
|
34
|
+
private readonly prefix;
|
|
27
35
|
private readonly html;
|
|
36
|
+
constructor(links: CodeLinks,
|
|
37
|
+
/** The rendering page's `../` prefix, so a code-span link resolves at any hosting path. */
|
|
38
|
+
prefix: string);
|
|
39
|
+
/** The same renderer for a page at another depth — `prefix` is that page's `../` prefix. */
|
|
40
|
+
forPage(prefix: string): Markdown;
|
|
28
41
|
/** The rendered HTML for a markdown document. */
|
|
29
42
|
render(source: string): string;
|
|
30
43
|
/** Inline markdown only — for a place that is already one line, like a table cell. */
|
|
31
44
|
inline(source: string): string;
|
|
45
|
+
/** One code span: a link to its page when it names one, plain code otherwise. */
|
|
46
|
+
private code;
|
|
32
47
|
/** @returns the index of the first line AFTER the block this consumed. */
|
|
33
48
|
private block;
|
|
34
49
|
private fence;
|
package/src/markdown/Markdown.js
CHANGED
|
@@ -22,13 +22,29 @@ const Html_1 = require("../render/Html");
|
|
|
22
22
|
*
|
|
23
23
|
* and inline: `` `code` ``, `**bold**`, `*italic*`, `[text](url)`.
|
|
24
24
|
*
|
|
25
|
+
* A code span that names a known operation or schema is rendered as a LINK to its page (#1284) — see
|
|
26
|
+
* {@link CodeLinks}. That is how a JSDoc `{@link}`, which the generator publishes as a code span of
|
|
27
|
+
* the target's published name, becomes a hyperlink here and plain code everywhere else.
|
|
28
|
+
*
|
|
25
29
|
* **Everything is HTML-escaped first**, before any inline pattern runs, so a `<` in a JSDoc body is
|
|
26
30
|
* text rather than the start of a tag. That ordering is the whole safety argument: escape-then-mark
|
|
27
31
|
* cannot produce a tag the source did not ask for, while mark-then-escape would escape the tags this
|
|
28
32
|
* renderer just wrote.
|
|
29
33
|
*/
|
|
30
34
|
class Markdown {
|
|
35
|
+
links;
|
|
36
|
+
prefix;
|
|
31
37
|
html = new Html_1.Html();
|
|
38
|
+
constructor(links,
|
|
39
|
+
/** The rendering page's `../` prefix, so a code-span link resolves at any hosting path. */
|
|
40
|
+
prefix) {
|
|
41
|
+
this.links = links;
|
|
42
|
+
this.prefix = prefix;
|
|
43
|
+
}
|
|
44
|
+
/** The same renderer for a page at another depth — `prefix` is that page's `../` prefix. */
|
|
45
|
+
forPage(prefix) {
|
|
46
|
+
return new Markdown(this.links, prefix);
|
|
47
|
+
}
|
|
32
48
|
/** The rendered HTML for a markdown document. */
|
|
33
49
|
render(source) {
|
|
34
50
|
const lines = source.replace(/\r\n/g, '\n').split('\n');
|
|
@@ -44,11 +60,18 @@ class Markdown {
|
|
|
44
60
|
inline(source) {
|
|
45
61
|
const escaped = this.html.escape(source);
|
|
46
62
|
return escaped
|
|
47
|
-
.replace(/`([^`]+)`/g,
|
|
63
|
+
.replace(/`([^`]+)`/g, (_all, code) => this.code(code))
|
|
48
64
|
.replace(/\[([^\]]+)\]\(([^)\s]+)\)/g, '<a href="$2">$1</a>')
|
|
49
65
|
.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>')
|
|
50
66
|
.replace(/(^|[^*])\*([^*]+)\*/g, '$1<em>$2</em>');
|
|
51
67
|
}
|
|
68
|
+
/** One code span: a link to its page when it names one, plain code otherwise. */
|
|
69
|
+
code(code) {
|
|
70
|
+
const href = this.links.hrefFor(code);
|
|
71
|
+
return href === undefined
|
|
72
|
+
? `<code>${code}</code>`
|
|
73
|
+
: `<a href="${this.prefix}${href}"><code>${code}</code></a>`;
|
|
74
|
+
}
|
|
52
75
|
/** @returns the index of the first line AFTER the block this consumed. */
|
|
53
76
|
block(lines, start, out) {
|
|
54
77
|
const line = lines[start] ?? '';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/markdown/Markdown.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAEtC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAa,QAAQ;IACA,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,iDAAiD;IACjD,MAAM,CAAC,MAAc;QACjB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YAC/C,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,sFAAsF;IACtF,MAAM,CAAC,MAAc;QACjB,MAAM,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C,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClE,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;CACJ;AA3KD,4BA2KC","sourcesContent":["import { Html } from '../render/Html';\n\n/**\n * A DOCUMENTED SUBSET of CommonMark, over trusted, PR-reviewed input — the JSDoc a developer wrote\n * and the markdown files a manifest names. It is not a CommonMark implementation and does not try to\n * be; #985 puts a full one explicitly out of scope, because the alternative to ~180 lines here is a\n * dependency in every upstream project that wants an API reference.\n *\n * What it renders:\n *\n * | block | spelling |\n * |---|---|\n * | heading | `#` through `######` |\n * | fenced code | ` ``` ` with an optional language word |\n * | table | a `\\|` row, then a `\\|---\\|` row, then rows |\n * | list | `- ` / `* ` for bullets, `1. ` for numbers |\n * | blockquote | `> ` |\n * | rule | `---` on its own line |\n * | paragraph | anything else, blank-line separated |\n *\n * and inline: `` `code` ``, `**bold**`, `*italic*`, `[text](url)`.\n *\n * **Everything is HTML-escaped first**, before any inline pattern runs, so a `<` in a JSDoc body is\n * text rather than the start of a tag. That ordering is the whole safety argument: escape-then-mark\n * cannot produce a tag the source did not ask for, while mark-then-escape would escape the tags this\n * renderer just wrote.\n */\nexport class Markdown {\n private readonly html = new Html();\n\n /** The rendered HTML for a markdown document. */\n render(source: string): string {\n const lines = source.replace(/\\r\\n/g, '\\n').split('\\n');\n const out: string[] = [];\n let index = 0;\n while (index < lines.length) {\n const consumed = this.block(lines, index, out);\n index = consumed > index ? consumed : index + 1;\n }\n return out.join('\\n');\n }\n\n /** Inline markdown only — for a place that is already one line, like a table cell. */\n inline(source: string): string {\n const escaped = this.html.escape(source);\n return escaped\n .replace(/`([^`]+)`/g, '<code>$1</code>')\n .replace(/\\[([^\\]]+)\\]\\(([^)\\s]+)\\)/g, '<a href=\"$2\">$1</a>')\n .replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>')\n .replace(/(^|[^*])\\*([^*]+)\\*/g, '$1<em>$2</em>');\n }\n\n /** @returns the index of the first line AFTER the block this consumed. */\n private block(lines: readonly string[], start: number, out: string[]): number {\n const line = lines[start] ?? '';\n if (line.trim() === '') {\n return start + 1;\n }\n if (line.startsWith('```')) {\n return this.fence(lines, start, out);\n }\n if (/^#{1,6}\\s/.test(line)) {\n return this.heading(line, start, out);\n }\n if (/^(-{3,}|\\*{3,})\\s*$/.test(line.trim())) {\n out.push('<hr />');\n return start + 1;\n }\n if (line.trimStart().startsWith('|') && this.isDivider(lines[start + 1])) {\n return this.table(lines, start, out);\n }\n if (this.isBullet(line) || this.isNumber(line)) {\n return this.list(lines, start, out);\n }\n if (line.trimStart().startsWith('> ')) {\n return this.quote(lines, start, out);\n }\n return this.paragraph(lines, start, out);\n }\n\n private fence(lines: readonly string[], start: number, out: string[]): number {\n const language = (lines[start] ?? '').slice(3).trim();\n const body: string[] = [];\n let index = start + 1;\n while (index < lines.length && !(lines[index] ?? '').startsWith('```')) {\n body.push(lines[index] ?? '');\n index++;\n }\n const languageClass =\n language === '' ? '' : ` class=\"language-${this.html.escape(language)}\"`;\n out.push(`<pre><code${languageClass}>${this.html.escape(body.join('\\n'))}</code></pre>`);\n return index + 1;\n }\n\n private heading(line: string, start: number, out: string[]): number {\n const hashes = (/^#{1,6}/.exec(line) ?? [''])[0].length;\n out.push(`<h${hashes}>${this.inline(line.slice(hashes).trim())}</h${hashes}>`);\n return start + 1;\n }\n\n private table(lines: readonly string[], start: number, out: string[]): number {\n const header = this.cells(lines[start] ?? '');\n const rows: string[][] = [];\n let index = start + 2;\n while (index < lines.length && (lines[index] ?? '').trimStart().startsWith('|')) {\n rows.push(this.cells(lines[index] ?? ''));\n index++;\n }\n const head = header.map((cell: string): string => `<th>${this.inline(cell)}</th>`).join('');\n const body = rows\n .map(\n (row: string[]): string =>\n `<tr>${row.map((cell: string): string => `<td>${this.inline(cell)}</td>`).join('')}</tr>`,\n )\n .join('');\n out.push(`<table><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table>`);\n return index;\n }\n\n private list(lines: readonly string[], start: number, out: string[]): number {\n const ordered = this.isNumber(lines[start] ?? '');\n const items: string[] = [];\n let index = start;\n while (\n index < lines.length &&\n (this.isBullet(lines[index] ?? '') || this.isNumber(lines[index] ?? ''))\n ) {\n items.push(this.inline(this.itemTextOf(lines[index] ?? '')));\n index++;\n }\n const tag = ordered ? 'ol' : 'ul';\n const body = items.map((item: string): string => `<li>${item}</li>`).join('');\n out.push(`<${tag}>${body}</${tag}>`);\n return index;\n }\n\n private quote(lines: readonly string[], start: number, out: string[]): number {\n const body: string[] = [];\n let index = start;\n while (index < lines.length && (lines[index] ?? '').trimStart().startsWith('> ')) {\n body.push((lines[index] ?? '').trimStart().slice(2));\n index++;\n }\n out.push(`<blockquote>${this.render(body.join('\\n'))}</blockquote>`);\n return index;\n }\n\n private paragraph(lines: readonly string[], start: number, out: string[]): number {\n const body: string[] = [];\n let index = start;\n while (\n index < lines.length &&\n (lines[index] ?? '').trim() !== '' &&\n !this.startsBlock(lines, index)\n ) {\n body.push(lines[index] ?? '');\n index++;\n }\n out.push(`<p>${this.inline(body.join('\\n'))}</p>`);\n return index === start ? start + 1 : index;\n }\n\n /** True when the line at `index` begins a block that a paragraph must not swallow. */\n private startsBlock(lines: readonly string[], index: number): boolean {\n if (index === 0) {\n return false;\n }\n const line = lines[index] ?? '';\n return (\n line.startsWith('```') ||\n /^#{1,6}\\s/.test(line) ||\n this.isBullet(line) ||\n this.isNumber(line) ||\n line.trimStart().startsWith('> ') ||\n (line.trimStart().startsWith('|') && this.isDivider(lines[index + 1]))\n );\n }\n\n private isDivider(line: string | undefined): boolean {\n return line !== undefined && /^\\s*\\|[\\s:|-]+\\|\\s*$/.test(line);\n }\n\n private isBullet(line: string): boolean {\n return /^\\s*[-*]\\s+/.test(line);\n }\n\n private isNumber(line: string): boolean {\n return /^\\s*\\d+\\.\\s+/.test(line);\n }\n\n private itemTextOf(line: string): string {\n return line.replace(/^\\s*(?:[-*]|\\d+\\.)\\s+/, '');\n }\n\n private cells(line: string): string[] {\n const trimmed = line.trim().replace(/^\\|/, '').replace(/\\|$/, '');\n return trimmed.split('|').map((cell: string): string => cell.trim());\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/markdown/Markdown.ts"],"names":[],"mappings":";;;AAAA,yCAAsC;AAGtC;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAa,QAAQ;IAII;IAEA;IALJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,KAAgB;IACjC,2FAA2F;IAC1E,MAAc;QAFd,UAAK,GAAL,KAAK,CAAW;QAEhB,WAAM,GAAN,MAAM,CAAQ;IAChC,CAAC;IAEJ,4FAA4F;IAC5F,OAAO,CAAC,MAAc;QAClB,OAAO,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED,iDAAiD;IACjD,MAAM,CAAC,MAAc;QACjB,MAAM,KAAK,GAAG,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACxD,MAAM,GAAG,GAAa,EAAE,CAAC;QACzB,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,OAAO,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAC1B,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;YAC/C,KAAK,GAAG,QAAQ,GAAG,KAAK,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1B,CAAC;IAED,sFAA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;QACzB,OAAO,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAEO,QAAQ,CAAC,IAAY;QACzB,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEO,UAAU,CAAC,IAAY;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE,EAAE,CAAC,CAAC;IACrD,CAAC;IAEO,KAAK,CAAC,IAAY;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClE,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IACzE,CAAC;CACJ;AA9LD,4BA8LC","sourcesContent":["import { Html } from '../render/Html';\nimport { CodeLinks } from './CodeLinks';\n\n/**\n * A DOCUMENTED SUBSET of CommonMark, over trusted, PR-reviewed input — the JSDoc a developer wrote\n * and the markdown files a manifest names. It is not a CommonMark implementation and does not try to\n * be; #985 puts a full one explicitly out of scope, because the alternative to ~180 lines here is a\n * dependency in every upstream project that wants an API reference.\n *\n * What it renders:\n *\n * | block | spelling |\n * |---|---|\n * | heading | `#` through `######` |\n * | fenced code | ` ``` ` with an optional language word |\n * | table | a `\\|` row, then a `\\|---\\|` row, then rows |\n * | list | `- ` / `* ` for bullets, `1. ` for numbers |\n * | blockquote | `> ` |\n * | rule | `---` on its own line |\n * | paragraph | anything else, blank-line separated |\n *\n * and inline: `` `code` ``, `**bold**`, `*italic*`, `[text](url)`.\n *\n * A code span that names a known operation or schema is rendered as a LINK to its page (#1284) — see\n * {@link CodeLinks}. That is how a JSDoc `{@link}`, which the generator publishes as a code span of\n * the target's published name, becomes a hyperlink here and plain code everywhere else.\n *\n * **Everything is HTML-escaped first**, before any inline pattern runs, so a `<` in a JSDoc body is\n * text rather than the start of a tag. That ordering is the whole safety argument: escape-then-mark\n * cannot produce a tag the source did not ask for, while mark-then-escape would escape the tags this\n * renderer just wrote.\n */\nexport class Markdown {\n private readonly html = new Html();\n\n constructor(\n private readonly links: CodeLinks,\n /** The rendering page's `../` prefix, so a code-span link resolves at any hosting path. */\n private readonly prefix: string,\n ) {}\n\n /** The same renderer for a page at another depth — `prefix` is that page's `../` prefix. */\n forPage(prefix: string): Markdown {\n return new Markdown(this.links, prefix);\n }\n\n /** The rendered HTML for a markdown document. */\n render(source: string): string {\n const lines = source.replace(/\\r\\n/g, '\\n').split('\\n');\n const out: string[] = [];\n let index = 0;\n while (index < lines.length) {\n const consumed = this.block(lines, index, out);\n index = consumed > index ? consumed : index + 1;\n }\n return out.join('\\n');\n }\n\n /** Inline markdown only — for a place that is already one line, like a table cell. */\n inline(source: string): string {\n const escaped = this.html.escape(source);\n return escaped\n .replace(/`([^`]+)`/g, (_all: string, code: string): string => this.code(code))\n .replace(/\\[([^\\]]+)\\]\\(([^)\\s]+)\\)/g, '<a href=\"$2\">$1</a>')\n .replace(/\\*\\*([^*]+)\\*\\*/g, '<strong>$1</strong>')\n .replace(/(^|[^*])\\*([^*]+)\\*/g, '$1<em>$2</em>');\n }\n\n /** One code span: a link to its page when it names one, plain code otherwise. */\n private code(code: string): string {\n const href = this.links.hrefFor(code);\n return href === undefined\n ? `<code>${code}</code>`\n : `<a href=\"${this.prefix}${href}\"><code>${code}</code></a>`;\n }\n\n /** @returns the index of the first line AFTER the block this consumed. */\n private block(lines: readonly string[], start: number, out: string[]): number {\n const line = lines[start] ?? '';\n if (line.trim() === '') {\n return start + 1;\n }\n if (line.startsWith('```')) {\n return this.fence(lines, start, out);\n }\n if (/^#{1,6}\\s/.test(line)) {\n return this.heading(line, start, out);\n }\n if (/^(-{3,}|\\*{3,})\\s*$/.test(line.trim())) {\n out.push('<hr />');\n return start + 1;\n }\n if (line.trimStart().startsWith('|') && this.isDivider(lines[start + 1])) {\n return this.table(lines, start, out);\n }\n if (this.isBullet(line) || this.isNumber(line)) {\n return this.list(lines, start, out);\n }\n if (line.trimStart().startsWith('> ')) {\n return this.quote(lines, start, out);\n }\n return this.paragraph(lines, start, out);\n }\n\n private fence(lines: readonly string[], start: number, out: string[]): number {\n const language = (lines[start] ?? '').slice(3).trim();\n const body: string[] = [];\n let index = start + 1;\n while (index < lines.length && !(lines[index] ?? '').startsWith('```')) {\n body.push(lines[index] ?? '');\n index++;\n }\n const languageClass =\n language === '' ? '' : ` class=\"language-${this.html.escape(language)}\"`;\n out.push(`<pre><code${languageClass}>${this.html.escape(body.join('\\n'))}</code></pre>`);\n return index + 1;\n }\n\n private heading(line: string, start: number, out: string[]): number {\n const hashes = (/^#{1,6}/.exec(line) ?? [''])[0].length;\n out.push(`<h${hashes}>${this.inline(line.slice(hashes).trim())}</h${hashes}>`);\n return start + 1;\n }\n\n private table(lines: readonly string[], start: number, out: string[]): number {\n const header = this.cells(lines[start] ?? '');\n const rows: string[][] = [];\n let index = start + 2;\n while (index < lines.length && (lines[index] ?? '').trimStart().startsWith('|')) {\n rows.push(this.cells(lines[index] ?? ''));\n index++;\n }\n const head = header.map((cell: string): string => `<th>${this.inline(cell)}</th>`).join('');\n const body = rows\n .map(\n (row: string[]): string =>\n `<tr>${row.map((cell: string): string => `<td>${this.inline(cell)}</td>`).join('')}</tr>`,\n )\n .join('');\n out.push(`<table><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table>`);\n return index;\n }\n\n private list(lines: readonly string[], start: number, out: string[]): number {\n const ordered = this.isNumber(lines[start] ?? '');\n const items: string[] = [];\n let index = start;\n while (\n index < lines.length &&\n (this.isBullet(lines[index] ?? '') || this.isNumber(lines[index] ?? ''))\n ) {\n items.push(this.inline(this.itemTextOf(lines[index] ?? '')));\n index++;\n }\n const tag = ordered ? 'ol' : 'ul';\n const body = items.map((item: string): string => `<li>${item}</li>`).join('');\n out.push(`<${tag}>${body}</${tag}>`);\n return index;\n }\n\n private quote(lines: readonly string[], start: number, out: string[]): number {\n const body: string[] = [];\n let index = start;\n while (index < lines.length && (lines[index] ?? '').trimStart().startsWith('> ')) {\n body.push((lines[index] ?? '').trimStart().slice(2));\n index++;\n }\n out.push(`<blockquote>${this.render(body.join('\\n'))}</blockquote>`);\n return index;\n }\n\n private paragraph(lines: readonly string[], start: number, out: string[]): number {\n const body: string[] = [];\n let index = start;\n while (\n index < lines.length &&\n (lines[index] ?? '').trim() !== '' &&\n !this.startsBlock(lines, index)\n ) {\n body.push(lines[index] ?? '');\n index++;\n }\n out.push(`<p>${this.inline(body.join('\\n'))}</p>`);\n return index === start ? start + 1 : index;\n }\n\n /** True when the line at `index` begins a block that a paragraph must not swallow. */\n private startsBlock(lines: readonly string[], index: number): boolean {\n if (index === 0) {\n return false;\n }\n const line = lines[index] ?? '';\n return (\n line.startsWith('```') ||\n /^#{1,6}\\s/.test(line) ||\n this.isBullet(line) ||\n this.isNumber(line) ||\n line.trimStart().startsWith('> ') ||\n (line.trimStart().startsWith('|') && this.isDivider(lines[index + 1]))\n );\n }\n\n private isDivider(line: string | undefined): boolean {\n return line !== undefined && /^\\s*\\|[\\s:|-]+\\|\\s*$/.test(line);\n }\n\n private isBullet(line: string): boolean {\n return /^\\s*[-*]\\s+/.test(line);\n }\n\n private isNumber(line: string): boolean {\n return /^\\s*\\d+\\.\\s+/.test(line);\n }\n\n private itemTextOf(line: string): string {\n return line.replace(/^\\s*(?:[-*]|\\d+\\.)\\s+/, '');\n }\n\n private cells(line: string): string[] {\n const trimmed = line.trim().replace(/^\\|/, '').replace(/\\|$/, '');\n return trimmed.split('|').map((cell: string): string => cell.trim());\n }\n}\n"]}
|
|
@@ -60,7 +60,7 @@ class FieldTreeRenderer {
|
|
|
60
60
|
}
|
|
61
61
|
parts.push('</div>');
|
|
62
62
|
if (field.description !== '') {
|
|
63
|
-
parts.push(`<div class="field-doc">${this.markdown.render(field.description)}</div>`);
|
|
63
|
+
parts.push(`<div class="field-doc">${this.markdown.forPage(prefix).render(field.description)}</div>`);
|
|
64
64
|
}
|
|
65
65
|
parts.push(this.chips(field));
|
|
66
66
|
if (field.children.length > 0) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldTreeRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/FieldTreeRenderer.ts"],"names":[],"mappings":";;;AACA,iCAA8B;AAI9B,yFAAyF;AAC5E,QAAA,eAAe,GAAG,kBAAkB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,MAAa,iBAAiB;IAIL;IACA;IAJJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,QAAkB,EAClB,IAAc;QADd,aAAQ,GAAR,QAAQ,CAAU;QAClB,SAAI,GAAJ,IAAI,CAAU;IAChC,CAAC;IAEJ,4FAA4F;IAC5F,MAAM,CAAC,MAA4B,EAAE,MAAc;QAC/C,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACtB,OAAO,qCAAqC,CAAC;QACjD,CAAC;QACD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAgB,EAAU,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACxF,CAAC;IAED;;;;OAIG;IACH,cAAc,CACV,QAAkC,EAClC,aAAqB,EACrB,MAAc;QAEd,OAAO,QAAQ;aACV,GAAG,CAAC,CAAC,OAAsB,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,CAAC,CAAC;aACrF,IAAI,CAAC,EAAE,CAAC,CAAC;IAClB,CAAC;IAEO,OAAO,CAAC,OAAsB,EAAE,aAAqB,EAAE,MAAc;QACzE,MAAM,GAAG,GACL,OAAO,CAAC,kBAAkB,KAAK,EAAE,IAAI,aAAa,KAAK,EAAE;YACrD,CAAC,CA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,EAAE,MAAc;QAC9C,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAC1D,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QAChD,OAAO,YAAY,IAAI,KAAK,KAAK,MAAM,CAAC;IAC5C,CAAC;IAEO,KAAK,CAAC,KAAgB;QAC1B,IAAI,KAAK,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACpC,OAAO,EAAE,CAAC;QACd,CAAC;QACD,MAAM,KAAK,GAAG,KAAK,CAAC,cAAc;aAC7B,GAAG,CAAC,CAAC,KAAa,EAAU,EAAE,CAAC,sBAAsB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC;aACtF,IAAI,CAAC,EAAE,CAAC,CAAC;QACd,OAAO,sBAAsB,uBAAe,IAAI,KAAK,QAAQ,CAAC;IAClE,CAAC;CACJ;AAjFD,8CAiFC","sourcesContent":["import { FieldNode, SchemaVariant } from '../spec/FieldTree';\nimport { Html } from './Html';\nimport { Markdown } from '../markdown/Markdown';\nimport { SiteUrls } from './SiteUrls';\n\n/** The literal line a reader Ctrl-Fs for when they want to know what an enum accepts. */\nexport const POSSIBLE_VALUES = 'Possible values:';\n\n/**\n * Renders the parameter tree: field name, type label, prose, and — for an enum — the COMPLETE\n * `Possible values:` chip line.\n *\n * The list is complete or it is absent; there is no \"…and 3 more\". A truncated list of accepted\n * values is the shape of documentation that makes a partner guess, and the guess is a 400 they\n * cannot debug from the page they are reading.\n *\n * A field whose type is a named object renders as a LINK to that object's page and is NOT expanded\n * underneath — see `FieldTreeBuilder` for why the example body resolves the same reference fully.\n */\nexport class FieldTreeRenderer {\n private readonly html = new Html();\n\n constructor(\n private readonly markdown: Markdown,\n private readonly urls: SiteUrls,\n ) {}\n\n /** One tree. `prefix` is the page's `../` prefix, so the links work at any hosting path. */\n render(fields: readonly FieldNode[], prefix: string): string {\n if (fields.length === 0) {\n return '<p class=\"field-doc\">No fields.</p>';\n }\n return fields.map((field: FieldNode): string => this.field(field, prefix)).join('');\n }\n\n /**\n * The `oneOf` variants, ALL EXPANDED, one labelled block per branch keyed by its discriminator\n * value. Never tabbed: a partner writing one handler needs every shape at once, and a tab is\n * invisible to Ctrl-F and to print.\n */\n renderVariants(\n variants: readonly SchemaVariant[],\n discriminator: string,\n prefix: string,\n ): string {\n return variants\n .map((variant: SchemaVariant): string => this.variant(variant, discriminator, prefix))\n .join('');\n }\n\n private variant(variant: SchemaVariant, discriminator: string, prefix: string): string {\n const key =\n variant.discriminatorValue === '' || discriminator === ''\n ? ''\n : ` — <code>${this.html.escape(discriminator)}: \"${this.html.escape(variant.discriminatorValue)}\"</code>`;\n return [\n '<section class=\"variant\">',\n `<div class=\"variant-head\">${this.html.escape(variant.label)}${key}</div>`,\n this.render(variant.fields, prefix),\n '</section>',\n ].join('');\n }\n\n private field(field: FieldNode, prefix: string): string {\n const parts = ['<div class=\"field\">', '<div class=\"field-head\">'];\n parts.push(`<span class=\"field-name\">${this.html.escape(field.name)}</span>`);\n parts.push(`<span class=\"field-type\">${this.typeLabel(field, prefix)}</span>`);\n if (field.required) {\n parts.push('<span class=\"field-required\">REQUIRED</span>');\n }\n parts.push('</div>');\n if (field.description !== '') {\n parts.push(`<div class=\"field-doc\">${this.markdown.forPage(prefix).render(field.description)}</div>`);\n }\n parts.push(this.chips(field));\n if (field.children.length > 0) {\n parts.push(`<div class=\"field-children\">${this.render(field.children, prefix)}</div>`);\n }\n parts.push('</div>');\n return parts.join('');\n }\n\n private typeLabel(field: FieldNode, prefix: string): string {\n if (field.linkTo === undefined) {\n return this.html.escape(field.typeLabel);\n }\n const href = `${prefix}${this.urls.schema(field.linkTo)}`;\n const label = this.html.escape(field.typeLabel);\n return `<a href=\"${href}\">${label}</a>`;\n }\n\n private chips(field: FieldNode): string {\n if (field.possibleValues.length === 0) {\n return '';\n }\n const chips = field.possibleValues\n .map((value: string): string => `<span class=\"chip\">${this.html.escape(value)}</span>`)\n .join('');\n return `<div class=\"chips\">${POSSIBLE_VALUES} ${chips}</div>`;\n }\n}\n"]}
|
|
@@ -20,8 +20,11 @@ export declare class HeaderListRenderer {
|
|
|
20
20
|
private readonly markdown;
|
|
21
21
|
private readonly html;
|
|
22
22
|
constructor(lens: SchemaLens, markdown: Markdown);
|
|
23
|
-
/**
|
|
24
|
-
|
|
23
|
+
/**
|
|
24
|
+
* The list, or the empty string when there are no headers — no empty heading. `prefix` is the
|
|
25
|
+
* page's `../` prefix, for a code span in a header's prose that links to a page.
|
|
26
|
+
*/
|
|
27
|
+
render(headers: readonly HeaderInfo[], prefix: string): string;
|
|
25
28
|
private row;
|
|
26
29
|
/** A header with no `schema` is a string on the wire — every HTTP header value is text. */
|
|
27
30
|
private typeOf;
|
|
@@ -24,15 +24,18 @@ class HeaderListRenderer {
|
|
|
24
24
|
this.lens = lens;
|
|
25
25
|
this.markdown = markdown;
|
|
26
26
|
}
|
|
27
|
-
/**
|
|
28
|
-
|
|
27
|
+
/**
|
|
28
|
+
* The list, or the empty string when there are no headers — no empty heading. `prefix` is the
|
|
29
|
+
* page's `../` prefix, for a code span in a header's prose that links to a page.
|
|
30
|
+
*/
|
|
31
|
+
render(headers, prefix) {
|
|
29
32
|
if (headers.length === 0) {
|
|
30
33
|
return '';
|
|
31
34
|
}
|
|
32
|
-
const rows = headers.map((header) => this.row(header)).join('');
|
|
35
|
+
const rows = headers.map((header) => this.row(header, prefix)).join('');
|
|
33
36
|
return `<div class="headers"><div class="headers-head">${exports.HEADERS_HEADING}</div>${rows}</div>`;
|
|
34
37
|
}
|
|
35
|
-
row(header) {
|
|
38
|
+
row(header, prefix) {
|
|
36
39
|
const parts = ['<div class="field">', '<div class="field-head">'];
|
|
37
40
|
parts.push(`<span class="field-name">${this.html.escape(header.name)}</span>`);
|
|
38
41
|
parts.push(`<span class="field-type">${this.html.escape(this.typeOf(header))}</span>`);
|
|
@@ -42,7 +45,7 @@ class HeaderListRenderer {
|
|
|
42
45
|
parts.push('</div>');
|
|
43
46
|
const description = header.description !== '' ? header.description : this.lens.describe(header.schema);
|
|
44
47
|
if (description !== '') {
|
|
45
|
-
parts.push(`<div class="field-doc">${this.markdown.render(description)}</div>`);
|
|
48
|
+
parts.push(`<div class="field-doc">${this.markdown.forPage(prefix).render(description)}</div>`);
|
|
46
49
|
}
|
|
47
50
|
parts.push('</div>');
|
|
48
51
|
return parts.join('');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"HeaderListRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/HeaderListRenderer.ts"],"names":[],"mappings":";;;AAEA,iCAA8B;AAG9B,qEAAqE;AACxD,QAAA,eAAe,GAAG,SAAS,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAa,kBAAkB;IAIN;IACA;IAJJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,IAAgB,EAChB,QAAkB;QADlB,SAAI,GAAJ,IAAI,CAAY;QAChB,aAAQ,GAAR,QAAQ,CAAU;IACpC,CAAC;IAEJ
|
|
1
|
+
{"version":3,"file":"HeaderListRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/HeaderListRenderer.ts"],"names":[],"mappings":";;;AAEA,iCAA8B;AAG9B,qEAAqE;AACxD,QAAA,eAAe,GAAG,SAAS,CAAC;AAEzC;;;;;;;;;;;GAWG;AACH,MAAa,kBAAkB;IAIN;IACA;IAJJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,IAAgB,EAChB,QAAkB;QADlB,S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Q,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;QACpG,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACrB,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1B,CAAC;IAED,2FAA2F;IACnF,MAAM,CAAC,MAAkB;QAC7B,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC;IAChF,CAAC;CACJ;AA1CD,gDA0CC","sourcesContent":["import { HeaderInfo } from '../spec/ApiSpec';\nimport { SchemaLens } from '../spec/SchemaLens';\nimport { Html } from './Html';\nimport { Markdown } from '../markdown/Markdown';\n\n/** The heading a reader Ctrl-Fs for, above every list of headers. */\nexport const HEADERS_HEADING = 'Headers';\n\n/**\n * A **Headers** list (#1292): one row per header with its name, type, `REQUIRED` / `OPTIONAL`, and\n * prose — on a response card beside the body schema, and in the request section for `in: \"header\"`\n * parameters.\n *\n * A response header used to be invisible on the site although the document declared it: the\n * `x-request-id` a partner must quote in a support ticket was in `components.headers` and on every\n * response, and no page said so. Each row uses the SAME markup as a body field, and its type label\n * is the same {@link SchemaLens} reading, so a header reads exactly like a field. Unlike a body field,\n * optional is said out loud: a header list is short, and \"may I omit this\" is the question a reader\n * of one is asking.\n */\nexport class HeaderListRenderer {\n private readonly html = new Html();\n\n constructor(\n private readonly lens: SchemaLens,\n private readonly markdown: Markdown,\n ) {}\n\n /**\n * The list, or the empty string when there are no headers — no empty heading. `prefix` is the\n * page's `../` prefix, for a code span in a header's prose that links to a page.\n */\n render(headers: readonly HeaderInfo[], prefix: string): string {\n if (headers.length === 0) {\n return '';\n }\n const rows = headers.map((header: HeaderInfo): string => this.row(header, prefix)).join('');\n return `<div class=\"headers\"><div class=\"headers-head\">${HEADERS_HEADING}</div>${rows}</div>`;\n }\n\n private row(header: HeaderInfo, prefix: string): string {\n const parts = ['<div class=\"field\">', '<div class=\"field-head\">'];\n parts.push(`<span class=\"field-name\">${this.html.escape(header.name)}</span>`);\n parts.push(`<span class=\"field-type\">${this.html.escape(this.typeOf(header))}</span>`);\n parts.push(\n header.required\n ? '<span class=\"field-required\">REQUIRED</span>'\n : '<span class=\"field-optional\">OPTIONAL</span>',\n );\n parts.push('</div>');\n const description = header.description !== '' ? header.description : this.lens.describe(header.schema);\n if (description !== '') {\n parts.push(`<div class=\"field-doc\">${this.markdown.forPage(prefix).render(description)}</div>`);\n }\n parts.push('</div>');\n return parts.join('');\n }\n\n /** A header with no `schema` is a string on the wire — every HTTP header value is text. */\n private typeOf(header: HeaderInfo): string {\n return header.schema.isObject() ? this.lens.label(header.schema) : 'string';\n }\n}\n"]}
|
|
@@ -46,7 +46,13 @@ export declare class OperationPageRenderer {
|
|
|
46
46
|
private requestSection;
|
|
47
47
|
private responseSection;
|
|
48
48
|
private response;
|
|
49
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* A `oneOf` renders as expanded variants; anything else renders as one flat field tree. An INLINE
|
|
51
|
+
* body (#1303) is headed by its `title` and `description` first: it has no schema page, so this
|
|
52
|
+
* page is the only place a reader can see the name a generated client gives it, or its prose.
|
|
53
|
+
*/
|
|
50
54
|
private tree;
|
|
55
|
+
private inlineHead;
|
|
56
|
+
private fieldTree;
|
|
51
57
|
private cardColumn;
|
|
52
58
|
}
|
|
@@ -47,7 +47,7 @@ class OperationPageRenderer {
|
|
|
47
47
|
body(operation, prefix) {
|
|
48
48
|
const parts = [this.head(operation), `<h1>${this.html.escape(operation.name)}</h1>`];
|
|
49
49
|
if (operation.description !== '') {
|
|
50
|
-
parts.push(this.markdown.render(operation.description));
|
|
50
|
+
parts.push(this.markdown.forPage(prefix).render(operation.description));
|
|
51
51
|
}
|
|
52
52
|
parts.push(this.requestSection(operation, prefix));
|
|
53
53
|
parts.push(this.responseSection(operation, prefix));
|
|
@@ -71,7 +71,7 @@ class OperationPageRenderer {
|
|
|
71
71
|
requestSection(operation, prefix) {
|
|
72
72
|
const parts = [];
|
|
73
73
|
if (operation.requestHeaders.length > 0) {
|
|
74
|
-
parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders)}`);
|
|
74
|
+
parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders, prefix)}`);
|
|
75
75
|
}
|
|
76
76
|
if (operation.requestSchema !== undefined) {
|
|
77
77
|
parts.push(`<h2>Request body</h2>${this.tree(operation.requestSchema, prefix)}`);
|
|
@@ -88,16 +88,37 @@ class OperationPageRenderer {
|
|
|
88
88
|
return `<h2>Responses</h2>${blocks}`;
|
|
89
89
|
}
|
|
90
90
|
response(response, prefix) {
|
|
91
|
-
|
|
91
|
+
// Inline markdown: a `{@link}` in `@returns` arrives as a code span, and may link (#1284).
|
|
92
|
+
const summary = `${this.html.escape(response.status)} — ${this.markdown.forPage(prefix).inline(response.description)}`;
|
|
92
93
|
const body = response.schema === undefined
|
|
93
94
|
? '<p class="field-doc">No body.</p>'
|
|
94
95
|
: this.tree(response.schema, prefix);
|
|
95
96
|
// The headers ride the card beside the body (#1292) — the response a partner holds carries both.
|
|
96
|
-
const headers = this.headers.render(response.headers);
|
|
97
|
+
const headers = this.headers.render(response.headers, prefix);
|
|
97
98
|
return `<details class="disclosure" open><summary>${summary}</summary>${headers}${body}</details>`;
|
|
98
99
|
}
|
|
99
|
-
/**
|
|
100
|
+
/**
|
|
101
|
+
* A `oneOf` renders as expanded variants; anything else renders as one flat field tree. An INLINE
|
|
102
|
+
* body (#1303) is headed by its `title` and `description` first: it has no schema page, so this
|
|
103
|
+
* page is the only place a reader can see the name a generated client gives it, or its prose.
|
|
104
|
+
*/
|
|
100
105
|
tree(schema, prefix) {
|
|
106
|
+
return this.inlineHead(schema) + this.fieldTree(schema, prefix);
|
|
107
|
+
}
|
|
108
|
+
inlineHead(schema) {
|
|
109
|
+
const head = this.fields.inlineHeadOf(schema);
|
|
110
|
+
if (head === undefined) {
|
|
111
|
+
return '';
|
|
112
|
+
}
|
|
113
|
+
const title = head.title === ''
|
|
114
|
+
? ''
|
|
115
|
+
: `<p class="body-type"><code title="schema title">${this.html.escape(head.title)}</code></p>`;
|
|
116
|
+
const description = head.description === ''
|
|
117
|
+
? ''
|
|
118
|
+
: `<div class="field-doc">${this.markdown.render(head.description)}</div>`;
|
|
119
|
+
return title + description;
|
|
120
|
+
}
|
|
121
|
+
fieldTree(schema, prefix) {
|
|
101
122
|
const variants = this.fields.variantsOf(schema);
|
|
102
123
|
if (variants.length > 0) {
|
|
103
124
|
return this.trees.renderVariants(variants, this.fields.discriminatorPropertyOf(schema), prefix);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationPageRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/OperationPageRenderer.ts"],"names":[],"mappings":";;;AAOA,iCAA8B;AAK9B,yCAAsC;AAEtC,yDAAyD;AAC5C,QAAA,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAa,qBAAqB;IAIT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAZJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,IAAa,EACb,MAAwB,EACxB,KAAwB,EACxB,QAAkB,EAClB,KAAmB,EACnB,OAA0B,EAC1B,QAAwB,EACxB,MAAc,EACd,IAAc,EACd,OAA2B;QAT3B,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAkB;QACxB,UAAK,GAAL,KAAK,CAAmB;QACxB,aAAQ,GAAR,QAAQ,CAAU;QAClB,UAAK,GAAL,KAAK,CAAc;QACnB,YAAO,GAAP,OAAO,CAAmB;QAC1B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAU;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C,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;QACnF,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,OAAO;YACH,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;YAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;SACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;CACJ;AAjHD,sDAiHC","sourcesContent":["import { ApiSpec, OperationInfo, ResponseInfo } from '../spec/ApiSpec';\nimport { CardRenderer } from './CardRenderer';\nimport { CodeSampleBuilder } from '../samples/CodeSamples';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\nimport { FieldTreeBuilder } from '../spec/FieldTree';\nimport { FieldTreeRenderer } from './FieldTreeRenderer';\nimport { HeaderListRenderer } from './HeaderListRenderer';\nimport { Html } from './Html';\nimport { JsonNode } from '../spec/JsonNode';\nimport { Layout } from './Layout';\nimport { Markdown } from '../markdown/Markdown';\nimport { SiteUrls } from './SiteUrls';\nimport { SitePage } from './SitePage';\n\n/** The badge a webhook carries everywhere it appears. */\nexport const WEBHOOK_BADGE = 'WEBHOOK';\n\n/**\n * One pre-rendered page per operation, at `reference/<kebab-operation>/index.html`.\n *\n * ## What a WEBHOOK page leaves out, and why\n *\n * No method, no path, no code samples. The url is the PARTNER's — they host the endpoint wherever\n * they choose — so a `POST https://api.example.com/...` sample on a webhook page invites them to\n * call something that does not exist. What it keeps is the payload, because the payload is the part\n * that IS ours, and the event name, because that is what they match on the wire.\n */\nexport class OperationPageRenderer {\n private readonly html = new Html();\n\n constructor(\n private readonly spec: ApiSpec,\n private readonly fields: FieldTreeBuilder,\n private readonly trees: FieldTreeRenderer,\n private readonly markdown: Markdown,\n private readonly cards: CardRenderer,\n private readonly samples: CodeSampleBuilder,\n private readonly examples: ExampleBuilder,\n private readonly layout: Layout,\n private readonly urls: SiteUrls,\n private readonly headers: HeaderListRenderer,\n ) {}\n\n page(operation: OperationInfo): SitePage {\n const url = this.urls.operation(operation);\n const prefix = this.urls.prefixFor(url);\n return new SitePage(\n url,\n operation.name,\n this.layout.render(\n url,\n operation.name,\n this.body(operation, prefix),\n this.cardColumn(operation),\n ),\n );\n }\n\n private body(operation: OperationInfo, prefix: string): string {\n const parts = [this.head(operation), `<h1>${this.html.escape(operation.name)}</h1>`];\n if (operation.description !== '') {\n parts.push(this.markdown.render(operation.description));\n }\n parts.push(this.requestSection(operation, prefix));\n parts.push(this.responseSection(operation, prefix));\n return parts.join('\\n');\n }\n\n /**\n * The badge, the path (or event) and the `operationId`. The page HEADING is the operation's\n * summary (#1296); the operationId stays visible here because it is what a generated client names\n * the method, which is what a developer searches their code for.\n */\n private head(operation: OperationInfo): string {\n const id =\n operation.operationId === ''\n ? ''\n : `<code class=\"op-id\" title=\"operationId\">${this.html.escape(operation.operationId)}</code>`;\n if (operation.isWebhook) {\n return `<div class=\"op-head\"><span class=\"badge\">${WEBHOOK_BADGE}</span><code class=\"op-path\">${this.html.escape(operation.eventName)}</code>${id}</div>`;\n }\n return `<div class=\"op-head\"><span class=\"badge\">${this.html.escape(operation.httpMethod)}</span><code class=\"op-path\">${this.html.escape(operation.path)}</code>${id}</div>`;\n }\n\n /** The request's `in: \"header\"` parameters, then its body — each only when there is one. */\n private requestSection(operation: OperationInfo, prefix: string): string {\n const parts: string[] = [];\n if (operation.requestHeaders.length > 0) {\n parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders)}`);\n }\n if (operation.requestSchema !== undefined) {\n parts.push(`<h2>Request body</h2>${this.tree(operation.requestSchema, prefix)}`);\n }\n return parts.join('');\n }\n\n private responseSection(operation: OperationInfo, prefix: string): string {\n if (operation.responses.length === 0) {\n return '';\n }\n const blocks = operation.responses\n .map((response: ResponseInfo): string => this.response(response, prefix))\n .join('');\n return `<h2>Responses</h2>${blocks}`;\n }\n\n private response(response: ResponseInfo, prefix: string): string {\n const summary = `${this.html.escape(response.status)} — ${this.html.escape(response.description)}`;\n const body =\n response.schema === undefined\n ? '<p class=\"field-doc\">No body.</p>'\n : this.tree(response.schema, prefix);\n // The headers ride the card beside the body (#1292) — the response a partner holds carries both.\n const headers = this.headers.render(response.headers);\n return `<details class=\"disclosure\" open><summary>${summary}</summary>${headers}${body}</details>`;\n }\n\n /** A `oneOf` renders as expanded variants; anything else renders as one flat field tree. */\n private tree(schema: JsonNode, prefix: string): string {\n const variants = this.fields.variantsOf(schema);\n if (variants.length > 0) {\n return this.trees.renderVariants(\n variants,\n this.fields.discriminatorPropertyOf(schema),\n prefix,\n );\n }\n return this.trees.render(this.fields.fieldsOf(schema), prefix);\n }\n\n private cardColumn(operation: OperationInfo): string {\n const payload = this.examples.render(this.examples.build(operation.requestSchema));\n if (operation.isWebhook) {\n return this.cards.example('EVENT PAYLOAD', payload);\n }\n return [\n this.cards.authorization(operation, this.spec.securitySchemes),\n this.cards.samples(this.samples.samplesFor(operation)),\n ].join('\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"OperationPageRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/OperationPageRenderer.ts"],"names":[],"mappings":";;;AAOA,iCAA8B;AAK9B,yCAAsC;AAEtC,yDAAyD;AAC5C,QAAA,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAa,qBAAqB;IAIT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAZJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,IAAa,EACb,MAAwB,EACxB,KAAwB,EACxB,QAAkB,EAClB,KAAmB,EACnB,OAA0B,EAC1B,QAAwB,EACxB,MAAc,EACd,IA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AAS,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,OAAO;YACH,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;YAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;SACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;CACJ;AA1ID,sDA0IC","sourcesContent":["import { ApiSpec, OperationInfo, ResponseInfo } from '../spec/ApiSpec';\nimport { CardRenderer } from './CardRenderer';\nimport { CodeSampleBuilder } from '../samples/CodeSamples';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\nimport { FieldTreeBuilder } from '../spec/FieldTree';\nimport { FieldTreeRenderer } from './FieldTreeRenderer';\nimport { HeaderListRenderer } from './HeaderListRenderer';\nimport { Html } from './Html';\nimport { JsonNode } from '../spec/JsonNode';\nimport { Layout } from './Layout';\nimport { Markdown } from '../markdown/Markdown';\nimport { SiteUrls } from './SiteUrls';\nimport { SitePage } from './SitePage';\n\n/** The badge a webhook carries everywhere it appears. */\nexport const WEBHOOK_BADGE = 'WEBHOOK';\n\n/**\n * One pre-rendered page per operation, at `reference/<kebab-operation>/index.html`.\n *\n * ## What a WEBHOOK page leaves out, and why\n *\n * No method, no path, no code samples. The url is the PARTNER's — they host the endpoint wherever\n * they choose — so a `POST https://api.example.com/...` sample on a webhook page invites them to\n * call something that does not exist. What it keeps is the payload, because the payload is the part\n * that IS ours, and the event name, because that is what they match on the wire.\n */\nexport class OperationPageRenderer {\n private readonly html = new Html();\n\n constructor(\n private readonly spec: ApiSpec,\n private readonly fields: FieldTreeBuilder,\n private readonly trees: FieldTreeRenderer,\n private readonly markdown: Markdown,\n private readonly cards: CardRenderer,\n private readonly samples: CodeSampleBuilder,\n private readonly examples: ExampleBuilder,\n private readonly layout: Layout,\n private readonly urls: SiteUrls,\n private readonly headers: HeaderListRenderer,\n ) {}\n\n page(operation: OperationInfo): SitePage {\n const url = this.urls.operation(operation);\n const prefix = this.urls.prefixFor(url);\n return new SitePage(\n url,\n operation.name,\n this.layout.render(\n url,\n operation.name,\n this.body(operation, prefix),\n this.cardColumn(operation),\n ),\n );\n }\n\n private body(operation: OperationInfo, prefix: string): string {\n const parts = [this.head(operation), `<h1>${this.html.escape(operation.name)}</h1>`];\n if (operation.description !== '') {\n parts.push(this.markdown.forPage(prefix).render(operation.description));\n }\n parts.push(this.requestSection(operation, prefix));\n parts.push(this.responseSection(operation, prefix));\n return parts.join('\\n');\n }\n\n /**\n * The badge, the path (or event) and the `operationId`. The page HEADING is the operation's\n * summary (#1296); the operationId stays visible here because it is what a generated client names\n * the method, which is what a developer searches their code for.\n */\n private head(operation: OperationInfo): string {\n const id =\n operation.operationId === ''\n ? ''\n : `<code class=\"op-id\" title=\"operationId\">${this.html.escape(operation.operationId)}</code>`;\n if (operation.isWebhook) {\n return `<div class=\"op-head\"><span class=\"badge\">${WEBHOOK_BADGE}</span><code class=\"op-path\">${this.html.escape(operation.eventName)}</code>${id}</div>`;\n }\n return `<div class=\"op-head\"><span class=\"badge\">${this.html.escape(operation.httpMethod)}</span><code class=\"op-path\">${this.html.escape(operation.path)}</code>${id}</div>`;\n }\n\n /** The request's `in: \"header\"` parameters, then its body — each only when there is one. */\n private requestSection(operation: OperationInfo, prefix: string): string {\n const parts: string[] = [];\n if (operation.requestHeaders.length > 0) {\n parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders, prefix)}`);\n }\n if (operation.requestSchema !== undefined) {\n parts.push(`<h2>Request body</h2>${this.tree(operation.requestSchema, prefix)}`);\n }\n return parts.join('');\n }\n\n private responseSection(operation: OperationInfo, prefix: string): string {\n if (operation.responses.length === 0) {\n return '';\n }\n const blocks = operation.responses\n .map((response: ResponseInfo): string => this.response(response, prefix))\n .join('');\n return `<h2>Responses</h2>${blocks}`;\n }\n\n private response(response: ResponseInfo, prefix: string): string {\n // Inline markdown: a `{@link}` in `@returns` arrives as a code span, and may link (#1284).\n const summary = `${this.html.escape(response.status)} — ${this.markdown.forPage(prefix).inline(response.description)}`;\n const body =\n response.schema === undefined\n ? '<p class=\"field-doc\">No body.</p>'\n : this.tree(response.schema, prefix);\n // The headers ride the card beside the body (#1292) — the response a partner holds carries both.\n const headers = this.headers.render(response.headers, prefix);\n return `<details class=\"disclosure\" open><summary>${summary}</summary>${headers}${body}</details>`;\n }\n\n /**\n * A `oneOf` renders as expanded variants; anything else renders as one flat field tree. An INLINE\n * body (#1303) is headed by its `title` and `description` first: it has no schema page, so this\n * page is the only place a reader can see the name a generated client gives it, or its prose.\n */\n private tree(schema: JsonNode, prefix: string): string {\n return this.inlineHead(schema) + this.fieldTree(schema, prefix);\n }\n\n private inlineHead(schema: JsonNode): string {\n const head = this.fields.inlineHeadOf(schema);\n if (head === undefined) {\n return '';\n }\n const title =\n head.title === ''\n ? ''\n : `<p class=\"body-type\"><code title=\"schema title\">${this.html.escape(head.title)}</code></p>`;\n const description =\n head.description === ''\n ? ''\n : `<div class=\"field-doc\">${this.markdown.render(head.description)}</div>`;\n return title + description;\n }\n\n private fieldTree(schema: JsonNode, prefix: string): string {\n const variants = this.fields.variantsOf(schema);\n if (variants.length > 0) {\n return this.trees.renderVariants(\n variants,\n this.fields.discriminatorPropertyOf(schema),\n prefix,\n );\n }\n return this.trees.render(this.fields.fieldsOf(schema), prefix);\n }\n\n private cardColumn(operation: OperationInfo): string {\n const payload = this.examples.render(this.examples.build(operation.requestSchema));\n if (operation.isWebhook) {\n return this.cards.example('EVENT PAYLOAD', payload);\n }\n return [\n this.cards.authorization(operation, this.spec.securitySchemes),\n this.cards.samples(this.samples.samplesFor(operation)),\n ].join('\\n');\n }\n}\n"]}
|
|
@@ -18,7 +18,6 @@ export declare const OVERVIEW_TITLE = "Overview";
|
|
|
18
18
|
* link, which is strictly worse than the unresolved type name it replaced.
|
|
19
19
|
*/
|
|
20
20
|
export declare class SiteRenderer {
|
|
21
|
-
private readonly markdown;
|
|
22
21
|
private readonly cards;
|
|
23
22
|
private readonly html;
|
|
24
23
|
private readonly urls;
|
|
@@ -8,6 +8,7 @@ const FieldTree_1 = require("../spec/FieldTree");
|
|
|
8
8
|
const FieldTreeRenderer_1 = require("./FieldTreeRenderer");
|
|
9
9
|
const Html_1 = require("./Html");
|
|
10
10
|
const Layout_1 = require("./Layout");
|
|
11
|
+
const CodeLinks_1 = require("../markdown/CodeLinks");
|
|
11
12
|
const Markdown_1 = require("../markdown/Markdown");
|
|
12
13
|
const NavModel_1 = require("./NavModel");
|
|
13
14
|
const HeaderListRenderer_1 = require("./HeaderListRenderer");
|
|
@@ -34,30 +35,32 @@ exports.OVERVIEW_TITLE = 'Overview';
|
|
|
34
35
|
* link, which is strictly worse than the unresolved type name it replaced.
|
|
35
36
|
*/
|
|
36
37
|
class SiteRenderer {
|
|
37
|
-
markdown = new Markdown_1.Markdown();
|
|
38
38
|
cards = new CardRenderer_1.CardRenderer();
|
|
39
39
|
html = new Html_1.Html();
|
|
40
40
|
urls = new SiteUrls_1.SiteUrls();
|
|
41
41
|
/** @param spec the document. @param prose the manifest's pages, in the manifest's order. */
|
|
42
42
|
render(spec, prose, titleOverride) {
|
|
43
43
|
const lens = new SchemaLens_1.SchemaLens(spec);
|
|
44
|
+
// A code span naming an operation or a schema links to its page (#1284); bound at the site
|
|
45
|
+
// root, and re-bound per page with `forPage`.
|
|
46
|
+
const markdown = new Markdown_1.Markdown(CodeLinks_1.CodeLinks.of(spec, this.urls), '');
|
|
44
47
|
const fields = new FieldTree_1.FieldTreeBuilder(lens);
|
|
45
|
-
const trees = new FieldTreeRenderer_1.FieldTreeRenderer(
|
|
48
|
+
const trees = new FieldTreeRenderer_1.FieldTreeRenderer(markdown, this.urls);
|
|
46
49
|
const examples = new ExampleBuilder_1.ExampleBuilder(lens);
|
|
47
50
|
const title = titleOverride === '' ? spec.title : titleOverride;
|
|
48
51
|
const nav = new NavModel_1.NavBuilder(this.urls).build(spec, prose, exports.OVERVIEW_TITLE);
|
|
49
52
|
const layout = new Layout_1.Layout(nav, this.urls, title, spec.version);
|
|
50
|
-
const operations = new OperationPageRenderer_1.OperationPageRenderer(spec, fields, trees,
|
|
51
|
-
const pages = [this.overview(spec, layout)];
|
|
53
|
+
const operations = new OperationPageRenderer_1.OperationPageRenderer(spec, fields, trees, markdown, this.cards, new CodeSamples_1.CodeSampleBuilder(spec, examples), examples, layout, this.urls, new HeaderListRenderer_1.HeaderListRenderer(lens, markdown));
|
|
54
|
+
const pages = [this.overview(spec, layout, markdown)];
|
|
52
55
|
for (const page of prose) {
|
|
53
|
-
pages.push(this.prosePage(page, layout));
|
|
56
|
+
pages.push(this.prosePage(page, layout, markdown));
|
|
54
57
|
}
|
|
55
58
|
for (const operation of spec.operations()) {
|
|
56
59
|
pages.push(operations.page(operation));
|
|
57
60
|
}
|
|
58
61
|
for (const schema of spec.schemas) {
|
|
59
62
|
if (schema.hasOwnPage) {
|
|
60
|
-
pages.push(this.schemaPage(schema, fields, trees, examples, layout));
|
|
63
|
+
pages.push(this.schemaPage(schema, fields, trees, examples, layout, markdown));
|
|
61
64
|
}
|
|
62
65
|
}
|
|
63
66
|
return new SitePage_1.RenderedSite(pages, this.assets());
|
|
@@ -69,25 +72,25 @@ class SiteRenderer {
|
|
|
69
72
|
new SitePage_1.SiteAsset('site.js', SiteScript_1.SiteScript.JS),
|
|
70
73
|
];
|
|
71
74
|
}
|
|
72
|
-
overview(spec, layout) {
|
|
75
|
+
overview(spec, layout, markdown) {
|
|
73
76
|
const parts = [`<h1>${this.html.escape(spec.title)}</h1>`];
|
|
74
77
|
if (spec.summary !== '') {
|
|
75
78
|
parts.push(`<p class="api-summary">${this.html.escape(spec.summary)}</p>`);
|
|
76
79
|
}
|
|
77
80
|
if (spec.description !== '') {
|
|
78
|
-
parts.push(
|
|
81
|
+
parts.push(markdown.render(spec.description));
|
|
79
82
|
}
|
|
80
|
-
parts.push(this.sectionIndex(spec));
|
|
83
|
+
parts.push(this.sectionIndex(spec, markdown));
|
|
81
84
|
const url = this.urls.home();
|
|
82
85
|
return new SitePage_1.SitePage(url, exports.OVERVIEW_TITLE, layout.render(url, exports.OVERVIEW_TITLE, parts.join('\n'), this.serversCard(spec)));
|
|
83
86
|
}
|
|
84
|
-
sectionIndex(spec) {
|
|
87
|
+
sectionIndex(spec, markdown) {
|
|
85
88
|
return spec.sections
|
|
86
89
|
.map((section) => {
|
|
87
90
|
const items = section.operations
|
|
88
91
|
.map((operation) => `<li>${this.html.link(this.urls.operation(operation), operation.name)}</li>`)
|
|
89
92
|
.join('');
|
|
90
|
-
return `<h2>${this.html.escape(section.name)}</h2>${
|
|
93
|
+
return `<h2>${this.html.escape(section.name)}</h2>${markdown.render(section.description)}<ul>${items}</ul>`;
|
|
91
94
|
})
|
|
92
95
|
.join('\n');
|
|
93
96
|
}
|
|
@@ -100,18 +103,18 @@ class SiteRenderer {
|
|
|
100
103
|
.join('');
|
|
101
104
|
return this.cards.panel('SERVERS', rows);
|
|
102
105
|
}
|
|
103
|
-
prosePage(page, layout) {
|
|
106
|
+
prosePage(page, layout, markdown) {
|
|
104
107
|
const url = this.urls.prose(page);
|
|
105
|
-
const body = `<h1>${this.html.escape(page.title)}</h1>${this.
|
|
108
|
+
const body = `<h1>${this.html.escape(page.title)}</h1>${markdown.forPage(this.urls.prefixFor(url)).render(page.markdown)}`;
|
|
106
109
|
return new SitePage_1.SitePage(url, page.title, layout.render(url, page.title, body, ''));
|
|
107
110
|
}
|
|
108
|
-
schemaPage(schema, fields, trees, examples, layout) {
|
|
111
|
+
schemaPage(schema, fields, trees, examples, layout, markdown) {
|
|
109
112
|
const url = this.urls.schema(schema);
|
|
110
113
|
const prefix = this.urls.prefixFor(url);
|
|
111
114
|
const parts = [`<h1>${this.html.escape(schema.name)}</h1>`];
|
|
112
115
|
const description = schema.node.text('description');
|
|
113
116
|
if (description !== undefined) {
|
|
114
|
-
parts.push(
|
|
117
|
+
parts.push(markdown.forPage(prefix).render(description));
|
|
115
118
|
}
|
|
116
119
|
const variants = fields.variantsOf(schema.node);
|
|
117
120
|
parts.push(variants.length > 0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SiteRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/SiteRenderer.ts"],"names":[],"mappings":";;;AACA,iDAA8C;AAC9C,wDAA2D;AAC3D,2DAAwD;AACxD,iDAAqD;AACrD,2DAAwD;AACxD,iCAA8B;AAC9B,qCAAkC;AAClC,mDAAgD;AAChD,yCAAwC;AACxC,6DAA0D;AAC1D,mEAAgE;AAEhE,yCAA+D;AAC/D,mDAAgD;AAChD,qDAAkD;AAClD,qDAAkD;AAClD,yCAAsC;AAEtC,gDAAgD;AACnC,QAAA,cAAc,GAAG,UAAU,CAAC;AAEzC;;;;;;;;;;;;;GAaG;AACH,MAAa,YAAY;IACJ,QAAQ,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAC1B,KAAK,GAAG,IAAI,2BAAY,EAAE,CAAC;IAC3B,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAClB,IAAI,GAAG,IAAI,mBAAQ,EAAE,CAAC;IAEvC,4FAA4F;IAC5F,MAAM,CAAC,IAAa,EAAE,KAA2B,EAAE,aAAqB;QACpE,MAAM,IAAI,GAAG,IAAI,uBAAU,CAAC,IAAI,CAAC,CAAC;QAClC,MAAM,MAAM,GAAG,IAAI,4BAAgB,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,qCAAiB,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9D,MAAM,QAAQ,GAAG,IAAI,+BAAc,CAAC,IAAI,CAAC,CAAC;QAC1C,MAAM,KAAK,GAAG,aAAa,KAAK,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,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AC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,OAAO,IAAI,mBAAQ,CACf,GAAG,EACH,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,MAAM,CACT,GAAG,EACH,MAAM,CAAC,IAAI,EACX,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAChB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CACxC,CACJ,CAAC;IACN,CAAC;CACJ;AAxID,oCAwIC","sourcesContent":["import { ApiSpec, NamedSchema, OperationInfo, ServerInfo, TagSection } from '../spec/ApiSpec';\nimport { CardRenderer } from './CardRenderer';\nimport { CodeSampleBuilder } from '../samples/CodeSamples';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\nimport { FieldTreeBuilder } from '../spec/FieldTree';\nimport { FieldTreeRenderer } from './FieldTreeRenderer';\nimport { Html } from './Html';\nimport { Layout } from './Layout';\nimport { Markdown } from '../markdown/Markdown';\nimport { NavBuilder } from './NavModel';\nimport { HeaderListRenderer } from './HeaderListRenderer';\nimport { OperationPageRenderer } from './OperationPageRenderer';\nimport { ProsePage } from '../manifest/DocsManifest';\nimport { RenderedSite, SiteAsset, SitePage } from './SitePage';\nimport { SchemaLens } from '../spec/SchemaLens';\nimport { SiteScript } from '../assets/SiteScript';\nimport { SiteStyles } from '../assets/SiteStyles';\nimport { SiteUrls } from './SiteUrls';\n\n/** The nav title of the generated home page. */\nexport const OVERVIEW_TITLE = 'Overview';\n\n/**\n * Turns one {@link ApiSpec} plus its prose into the complete list of files to write.\n *\n * Every URL is a FILE — `index.html`, `prose/<slug>/index.html`, `reference/<slug>/index.html`,\n * `schemas/<slug>/index.html` — so a deep link resolves without JS, the output is a folder any\n * static host serves, and a JSDoc edit is a diff on the one page it affects.\n *\n * ## One page per named object DTO\n *\n * Only OBJECTS get pages. A named enum or scalar alias renders inline at each use site with its\n * chips, because a page holding one line of values costs a reader the context they were reading.\n * An UNDEFINED `$ref` also stays inline — a link to a page the document never defined is a dead\n * link, which is strictly worse than the unresolved type name it replaced.\n */\nexport class SiteRenderer {\n private readonly markdown = new Markdown();\n private readonly cards = new CardRenderer();\n private readonly html = new Html();\n private readonly urls = new SiteUrls();\n\n /** @param spec the document. @param prose the manifest's pages, in the manifest's order. */\n render(spec: ApiSpec, prose: readonly ProsePage[], titleOverride: string): RenderedSite {\n const lens = new SchemaLens(spec);\n const fields = new FieldTreeBuilder(lens);\n const trees = new FieldTreeRenderer(this.markdown, this.urls);\n const examples = new ExampleBuilder(lens);\n const title = titleOverride === '' ? spec.title : titleOverride;\n const nav = new NavBuilder(this.urls).build(spec, prose, OVERVIEW_TITLE);\n const layout = new Layout(nav, this.urls, title, spec.version);\n const operations = new OperationPageRenderer(\n spec,\n fields,\n trees,\n this.markdown,\n this.cards,\n new CodeSampleBuilder(spec, examples),\n examples,\n layout,\n this.urls,\n new HeaderListRenderer(lens, this.markdown),\n );\n const pages: SitePage[] = [this.overview(spec, layout)];\n for (const page of prose) {\n pages.push(this.prosePage(page, layout));\n }\n for (const operation of spec.operations()) {\n pages.push(operations.page(operation));\n }\n for (const schema of spec.schemas) {\n if (schema.hasOwnPage) {\n pages.push(this.schemaPage(schema, fields, trees, examples, layout));\n }\n }\n return new RenderedSite(pages, this.assets());\n }\n\n /** The stylesheet and the script, written beside the pages. */\n assets(): readonly SiteAsset[] {\n return [\n new SiteAsset('styles.css', SiteStyles.CSS),\n new SiteAsset('site.js', SiteScript.JS),\n ];\n }\n\n private overview(spec: ApiSpec, layout: Layout): SitePage {\n const parts = [`<h1>${this.html.escape(spec.title)}</h1>`];\n if (spec.summary !== '') {\n parts.push(`<p class=\"api-summary\">${this.html.escape(spec.summary)}</p>`);\n }\n if (spec.description !== '') {\n parts.push(this.markdown.render(spec.description));\n }\n parts.push(this.sectionIndex(spec));\n const url = this.urls.home();\n return new SitePage(\n url,\n OVERVIEW_TITLE,\n layout.render(url, OVERVIEW_TITLE, parts.join('\\n'), this.serversCard(spec)),\n );\n }\n\n private sectionIndex(spec: ApiSpec): string {\n return spec.sections\n .map((section: TagSection): string => {\n const items = section.operations\n .map(\n (operation: OperationInfo): string =>\n `<li>${this.html.link(this.urls.operation(operation), operation.name)}</li>`,\n )\n .join('');\n return `<h2>${this.html.escape(section.name)}</h2>${this.markdown.render(section.description)}<ul>${items}</ul>`;\n })\n .join('\\n');\n }\n\n private serversCard(spec: ApiSpec): string {\n if (spec.servers.length === 0) {\n return '';\n }\n const rows = spec.servers\n .map(\n (server: ServerInfo): string =>\n `<div class=\"field\"><div class=\"field-head\"><span class=\"field-name\">${this.html.escape(server.url)}</span></div><div class=\"field-doc\">${this.html.escape(server.description ?? '')}</div></div>`,\n )\n .join('');\n return this.cards.panel('SERVERS', rows);\n }\n\n private prosePage(page: ProsePage, layout: Layout): SitePage {\n const url = this.urls.prose(page);\n const body = `<h1>${this.html.escape(page.title)}</h1>${this.markdown.render(page.markdown)}`;\n return new SitePage(url, page.title, layout.render(url, page.title, body, ''));\n }\n\n private schemaPage(\n schema: NamedSchema,\n fields: FieldTreeBuilder,\n trees: FieldTreeRenderer,\n examples: ExampleBuilder,\n layout: Layout,\n ): SitePage {\n const url = this.urls.schema(schema);\n const prefix = this.urls.prefixFor(url);\n const parts = [`<h1>${this.html.escape(schema.name)}</h1>`];\n const description = schema.node.text('description');\n if (description !== undefined) {\n parts.push(this.markdown.render(description));\n }\n const variants = fields.variantsOf(schema.node);\n parts.push(\n variants.length > 0\n ? trees.renderVariants(\n variants,\n fields.discriminatorPropertyOf(schema.node),\n prefix,\n )\n : trees.render(fields.fieldsOf(schema.node), prefix),\n );\n const sample = examples.render(examples.build(schema.node));\n return new SitePage(\n url,\n schema.name,\n layout.render(\n url,\n schema.name,\n parts.join('\\n'),\n this.cards.example('EXAMPLE', sample),\n ),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SiteRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/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AQ,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,OAAO,IAAI,mBAAQ,CACf,GAAG,EACH,MAAM,CAAC,IAAI,EACX,MAAM,CAAC,MAAM,CACT,GAAG,EACH,MAAM,CAAC,IAAI,EACX,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAChB,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,CACxC,CACJ,CAAC;IACN,CAAC;CACJ;AA3ID,oCA2IC","sourcesContent":["import { ApiSpec, NamedSchema, OperationInfo, ServerInfo, TagSection } from '../spec/ApiSpec';\nimport { CardRenderer } from './CardRenderer';\nimport { CodeSampleBuilder } from '../samples/CodeSamples';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\nimport { FieldTreeBuilder } from '../spec/FieldTree';\nimport { FieldTreeRenderer } from './FieldTreeRenderer';\nimport { Html } from './Html';\nimport { Layout } from './Layout';\nimport { CodeLinks } from '../markdown/CodeLinks';\nimport { Markdown } from '../markdown/Markdown';\nimport { NavBuilder } from './NavModel';\nimport { HeaderListRenderer } from './HeaderListRenderer';\nimport { OperationPageRenderer } from './OperationPageRenderer';\nimport { ProsePage } from '../manifest/DocsManifest';\nimport { RenderedSite, SiteAsset, SitePage } from './SitePage';\nimport { SchemaLens } from '../spec/SchemaLens';\nimport { SiteScript } from '../assets/SiteScript';\nimport { SiteStyles } from '../assets/SiteStyles';\nimport { SiteUrls } from './SiteUrls';\n\n/** The nav title of the generated home page. */\nexport const OVERVIEW_TITLE = 'Overview';\n\n/**\n * Turns one {@link ApiSpec} plus its prose into the complete list of files to write.\n *\n * Every URL is a FILE — `index.html`, `prose/<slug>/index.html`, `reference/<slug>/index.html`,\n * `schemas/<slug>/index.html` — so a deep link resolves without JS, the output is a folder any\n * static host serves, and a JSDoc edit is a diff on the one page it affects.\n *\n * ## One page per named object DTO\n *\n * Only OBJECTS get pages. A named enum or scalar alias renders inline at each use site with its\n * chips, because a page holding one line of values costs a reader the context they were reading.\n * An UNDEFINED `$ref` also stays inline — a link to a page the document never defined is a dead\n * link, which is strictly worse than the unresolved type name it replaced.\n */\nexport class SiteRenderer {\n private readonly cards = new CardRenderer();\n private readonly html = new Html();\n private readonly urls = new SiteUrls();\n\n /** @param spec the document. @param prose the manifest's pages, in the manifest's order. */\n render(spec: ApiSpec, prose: readonly ProsePage[], titleOverride: string): RenderedSite {\n const lens = new SchemaLens(spec);\n // A code span naming an operation or a schema links to its page (#1284); bound at the site\n // root, and re-bound per page with `forPage`.\n const markdown = new Markdown(CodeLinks.of(spec, this.urls), '');\n const fields = new FieldTreeBuilder(lens);\n const trees = new FieldTreeRenderer(markdown, this.urls);\n const examples = new ExampleBuilder(lens);\n const title = titleOverride === '' ? spec.title : titleOverride;\n const nav = new NavBuilder(this.urls).build(spec, prose, OVERVIEW_TITLE);\n const layout = new Layout(nav, this.urls, title, spec.version);\n const operations = new OperationPageRenderer(\n spec,\n fields,\n trees,\n markdown,\n this.cards,\n new CodeSampleBuilder(spec, examples),\n examples,\n layout,\n this.urls,\n new HeaderListRenderer(lens, markdown),\n );\n const pages: SitePage[] = [this.overview(spec, layout, markdown)];\n for (const page of prose) {\n pages.push(this.prosePage(page, layout, markdown));\n }\n for (const operation of spec.operations()) {\n pages.push(operations.page(operation));\n }\n for (const schema of spec.schemas) {\n if (schema.hasOwnPage) {\n pages.push(this.schemaPage(schema, fields, trees, examples, layout, markdown));\n }\n }\n return new RenderedSite(pages, this.assets());\n }\n\n /** The stylesheet and the script, written beside the pages. */\n assets(): readonly SiteAsset[] {\n return [\n new SiteAsset('styles.css', SiteStyles.CSS),\n new SiteAsset('site.js', SiteScript.JS),\n ];\n }\n\n private overview(spec: ApiSpec, layout: Layout, markdown: Markdown): SitePage {\n const parts = [`<h1>${this.html.escape(spec.title)}</h1>`];\n if (spec.summary !== '') {\n parts.push(`<p class=\"api-summary\">${this.html.escape(spec.summary)}</p>`);\n }\n if (spec.description !== '') {\n parts.push(markdown.render(spec.description));\n }\n parts.push(this.sectionIndex(spec, markdown));\n const url = this.urls.home();\n return new SitePage(\n url,\n OVERVIEW_TITLE,\n layout.render(url, OVERVIEW_TITLE, parts.join('\\n'), this.serversCard(spec)),\n );\n }\n\n private sectionIndex(spec: ApiSpec, markdown: Markdown): string {\n return spec.sections\n .map((section: TagSection): string => {\n const items = section.operations\n .map(\n (operation: OperationInfo): string =>\n `<li>${this.html.link(this.urls.operation(operation), operation.name)}</li>`,\n )\n .join('');\n return `<h2>${this.html.escape(section.name)}</h2>${markdown.render(section.description)}<ul>${items}</ul>`;\n })\n .join('\\n');\n }\n\n private serversCard(spec: ApiSpec): string {\n if (spec.servers.length === 0) {\n return '';\n }\n const rows = spec.servers\n .map(\n (server: ServerInfo): string =>\n `<div class=\"field\"><div class=\"field-head\"><span class=\"field-name\">${this.html.escape(server.url)}</span></div><div class=\"field-doc\">${this.html.escape(server.description ?? '')}</div></div>`,\n )\n .join('');\n return this.cards.panel('SERVERS', rows);\n }\n\n private prosePage(page: ProsePage, layout: Layout, markdown: Markdown): SitePage {\n const url = this.urls.prose(page);\n const body = `<h1>${this.html.escape(page.title)}</h1>${markdown.forPage(this.urls.prefixFor(url)).render(page.markdown)}`;\n return new SitePage(url, page.title, layout.render(url, page.title, body, ''));\n }\n\n private schemaPage(\n schema: NamedSchema,\n fields: FieldTreeBuilder,\n trees: FieldTreeRenderer,\n examples: ExampleBuilder,\n layout: Layout,\n markdown: Markdown,\n ): SitePage {\n const url = this.urls.schema(schema);\n const prefix = this.urls.prefixFor(url);\n const parts = [`<h1>${this.html.escape(schema.name)}</h1>`];\n const description = schema.node.text('description');\n if (description !== undefined) {\n parts.push(markdown.forPage(prefix).render(description));\n }\n const variants = fields.variantsOf(schema.node);\n parts.push(\n variants.length > 0\n ? trees.renderVariants(\n variants,\n fields.discriminatorPropertyOf(schema.node),\n prefix,\n )\n : trees.render(fields.fieldsOf(schema.node), prefix),\n );\n const sample = examples.render(examples.build(schema.node));\n return new SitePage(\n url,\n schema.name,\n layout.render(\n url,\n schema.name,\n parts.join('\\n'),\n this.cards.example('EXAMPLE', sample),\n ),\n );\n }\n}\n"]}
|
package/src/spec/FieldTree.d.ts
CHANGED
|
@@ -31,6 +31,24 @@ export declare class SchemaVariant {
|
|
|
31
31
|
readonly fields: readonly FieldNode[];
|
|
32
32
|
constructor(label: string, discriminatorValue: string, fields: readonly FieldNode[]);
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* What an INLINE request or response body says about itself: its `title` and `description`.
|
|
36
|
+
*
|
|
37
|
+
* A generator may define a single-use body inline at its operation rather than as a named component
|
|
38
|
+
* (webpieces does, #1303), keeping the type's name as `title`. Such a body has no schema page, so the
|
|
39
|
+
* operation page is the only place its name and prose can appear.
|
|
40
|
+
*/
|
|
41
|
+
export declare class InlineBodyHead {
|
|
42
|
+
/** The schema's `title` — the name a generated client gives the model. Empty when absent. */
|
|
43
|
+
readonly title: string;
|
|
44
|
+
/** The schema's `description`. Empty when absent. */
|
|
45
|
+
readonly description: string;
|
|
46
|
+
constructor(
|
|
47
|
+
/** The schema's `title` — the name a generated client gives the model. Empty when absent. */
|
|
48
|
+
title: string,
|
|
49
|
+
/** The schema's `description`. Empty when absent. */
|
|
50
|
+
description: string);
|
|
51
|
+
}
|
|
34
52
|
/**
|
|
35
53
|
* Builds the parameter tree.
|
|
36
54
|
*
|
|
@@ -54,6 +72,11 @@ export declare class FieldTreeBuilder {
|
|
|
54
72
|
constructor(lens: SchemaLens);
|
|
55
73
|
/** The fields of a schema — its own, plus every `allOf` branch's, in declaration order. */
|
|
56
74
|
fieldsOf(schema: JsonNode): readonly FieldNode[];
|
|
75
|
+
/**
|
|
76
|
+
* The title and description of a body schema written INLINE — `undefined` for a reference (whose
|
|
77
|
+
* prose lives on the referenced schema's own page) and for an inline schema stating neither.
|
|
78
|
+
*/
|
|
79
|
+
inlineHeadOf(schema: JsonNode): InlineBodyHead | undefined;
|
|
57
80
|
/**
|
|
58
81
|
* The `oneOf` branches of a schema, labelled by the discriminator value that selects each one.
|
|
59
82
|
* Empty when the schema is not a union, which is what tells a renderer to draw one flat tree.
|
package/src/spec/FieldTree.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FieldTreeBuilder = exports.SchemaVariant = exports.FieldNode = void 0;
|
|
3
|
+
exports.FieldTreeBuilder = exports.InlineBodyHead = exports.SchemaVariant = exports.FieldNode = void 0;
|
|
4
4
|
const SchemaShape_1 = require("./SchemaShape");
|
|
5
5
|
/**
|
|
6
6
|
* One row of the parameter tree: the field name, the type label, the prose, and — for an enum — the
|
|
@@ -45,6 +45,26 @@ class SchemaVariant {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
exports.SchemaVariant = SchemaVariant;
|
|
48
|
+
/**
|
|
49
|
+
* What an INLINE request or response body says about itself: its `title` and `description`.
|
|
50
|
+
*
|
|
51
|
+
* A generator may define a single-use body inline at its operation rather than as a named component
|
|
52
|
+
* (webpieces does, #1303), keeping the type's name as `title`. Such a body has no schema page, so the
|
|
53
|
+
* operation page is the only place its name and prose can appear.
|
|
54
|
+
*/
|
|
55
|
+
class InlineBodyHead {
|
|
56
|
+
title;
|
|
57
|
+
description;
|
|
58
|
+
constructor(
|
|
59
|
+
/** The schema's `title` — the name a generated client gives the model. Empty when absent. */
|
|
60
|
+
title,
|
|
61
|
+
/** The schema's `description`. Empty when absent. */
|
|
62
|
+
description) {
|
|
63
|
+
this.title = title;
|
|
64
|
+
this.description = description;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.InlineBodyHead = InlineBodyHead;
|
|
48
68
|
/**
|
|
49
69
|
* Builds the parameter tree.
|
|
50
70
|
*
|
|
@@ -81,6 +101,21 @@ class FieldTreeBuilder {
|
|
|
81
101
|
}
|
|
82
102
|
return fields;
|
|
83
103
|
}
|
|
104
|
+
/**
|
|
105
|
+
* The title and description of a body schema written INLINE — `undefined` for a reference (whose
|
|
106
|
+
* prose lives on the referenced schema's own page) and for an inline schema stating neither.
|
|
107
|
+
*/
|
|
108
|
+
inlineHeadOf(schema) {
|
|
109
|
+
if (this.lens.refTargetOf(schema) !== undefined) {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const title = schema.text('title') ?? '';
|
|
113
|
+
const description = schema.text('description') ?? '';
|
|
114
|
+
if (title === '' && description === '') {
|
|
115
|
+
return undefined;
|
|
116
|
+
}
|
|
117
|
+
return new InlineBodyHead(title, description);
|
|
118
|
+
}
|
|
84
119
|
/**
|
|
85
120
|
* The `oneOf` branches of a schema, labelled by the discriminator value that selects each one.
|
|
86
121
|
* Empty when the schema is not a union, which is what tells a renderer to draw one flat tree.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldTree.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/spec/FieldTree.ts"],"names":[],"mappings":";;;AAGA,+CAA4C;AAE5C;;;GAGG;AACH,MAAa,SAAS;IAEL;IACA;IACA;IACA;IACA;IAEA;IACA;IARb,YACa,IAAY,EACZ,SAAiB,EACjB,WAAmB,EACnB,QAAiB,EACjB,cAAiC;IAC1C,8FAA8F;IACrF,MAA+B,EAC/B,QAA8B;QAP9B,SAAI,GAAJ,IAAI,CAAQ;QACZ,cAAS,GAAT,SAAS,CAAQ;QACjB,gBAAW,GAAX,WAAW,CAAQ;QACnB,aAAQ,GAAR,QAAQ,CAAS;QACjB,mBAAc,GAAd,cAAc,CAAmB;QAEjC,WAAM,GAAN,MAAM,CAAyB;QAC/B,aAAQ,GAAR,QAAQ,CAAsB;IACxC,CAAC;CACP;AAXD,8BAWC;AAED;;;;;;GAMG;AACH,MAAa,aAAa;IAET;IACA;IACA;IAHb,YACa,KAAa,EACb,kBAA0B,EAC1B,MAA4B;QAF5B,UAAK,GAAL,KAAK,CAAQ;QACb,uBAAkB,GAAlB,kBAAkB,CAA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,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,CAAC;QACD,IAAI,QAAQ,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;IAEO,eAAe,CAAC,MAAgB;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAC5B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACrB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA5GD,4CA4GC","sourcesContent":["import { JsonEntry, JsonNode } from './JsonNode';\nimport { NamedSchema } from './ApiSpec';\nimport { SchemaLens } from './SchemaLens';\nimport { SchemaShape } from './SchemaShape';\n\n/**\n * One row of the parameter tree: the field name, the type label, the prose, and — for an enum — the\n * COMPLETE list of possible values. All four are read from the spec; none is authored here.\n */\nexport class FieldNode {\n constructor(\n readonly name: string,\n readonly typeLabel: string,\n readonly description: string,\n readonly required: boolean,\n readonly possibleValues: readonly string[],\n /** The named object this field's type is, when it has a page of its own. Else `undefined`. */\n readonly linkTo: NamedSchema | undefined,\n readonly children: readonly FieldNode[],\n ) {}\n}\n\n/**\n * One branch of a `oneOf` request body, keyed by its discriminator value.\n *\n * Every branch renders EXPANDED, one after another, rather than behind tabs. A partner writing one\n * handler needs every shape at once — and a tab is invisible to Ctrl-F and to print, so the shapes\n * behind the unselected tabs are, for a reader searching the page, simply not documented.\n */\nexport class SchemaVariant {\n constructor(\n readonly label: string,\n readonly discriminatorValue: string,\n readonly fields: readonly FieldNode[],\n ) {}\n}\n\n/**\n * Builds the parameter tree.\n *\n * ## Two trees on purpose: links here, full resolution in the example\n *\n * Every reference to a named OBJECT renders as a LINK to that object's own page, and the field's\n * children are NOT inlined underneath it — the link IS the expansion. The generated example body\n * (see `ExampleBuilder`) resolves the same references fully instead.\n *\n * Sharing one tree between them is the tempting simplification and it is wrong in both directions.\n * A hyperlink cannot live inside a JSON sample, so a shared tree that links prints `\"data\": {}` on a\n * partner's page; a shared tree that inlines gives every DTO as many copies as it has use sites, and\n * none of them is the page a reader can link to.\n *\n * A named ENUM or scalar alias is NOT linked — it renders inline with its chips, because a page\n * carrying one line of values costs the reader the context they were already reading.\n */\nexport class FieldTreeBuilder {\n private readonly shape = new SchemaShape();\n\n constructor(private readonly lens: SchemaLens) {}\n\n /** The fields of a schema — its own, plus every `allOf` branch's, in declaration order. */\n fieldsOf(schema: JsonNode): readonly FieldNode[] {\n const resolved = this.lens.resolve(schema);\n const fields: FieldNode[] = [];\n for (const branch of resolved.list('allOf')) {\n fields.push(...this.fieldsOf(branch));\n }\n const required = this.requiredNamesOf(resolved);\n for (const property of resolved.at('properties').entries()) {\n fields.push(this.fieldOf(property, required.includes(property.key)));\n }\n return fields;\n }\n\n /**\n * The `oneOf` branches of a schema, labelled by the discriminator value that selects each one.\n * Empty when the schema is not a union, which is what tells a renderer to draw one flat tree.\n */\n variantsOf(schema: JsonNode): readonly SchemaVariant[] {\n const branches = this.lens.branchesOf(schema);\n if (branches.length === 0) {\n return [];\n }\n const mapping = this.lens.resolve(schema).at('discriminator').at('mapping');\n const variants: SchemaVariant[] = [];\n for (const branch of branches) {\n const label = this.lens.label(branch);\n variants.push(\n new SchemaVariant(\n label,\n this.discriminatorValueOf(mapping, label),\n this.fieldsOf(branch),\n ),\n );\n }\n return variants;\n }\n\n /** The `propertyName` a discriminated union switches on, or the empty string when there is none. */\n discriminatorPropertyOf(schema: JsonNode): string {\n return this.lens.resolve(schema).at('discriminator').text('propertyName') ?? '';\n }\n\n private discriminatorValueOf(mapping: JsonNode, typeName: string): string {\n for (const entry of mapping.entries()) {\n const pointer = entry.value.asText();\n if (pointer !== undefined && pointer.endsWith(`/${typeName}`)) {\n return entry.key;\n }\n }\n return '';\n }\n\n private fieldOf(property: JsonEntry, required: boolean): FieldNode {\n const named = this.lens.named(property.value);\n const linked = named !== undefined && named.hasOwnPage ? named : undefined;\n return new FieldNode(\n property.key,\n this.lens.label(property.value),\n this.lens.describe(property.value),\n required,\n this.lens.enumValuesOf(property.value),\n linked ?? this.linkedItemOf(property.value),\n linked === undefined ? this.childrenOf(property.value) : [],\n );\n }\n\n /** For `array<Order>`, the page `Order` lives on — the row links, the array bracket does not. */\n private linkedItemOf(property: JsonNode): NamedSchema | undefined {\n if (this.shape.declaredType(this.lens.resolve(property)) !== 'array') {\n return undefined;\n }\n const named = this.lens.named(this.lens.resolve(property).at('items'));\n return named !== undefined && named.hasOwnPage ? named : undefined;\n }\n\n /**\n * The nested rows of an INLINE shape — an anonymous object, or an array of one. A named object\n * never gets children here; it got a link instead, which is what stops this recursing forever\n * on a self-referential DTO.\n */\n private childrenOf(property: JsonNode): readonly FieldNode[] {\n const resolved = this.lens.resolve(property);\n if (this.shape.declaredType(resolved) === 'array') {\n const items = resolved.at('items');\n return this.lens.named(items) === undefined ? this.fieldsOf(items) : [];\n }\n if (resolved.at('properties').isObject()) {\n return this.fieldsOf(resolved);\n }\n return [];\n }\n\n private requiredNamesOf(schema: JsonNode): readonly string[] {\n const names: string[] = [];\n for (const entry of schema.list('required')) {\n const name = entry.asText();\n if (name !== undefined) {\n names.push(name);\n }\n }\n return names;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"FieldTree.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/spec/FieldTree.ts"],"names":[],"mappings":";;;AAGA,+CAA4C;AAE5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Q,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC;YACnC,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5E,CAAC;QACD,IAAI,QAAQ,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;YACvC,OAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,EAAE,CAAC;IACd,CAAC;IAEO,eAAe,CAAC,MAAgB;QACpC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAC1C,MAAM,IAAI,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC;YAC5B,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;gBACrB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACrB,CAAC;QACL,CAAC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;CACJ;AA5HD,4CA4HC","sourcesContent":["import { JsonEntry, JsonNode } from './JsonNode';\nimport { NamedSchema } from './ApiSpec';\nimport { SchemaLens } from './SchemaLens';\nimport { SchemaShape } from './SchemaShape';\n\n/**\n * One row of the parameter tree: the field name, the type label, the prose, and — for an enum — the\n * COMPLETE list of possible values. All four are read from the spec; none is authored here.\n */\nexport class FieldNode {\n constructor(\n readonly name: string,\n readonly typeLabel: string,\n readonly description: string,\n readonly required: boolean,\n readonly possibleValues: readonly string[],\n /** The named object this field's type is, when it has a page of its own. Else `undefined`. */\n readonly linkTo: NamedSchema | undefined,\n readonly children: readonly FieldNode[],\n ) {}\n}\n\n/**\n * One branch of a `oneOf` request body, keyed by its discriminator value.\n *\n * Every branch renders EXPANDED, one after another, rather than behind tabs. A partner writing one\n * handler needs every shape at once — and a tab is invisible to Ctrl-F and to print, so the shapes\n * behind the unselected tabs are, for a reader searching the page, simply not documented.\n */\nexport class SchemaVariant {\n constructor(\n readonly label: string,\n readonly discriminatorValue: string,\n readonly fields: readonly FieldNode[],\n ) {}\n}\n\n/**\n * What an INLINE request or response body says about itself: its `title` and `description`.\n *\n * A generator may define a single-use body inline at its operation rather than as a named component\n * (webpieces does, #1303), keeping the type's name as `title`. Such a body has no schema page, so the\n * operation page is the only place its name and prose can appear.\n */\nexport class InlineBodyHead {\n constructor(\n /** The schema's `title` — the name a generated client gives the model. Empty when absent. */\n readonly title: string,\n /** The schema's `description`. Empty when absent. */\n readonly description: string,\n ) {}\n}\n\n/**\n * Builds the parameter tree.\n *\n * ## Two trees on purpose: links here, full resolution in the example\n *\n * Every reference to a named OBJECT renders as a LINK to that object's own page, and the field's\n * children are NOT inlined underneath it — the link IS the expansion. The generated example body\n * (see `ExampleBuilder`) resolves the same references fully instead.\n *\n * Sharing one tree between them is the tempting simplification and it is wrong in both directions.\n * A hyperlink cannot live inside a JSON sample, so a shared tree that links prints `\"data\": {}` on a\n * partner's page; a shared tree that inlines gives every DTO as many copies as it has use sites, and\n * none of them is the page a reader can link to.\n *\n * A named ENUM or scalar alias is NOT linked — it renders inline with its chips, because a page\n * carrying one line of values costs the reader the context they were already reading.\n */\nexport class FieldTreeBuilder {\n private readonly shape = new SchemaShape();\n\n constructor(private readonly lens: SchemaLens) {}\n\n /** The fields of a schema — its own, plus every `allOf` branch's, in declaration order. */\n fieldsOf(schema: JsonNode): readonly FieldNode[] {\n const resolved = this.lens.resolve(schema);\n const fields: FieldNode[] = [];\n for (const branch of resolved.list('allOf')) {\n fields.push(...this.fieldsOf(branch));\n }\n const required = this.requiredNamesOf(resolved);\n for (const property of resolved.at('properties').entries()) {\n fields.push(this.fieldOf(property, required.includes(property.key)));\n }\n return fields;\n }\n\n /**\n * The title and description of a body schema written INLINE — `undefined` for a reference (whose\n * prose lives on the referenced schema's own page) and for an inline schema stating neither.\n */\n inlineHeadOf(schema: JsonNode): InlineBodyHead | undefined {\n if (this.lens.refTargetOf(schema) !== undefined) {\n return undefined;\n }\n const title = schema.text('title') ?? '';\n const description = schema.text('description') ?? '';\n if (title === '' && description === '') {\n return undefined;\n }\n return new InlineBodyHead(title, description);\n }\n\n /**\n * The `oneOf` branches of a schema, labelled by the discriminator value that selects each one.\n * Empty when the schema is not a union, which is what tells a renderer to draw one flat tree.\n */\n variantsOf(schema: JsonNode): readonly SchemaVariant[] {\n const branches = this.lens.branchesOf(schema);\n if (branches.length === 0) {\n return [];\n }\n const mapping = this.lens.resolve(schema).at('discriminator').at('mapping');\n const variants: SchemaVariant[] = [];\n for (const branch of branches) {\n const label = this.lens.label(branch);\n variants.push(\n new SchemaVariant(\n label,\n this.discriminatorValueOf(mapping, label),\n this.fieldsOf(branch),\n ),\n );\n }\n return variants;\n }\n\n /** The `propertyName` a discriminated union switches on, or the empty string when there is none. */\n discriminatorPropertyOf(schema: JsonNode): string {\n return this.lens.resolve(schema).at('discriminator').text('propertyName') ?? '';\n }\n\n private discriminatorValueOf(mapping: JsonNode, typeName: string): string {\n for (const entry of mapping.entries()) {\n const pointer = entry.value.asText();\n if (pointer !== undefined && pointer.endsWith(`/${typeName}`)) {\n return entry.key;\n }\n }\n return '';\n }\n\n private fieldOf(property: JsonEntry, required: boolean): FieldNode {\n const named = this.lens.named(property.value);\n const linked = named !== undefined && named.hasOwnPage ? named : undefined;\n return new FieldNode(\n property.key,\n this.lens.label(property.value),\n this.lens.describe(property.value),\n required,\n this.lens.enumValuesOf(property.value),\n linked ?? this.linkedItemOf(property.value),\n linked === undefined ? this.childrenOf(property.value) : [],\n );\n }\n\n /** For `array<Order>`, the page `Order` lives on — the row links, the array bracket does not. */\n private linkedItemOf(property: JsonNode): NamedSchema | undefined {\n if (this.shape.declaredType(this.lens.resolve(property)) !== 'array') {\n return undefined;\n }\n const named = this.lens.named(this.lens.resolve(property).at('items'));\n return named !== undefined && named.hasOwnPage ? named : undefined;\n }\n\n /**\n * The nested rows of an INLINE shape — an anonymous object, or an array of one. A named object\n * never gets children here; it got a link instead, which is what stops this recursing forever\n * on a self-referential DTO.\n */\n private childrenOf(property: JsonNode): readonly FieldNode[] {\n const resolved = this.lens.resolve(property);\n if (this.shape.declaredType(resolved) === 'array') {\n const items = resolved.at('items');\n return this.lens.named(items) === undefined ? this.fieldsOf(items) : [];\n }\n if (resolved.at('properties').isObject()) {\n return this.fieldsOf(resolved);\n }\n return [];\n }\n\n private requiredNamesOf(schema: JsonNode): readonly string[] {\n const names: string[] = [];\n for (const entry of schema.list('required')) {\n const name = entry.asText();\n if (name !== undefined) {\n names.push(name);\n }\n }\n return names;\n }\n}\n"]}
|