@webpieces/docs-site 0.4.932 → 0.4.933
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/package.json +1 -1
- package/src/assets/SiteStyles.d.ts +1 -1
- package/src/assets/SiteStyles.js +3 -0
- package/src/assets/SiteStyles.js.map +1 -1
- package/src/index.d.ts +2 -1
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/render/HeaderListRenderer.d.ts +28 -0
- package/src/render/HeaderListRenderer.js +56 -0
- package/src/render/HeaderListRenderer.js.map +1 -0
- package/src/render/OperationPageRenderer.d.ts +4 -1
- package/src/render/OperationPageRenderer.js +14 -5
- package/src/render/OperationPageRenderer.js.map +1 -1
- package/src/render/SiteRenderer.js +2 -1
- package/src/render/SiteRenderer.js.map +1 -1
- package/src/spec/ApiSpec.d.ts +35 -2
- package/src/spec/ApiSpec.js +38 -3
- package/src/spec/ApiSpec.js.map +1 -1
- package/src/spec/SpecReader.d.ts +14 -0
- package/src/spec/SpecReader.js +53 -7
- package/src/spec/SpecReader.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/docs-site",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.933",
|
|
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\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-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\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";
|
|
13
13
|
}
|
package/src/assets/SiteStyles.js
CHANGED
|
@@ -87,6 +87,9 @@ button:hover { color: var(--fg); }
|
|
|
87
87
|
.field-name { font-weight: 600; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
|
|
88
88
|
.field-type { color: var(--fg-soft); font-size: 12px; }
|
|
89
89
|
.field-required { color: #c0392b; font-size: 11px; font-weight: 700; letter-spacing: .04em; }
|
|
90
|
+
.field-optional { color: var(--fg-soft); font-size: 11px; font-weight: 700; letter-spacing: .04em; }
|
|
91
|
+
.headers { margin: 8px 0 12px; }
|
|
92
|
+
.headers-head { font-size: 12px; font-weight: 700; letter-spacing: .04em; color: var(--fg-soft); text-transform: uppercase; }
|
|
90
93
|
.field-doc { margin: 4px 0 0; color: var(--fg-soft); }
|
|
91
94
|
.field-children { margin-left: 16px; border-left: 1px solid var(--line); padding-left: 12px; }
|
|
92
95
|
.chips { margin-top: 6px; font-size: 12px; color: var(--fg-soft); }
|
|
@@ -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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2FzB,CAAC;;AA5FF,gCA6FC","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\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`;\n}\n"]}
|
package/src/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
export { DocsSiteError } from './DocsSiteError';
|
|
13
13
|
export { JsonEntry, JsonNode } from './spec/JsonNode';
|
|
14
14
|
export type { JsonMap, JsonValue } from './spec/JsonNode';
|
|
15
|
-
export { ApiSpec, NamedSchema, OperationInfo, ResponseInfo, SecuritySchemeInfo, ServerInfo, TagSection, } from './spec/ApiSpec';
|
|
15
|
+
export { ApiSpec, NamedSchema, OperationInfo, HeaderInfo, ResponseInfo, SecuritySchemeInfo, ServerInfo, TagSection, } from './spec/ApiSpec';
|
|
16
16
|
export { RefTarget, SchemaLens } from './spec/SchemaLens';
|
|
17
17
|
export { SchemaShape } from './spec/SchemaShape';
|
|
18
18
|
export { Slug } from './spec/Slug';
|
|
@@ -30,6 +30,7 @@ export { SiteUrls } from './render/SiteUrls';
|
|
|
30
30
|
export { Layout } from './render/Layout';
|
|
31
31
|
export { COLLAPSE_ALL_LABEL, CardRenderer, REQUEST_LABEL } from './render/CardRenderer';
|
|
32
32
|
export { FieldTreeRenderer, POSSIBLE_VALUES } from './render/FieldTreeRenderer';
|
|
33
|
+
export { HEADERS_HEADING, HeaderListRenderer } from './render/HeaderListRenderer';
|
|
33
34
|
export { OperationPageRenderer, WEBHOOK_BADGE } from './render/OperationPageRenderer';
|
|
34
35
|
export { RenderedSite, SiteAsset, SitePage } from './render/SitePage';
|
|
35
36
|
export { OVERVIEW_TITLE, SiteRenderer } from './render/SiteRenderer';
|
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 = void 0;
|
|
3
|
+
exports.RenderedSite = exports.WEBHOOK_BADGE = 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.Markdown = exports.ProseLoader = exports.MANIFEST_FILE = exports.ProsePageEntry = exports.ProsePage = exports.DocsManifest = exports.ExampleBuilder = exports.SchemaVariant = 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 = 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.
|
|
@@ -22,6 +22,7 @@ var ApiSpec_1 = require("./spec/ApiSpec");
|
|
|
22
22
|
Object.defineProperty(exports, "ApiSpec", { enumerable: true, get: function () { return ApiSpec_1.ApiSpec; } });
|
|
23
23
|
Object.defineProperty(exports, "NamedSchema", { enumerable: true, get: function () { return ApiSpec_1.NamedSchema; } });
|
|
24
24
|
Object.defineProperty(exports, "OperationInfo", { enumerable: true, get: function () { return ApiSpec_1.OperationInfo; } });
|
|
25
|
+
Object.defineProperty(exports, "HeaderInfo", { enumerable: true, get: function () { return ApiSpec_1.HeaderInfo; } });
|
|
25
26
|
Object.defineProperty(exports, "ResponseInfo", { enumerable: true, get: function () { return ApiSpec_1.ResponseInfo; } });
|
|
26
27
|
Object.defineProperty(exports, "SecuritySchemeInfo", { enumerable: true, get: function () { return ApiSpec_1.SecuritySchemeInfo; } });
|
|
27
28
|
Object.defineProperty(exports, "ServerInfo", { enumerable: true, get: function () { return ApiSpec_1.ServerInfo; } });
|
|
@@ -77,6 +78,9 @@ Object.defineProperty(exports, "REQUEST_LABEL", { enumerable: true, get: functio
|
|
|
77
78
|
var FieldTreeRenderer_1 = require("./render/FieldTreeRenderer");
|
|
78
79
|
Object.defineProperty(exports, "FieldTreeRenderer", { enumerable: true, get: function () { return FieldTreeRenderer_1.FieldTreeRenderer; } });
|
|
79
80
|
Object.defineProperty(exports, "POSSIBLE_VALUES", { enumerable: true, get: function () { return FieldTreeRenderer_1.POSSIBLE_VALUES; } });
|
|
81
|
+
var HeaderListRenderer_1 = require("./render/HeaderListRenderer");
|
|
82
|
+
Object.defineProperty(exports, "HEADERS_HEADING", { enumerable: true, get: function () { return HeaderListRenderer_1.HEADERS_HEADING; } });
|
|
83
|
+
Object.defineProperty(exports, "HeaderListRenderer", { enumerable: true, get: function () { return HeaderListRenderer_1.HeaderListRenderer; } });
|
|
80
84
|
var OperationPageRenderer_1 = require("./render/OperationPageRenderer");
|
|
81
85
|
Object.defineProperty(exports, "OperationPageRenderer", { enumerable: true, get: function () { return OperationPageRenderer_1.OperationPageRenderer; } });
|
|
82
86
|
Object.defineProperty(exports, "WEBHOOK_BADGE", { enumerable: true, get: function () { return OperationPageRenderer_1.WEBHOOK_BADGE; } });
|
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,
|
|
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,8CAA8E;AAArE,sGAAA,SAAS,OAAA;AAAE,6GAAA,gBAAgB,OAAA;AAAE,0GAAA,aAAa,OAAA;AACnD,wDAAuD;AAA9C,gHAAA,cAAc,OAAA;AACvB,wDAAkF;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;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, 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 { 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,28 @@
|
|
|
1
|
+
import { HeaderInfo } from '../spec/ApiSpec';
|
|
2
|
+
import { SchemaLens } from '../spec/SchemaLens';
|
|
3
|
+
import { Markdown } from '../markdown/Markdown';
|
|
4
|
+
/** The heading a reader Ctrl-Fs for, above every list of headers. */
|
|
5
|
+
export declare const HEADERS_HEADING = "Headers";
|
|
6
|
+
/**
|
|
7
|
+
* A **Headers** list (#1292): one row per header with its name, type, `REQUIRED` / `OPTIONAL`, and
|
|
8
|
+
* prose — on a response card beside the body schema, and in the request section for `in: "header"`
|
|
9
|
+
* parameters.
|
|
10
|
+
*
|
|
11
|
+
* A response header used to be invisible on the site although the document declared it: the
|
|
12
|
+
* `x-request-id` a partner must quote in a support ticket was in `components.headers` and on every
|
|
13
|
+
* response, and no page said so. Each row uses the SAME markup as a body field, and its type label
|
|
14
|
+
* is the same {@link SchemaLens} reading, so a header reads exactly like a field. Unlike a body field,
|
|
15
|
+
* optional is said out loud: a header list is short, and "may I omit this" is the question a reader
|
|
16
|
+
* of one is asking.
|
|
17
|
+
*/
|
|
18
|
+
export declare class HeaderListRenderer {
|
|
19
|
+
private readonly lens;
|
|
20
|
+
private readonly markdown;
|
|
21
|
+
private readonly html;
|
|
22
|
+
constructor(lens: SchemaLens, markdown: Markdown);
|
|
23
|
+
/** The list, or the empty string when there are no headers — no empty heading. */
|
|
24
|
+
render(headers: readonly HeaderInfo[]): string;
|
|
25
|
+
private row;
|
|
26
|
+
/** A header with no `schema` is a string on the wire — every HTTP header value is text. */
|
|
27
|
+
private typeOf;
|
|
28
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HeaderListRenderer = exports.HEADERS_HEADING = void 0;
|
|
4
|
+
const Html_1 = require("./Html");
|
|
5
|
+
/** The heading a reader Ctrl-Fs for, above every list of headers. */
|
|
6
|
+
exports.HEADERS_HEADING = 'Headers';
|
|
7
|
+
/**
|
|
8
|
+
* A **Headers** list (#1292): one row per header with its name, type, `REQUIRED` / `OPTIONAL`, and
|
|
9
|
+
* prose — on a response card beside the body schema, and in the request section for `in: "header"`
|
|
10
|
+
* parameters.
|
|
11
|
+
*
|
|
12
|
+
* A response header used to be invisible on the site although the document declared it: the
|
|
13
|
+
* `x-request-id` a partner must quote in a support ticket was in `components.headers` and on every
|
|
14
|
+
* response, and no page said so. Each row uses the SAME markup as a body field, and its type label
|
|
15
|
+
* is the same {@link SchemaLens} reading, so a header reads exactly like a field. Unlike a body field,
|
|
16
|
+
* optional is said out loud: a header list is short, and "may I omit this" is the question a reader
|
|
17
|
+
* of one is asking.
|
|
18
|
+
*/
|
|
19
|
+
class HeaderListRenderer {
|
|
20
|
+
lens;
|
|
21
|
+
markdown;
|
|
22
|
+
html = new Html_1.Html();
|
|
23
|
+
constructor(lens, markdown) {
|
|
24
|
+
this.lens = lens;
|
|
25
|
+
this.markdown = markdown;
|
|
26
|
+
}
|
|
27
|
+
/** The list, or the empty string when there are no headers — no empty heading. */
|
|
28
|
+
render(headers) {
|
|
29
|
+
if (headers.length === 0) {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
const rows = headers.map((header) => this.row(header)).join('');
|
|
33
|
+
return `<div class="headers"><div class="headers-head">${exports.HEADERS_HEADING}</div>${rows}</div>`;
|
|
34
|
+
}
|
|
35
|
+
row(header) {
|
|
36
|
+
const parts = ['<div class="field">', '<div class="field-head">'];
|
|
37
|
+
parts.push(`<span class="field-name">${this.html.escape(header.name)}</span>`);
|
|
38
|
+
parts.push(`<span class="field-type">${this.html.escape(this.typeOf(header))}</span>`);
|
|
39
|
+
parts.push(header.required
|
|
40
|
+
? '<span class="field-required">REQUIRED</span>'
|
|
41
|
+
: '<span class="field-optional">OPTIONAL</span>');
|
|
42
|
+
parts.push('</div>');
|
|
43
|
+
const description = header.description !== '' ? header.description : this.lens.describe(header.schema);
|
|
44
|
+
if (description !== '') {
|
|
45
|
+
parts.push(`<div class="field-doc">${this.markdown.render(description)}</div>`);
|
|
46
|
+
}
|
|
47
|
+
parts.push('</div>');
|
|
48
|
+
return parts.join('');
|
|
49
|
+
}
|
|
50
|
+
/** A header with no `schema` is a string on the wire — every HTTP header value is text. */
|
|
51
|
+
typeOf(header) {
|
|
52
|
+
return header.schema.isObject() ? this.lens.label(header.schema) : 'string';
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
exports.HeaderListRenderer = HeaderListRenderer;
|
|
56
|
+
//# sourceMappingURL=HeaderListRenderer.js.map
|
|
@@ -0,0 +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,kFAAkF;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AAO,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;AAvCD,gDAuCC","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 /** The list, or the empty string when there are no headers — no empty heading. */\n render(headers: readonly HeaderInfo[]): string {\n if (headers.length === 0) {\n return '';\n }\n const rows = headers.map((header: HeaderInfo): string => this.row(header)).join('');\n return `<div class=\"headers\"><div class=\"headers-head\">${HEADERS_HEADING}</div>${rows}</div>`;\n }\n\n private row(header: HeaderInfo): 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.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"]}
|
|
@@ -4,6 +4,7 @@ import { CodeSampleBuilder } from '../samples/CodeSamples';
|
|
|
4
4
|
import { ExampleBuilder } from '../spec/ExampleBuilder';
|
|
5
5
|
import { FieldTreeBuilder } from '../spec/FieldTree';
|
|
6
6
|
import { FieldTreeRenderer } from './FieldTreeRenderer';
|
|
7
|
+
import { HeaderListRenderer } from './HeaderListRenderer';
|
|
7
8
|
import { Layout } from './Layout';
|
|
8
9
|
import { Markdown } from '../markdown/Markdown';
|
|
9
10
|
import { SiteUrls } from './SiteUrls';
|
|
@@ -30,11 +31,13 @@ export declare class OperationPageRenderer {
|
|
|
30
31
|
private readonly examples;
|
|
31
32
|
private readonly layout;
|
|
32
33
|
private readonly urls;
|
|
34
|
+
private readonly headers;
|
|
33
35
|
private readonly html;
|
|
34
|
-
constructor(spec: ApiSpec, fields: FieldTreeBuilder, trees: FieldTreeRenderer, markdown: Markdown, cards: CardRenderer, samples: CodeSampleBuilder, examples: ExampleBuilder, layout: Layout, urls: SiteUrls);
|
|
36
|
+
constructor(spec: ApiSpec, fields: FieldTreeBuilder, trees: FieldTreeRenderer, markdown: Markdown, cards: CardRenderer, samples: CodeSampleBuilder, examples: ExampleBuilder, layout: Layout, urls: SiteUrls, headers: HeaderListRenderer);
|
|
35
37
|
page(operation: OperationInfo): SitePage;
|
|
36
38
|
private body;
|
|
37
39
|
private head;
|
|
40
|
+
/** The request's `in: "header"` parameters, then its body — each only when there is one. */
|
|
38
41
|
private requestSection;
|
|
39
42
|
private responseSection;
|
|
40
43
|
private response;
|
|
@@ -25,8 +25,9 @@ class OperationPageRenderer {
|
|
|
25
25
|
examples;
|
|
26
26
|
layout;
|
|
27
27
|
urls;
|
|
28
|
+
headers;
|
|
28
29
|
html = new Html_1.Html();
|
|
29
|
-
constructor(spec, fields, trees, markdown, cards, samples, examples, layout, urls) {
|
|
30
|
+
constructor(spec, fields, trees, markdown, cards, samples, examples, layout, urls, headers) {
|
|
30
31
|
this.spec = spec;
|
|
31
32
|
this.fields = fields;
|
|
32
33
|
this.trees = trees;
|
|
@@ -36,6 +37,7 @@ class OperationPageRenderer {
|
|
|
36
37
|
this.examples = examples;
|
|
37
38
|
this.layout = layout;
|
|
38
39
|
this.urls = urls;
|
|
40
|
+
this.headers = headers;
|
|
39
41
|
}
|
|
40
42
|
page(operation) {
|
|
41
43
|
const url = this.urls.operation(operation);
|
|
@@ -57,11 +59,16 @@ class OperationPageRenderer {
|
|
|
57
59
|
}
|
|
58
60
|
return `<div class="op-head"><span class="badge">${this.html.escape(operation.httpMethod)}</span><code class="op-path">${this.html.escape(operation.path)}</code></div>`;
|
|
59
61
|
}
|
|
62
|
+
/** The request's `in: "header"` parameters, then its body — each only when there is one. */
|
|
60
63
|
requestSection(operation, prefix) {
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
const parts = [];
|
|
65
|
+
if (operation.requestHeaders.length > 0) {
|
|
66
|
+
parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders)}`);
|
|
67
|
+
}
|
|
68
|
+
if (operation.requestSchema !== undefined) {
|
|
69
|
+
parts.push(`<h2>Request body</h2>${this.tree(operation.requestSchema, prefix)}`);
|
|
63
70
|
}
|
|
64
|
-
return
|
|
71
|
+
return parts.join('');
|
|
65
72
|
}
|
|
66
73
|
responseSection(operation, prefix) {
|
|
67
74
|
if (operation.responses.length === 0) {
|
|
@@ -77,7 +84,9 @@ class OperationPageRenderer {
|
|
|
77
84
|
const body = response.schema === undefined
|
|
78
85
|
? '<p class="field-doc">No body.</p>'
|
|
79
86
|
: this.tree(response.schema, prefix);
|
|
80
|
-
|
|
87
|
+
// The headers ride the card beside the body (#1292) — the response a partner holds carries both.
|
|
88
|
+
const headers = this.headers.render(response.headers);
|
|
89
|
+
return `<details class="disclosure" open><summary>${summary}</summary>${headers}${body}</details>`;
|
|
81
90
|
}
|
|
82
91
|
/** A `oneOf` renders as expanded variants; anything else renders as one flat field tree. */
|
|
83
92
|
tree(schema, prefix) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationPageRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/OperationPageRenderer.ts"],"names":[],"mappings":";;;
|
|
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;QACd,YAAO,GAAP,OAAO,CAAoB;IAC7C,CAAC;IAEJ,IA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AC,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;AAxGD,sDAwGC","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 private head(operation: OperationInfo): string {\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></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></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"]}
|
|
@@ -10,6 +10,7 @@ const Html_1 = require("./Html");
|
|
|
10
10
|
const Layout_1 = require("./Layout");
|
|
11
11
|
const Markdown_1 = require("../markdown/Markdown");
|
|
12
12
|
const NavModel_1 = require("./NavModel");
|
|
13
|
+
const HeaderListRenderer_1 = require("./HeaderListRenderer");
|
|
13
14
|
const OperationPageRenderer_1 = require("./OperationPageRenderer");
|
|
14
15
|
const SitePage_1 = require("./SitePage");
|
|
15
16
|
const SchemaLens_1 = require("../spec/SchemaLens");
|
|
@@ -46,7 +47,7 @@ class SiteRenderer {
|
|
|
46
47
|
const title = titleOverride === '' ? spec.title : titleOverride;
|
|
47
48
|
const nav = new NavModel_1.NavBuilder(this.urls).build(spec, prose, exports.OVERVIEW_TITLE);
|
|
48
49
|
const layout = new Layout_1.Layout(nav, this.urls, title, spec.version);
|
|
49
|
-
const operations = new OperationPageRenderer_1.OperationPageRenderer(spec, fields, trees, this.markdown, this.cards, new CodeSamples_1.CodeSampleBuilder(spec, examples), examples, layout, this.urls);
|
|
50
|
+
const operations = new OperationPageRenderer_1.OperationPageRenderer(spec, fields, trees, this.markdown, this.cards, new CodeSamples_1.CodeSampleBuilder(spec, examples), examples, layout, this.urls, new HeaderListRenderer_1.HeaderListRenderer(lens, this.markdown));
|
|
50
51
|
const pages = [this.overview(spec, layout)];
|
|
51
52
|
for (const page of prose) {
|
|
52
53
|
pages.push(this.prosePage(page, layout));
|
|
@@ -1 +1 @@
|
|
|
1
|
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AG,CAAC,CAAC;QACxC,MAAM,KAAK,GAAG,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC5D,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;QACpD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;YAC5B,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;QAClD,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAChD,KAAK,CAAC,IAAI,CACN,QAAQ,CAAC,MAAM,GAAG,CAAC;YACf,CAAC,CAAC,KAAK,CAAC,cAAc,CAChB,QAAQ,EACR,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,IAAI,CAAC,EAC3C,MAAM,CACT;YACH,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAC3D,CAAC;QACF,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,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;AApID,oCAoIC","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 { 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 );\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.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/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,IA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,CAAC,MAAM,CAAC,IAAI,CAAC,EAC3C,MAAM,CACT;YACH,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,CAC3D,CAAC;QACF,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC,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;AArID,oCAqIC","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.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"]}
|
package/src/spec/ApiSpec.d.ts
CHANGED
|
@@ -26,12 +26,35 @@ export declare class SecuritySchemeInfo {
|
|
|
26
26
|
readonly description: string | undefined;
|
|
27
27
|
constructor(key: string, kind: string, sentIn: string, headerName: string, description: string | undefined);
|
|
28
28
|
}
|
|
29
|
+
/**
|
|
30
|
+
* One HTTP header a page documents: a response's `headers` entry, or a request parameter declared
|
|
31
|
+
* `in: "header"` (#1292). A `$ref` — into `components.headers` or `components.parameters` — is resolved
|
|
32
|
+
* when the document is read, so a renderer never follows a pointer.
|
|
33
|
+
*
|
|
34
|
+
* `schema` is kept as the node rather than a label, because the type label is the same
|
|
35
|
+
* `SchemaLens` reading every body field gets — a header typed by a named schema reads exactly like a
|
|
36
|
+
* field typed by one.
|
|
37
|
+
*/
|
|
38
|
+
export declare class HeaderInfo {
|
|
39
|
+
readonly name: string;
|
|
40
|
+
readonly required: boolean;
|
|
41
|
+
readonly description: string;
|
|
42
|
+
/** The header's `schema`; a node over `undefined` when the document states none. */
|
|
43
|
+
readonly schema: JsonNode;
|
|
44
|
+
constructor(name: string, required: boolean, description: string,
|
|
45
|
+
/** The header's `schema`; a node over `undefined` when the document states none. */
|
|
46
|
+
schema: JsonNode);
|
|
47
|
+
}
|
|
29
48
|
/** One response of one operation. */
|
|
30
49
|
export declare class ResponseInfo {
|
|
31
50
|
readonly status: string;
|
|
32
51
|
readonly description: string;
|
|
33
52
|
readonly schema: JsonNode | undefined;
|
|
34
|
-
|
|
53
|
+
/** Its `headers`, in document order — rendered on the card beside the body (#1292). */
|
|
54
|
+
readonly headers: readonly HeaderInfo[];
|
|
55
|
+
constructor(status: string, description: string, schema: JsonNode | undefined,
|
|
56
|
+
/** Its `headers`, in document order — rendered on the card beside the body (#1292). */
|
|
57
|
+
headers: readonly HeaderInfo[]);
|
|
35
58
|
}
|
|
36
59
|
/**
|
|
37
60
|
* One rendered page's worth of operation.
|
|
@@ -48,6 +71,11 @@ export declare class OperationInfo {
|
|
|
48
71
|
readonly description: string;
|
|
49
72
|
readonly tag: string;
|
|
50
73
|
readonly requestSchema: JsonNode | undefined;
|
|
74
|
+
/**
|
|
75
|
+
* Every `in: "header"` parameter, the path item's and the operation's (#1292). A credential
|
|
76
|
+
* header from a security scheme is not here: the authorization card documents those.
|
|
77
|
+
*/
|
|
78
|
+
readonly requestHeaders: readonly HeaderInfo[];
|
|
51
79
|
readonly responses: readonly ResponseInfo[];
|
|
52
80
|
readonly isWebhook: boolean;
|
|
53
81
|
readonly securityKeys: readonly string[];
|
|
@@ -58,7 +86,12 @@ export declare class OperationInfo {
|
|
|
58
86
|
* `order.state-changed` is what the partner matches on the wire.
|
|
59
87
|
*/
|
|
60
88
|
readonly eventName: string;
|
|
61
|
-
constructor(name: string, slug: string, httpMethod: string, path: string, description: string, tag: string, requestSchema: JsonNode | undefined,
|
|
89
|
+
constructor(name: string, slug: string, httpMethod: string, path: string, description: string, tag: string, requestSchema: JsonNode | undefined,
|
|
90
|
+
/**
|
|
91
|
+
* Every `in: "header"` parameter, the path item's and the operation's (#1292). A credential
|
|
92
|
+
* header from a security scheme is not here: the authorization card documents those.
|
|
93
|
+
*/
|
|
94
|
+
requestHeaders: readonly HeaderInfo[], responses: readonly ResponseInfo[], isWebhook: boolean, securityKeys: readonly string[],
|
|
62
95
|
/**
|
|
63
96
|
* The event NAME a webhook is keyed by in the document's `webhooks:` block, and the empty
|
|
64
97
|
* string for an ordinary operation. It is carried separately from `name` because the two
|
package/src/spec/ApiSpec.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ApiSpec = exports.NamedSchema = exports.TagSection = exports.OperationInfo = exports.ResponseInfo = exports.SecuritySchemeInfo = exports.ServerInfo = void 0;
|
|
3
|
+
exports.ApiSpec = exports.NamedSchema = exports.TagSection = exports.OperationInfo = exports.ResponseInfo = exports.HeaderInfo = exports.SecuritySchemeInfo = exports.ServerInfo = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* The model this package renders. It is read from a document STRUCTURALLY (see {@link JsonNode}), so
|
|
6
6
|
* it is deliberately NOT `@webpieces/openapi-generator`'s document classes even though it looks like
|
|
@@ -39,15 +39,43 @@ class SecuritySchemeInfo {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
exports.SecuritySchemeInfo = SecuritySchemeInfo;
|
|
42
|
+
/**
|
|
43
|
+
* One HTTP header a page documents: a response's `headers` entry, or a request parameter declared
|
|
44
|
+
* `in: "header"` (#1292). A `$ref` — into `components.headers` or `components.parameters` — is resolved
|
|
45
|
+
* when the document is read, so a renderer never follows a pointer.
|
|
46
|
+
*
|
|
47
|
+
* `schema` is kept as the node rather than a label, because the type label is the same
|
|
48
|
+
* `SchemaLens` reading every body field gets — a header typed by a named schema reads exactly like a
|
|
49
|
+
* field typed by one.
|
|
50
|
+
*/
|
|
51
|
+
class HeaderInfo {
|
|
52
|
+
name;
|
|
53
|
+
required;
|
|
54
|
+
description;
|
|
55
|
+
schema;
|
|
56
|
+
constructor(name, required, description,
|
|
57
|
+
/** The header's `schema`; a node over `undefined` when the document states none. */
|
|
58
|
+
schema) {
|
|
59
|
+
this.name = name;
|
|
60
|
+
this.required = required;
|
|
61
|
+
this.description = description;
|
|
62
|
+
this.schema = schema;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.HeaderInfo = HeaderInfo;
|
|
42
66
|
/** One response of one operation. */
|
|
43
67
|
class ResponseInfo {
|
|
44
68
|
status;
|
|
45
69
|
description;
|
|
46
70
|
schema;
|
|
47
|
-
|
|
71
|
+
headers;
|
|
72
|
+
constructor(status, description, schema,
|
|
73
|
+
/** Its `headers`, in document order — rendered on the card beside the body (#1292). */
|
|
74
|
+
headers) {
|
|
48
75
|
this.status = status;
|
|
49
76
|
this.description = description;
|
|
50
77
|
this.schema = schema;
|
|
78
|
+
this.headers = headers;
|
|
51
79
|
}
|
|
52
80
|
}
|
|
53
81
|
exports.ResponseInfo = ResponseInfo;
|
|
@@ -66,11 +94,17 @@ class OperationInfo {
|
|
|
66
94
|
description;
|
|
67
95
|
tag;
|
|
68
96
|
requestSchema;
|
|
97
|
+
requestHeaders;
|
|
69
98
|
responses;
|
|
70
99
|
isWebhook;
|
|
71
100
|
securityKeys;
|
|
72
101
|
eventName;
|
|
73
|
-
constructor(name, slug, httpMethod, path, description, tag, requestSchema,
|
|
102
|
+
constructor(name, slug, httpMethod, path, description, tag, requestSchema,
|
|
103
|
+
/**
|
|
104
|
+
* Every `in: "header"` parameter, the path item's and the operation's (#1292). A credential
|
|
105
|
+
* header from a security scheme is not here: the authorization card documents those.
|
|
106
|
+
*/
|
|
107
|
+
requestHeaders, responses, isWebhook, securityKeys,
|
|
74
108
|
/**
|
|
75
109
|
* The event NAME a webhook is keyed by in the document's `webhooks:` block, and the empty
|
|
76
110
|
* string for an ordinary operation. It is carried separately from `name` because the two
|
|
@@ -85,6 +119,7 @@ class OperationInfo {
|
|
|
85
119
|
this.description = description;
|
|
86
120
|
this.tag = tag;
|
|
87
121
|
this.requestSchema = requestSchema;
|
|
122
|
+
this.requestHeaders = requestHeaders;
|
|
88
123
|
this.responses = responses;
|
|
89
124
|
this.isWebhook = isWebhook;
|
|
90
125
|
this.securityKeys = securityKeys;
|
package/src/spec/ApiSpec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApiSpec.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/spec/ApiSpec.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AAEH,4FAA4F;AAC5F,MAAa,UAAU;IAEN;IACA;IAFb,YACa,GAAW,EACX,WAA+B;QAD/B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,gCAKC;AAED;;;;GAIG;AACH,MAAa,kBAAkB;IAEd;IACA;IACA;IACA;IACA;IALb,YACa,GAAW,EACX,IAAY,EACZ,MAAc,EACd,UAAkB,EAClB,WAA+B;QAJ/B,QAAG,GAAH,GAAG,CAAQ;QACX,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AARD,gDAQC;AAED,qCAAqC;AACrC,MAAa,YAAY;IAER;IACA;IACA;
|
|
1
|
+
{"version":3,"file":"ApiSpec.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/spec/ApiSpec.ts"],"names":[],"mappings":";;;AAEA;;;;;;;GAOG;AAEH,4FAA4F;AAC5F,MAAa,UAAU;IAEN;IACA;IAFb,YACa,GAAW,EACX,WAA+B;QAD/B,QAAG,GAAH,GAAG,CAAQ;QACX,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AALD,gCAKC;AAED;;;;GAIG;AACH,MAAa,kBAAkB;IAEd;IACA;IACA;IACA;IACA;IALb,YACa,GAAW,EACX,IAAY,EACZ,MAAc,EACd,UAAkB,EAClB,WAA+B;QAJ/B,QAAG,GAAH,GAAG,CAAQ;QACX,SAAI,GAAJ,IAAI,CAAQ;QACZ,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,gBAAW,GAAX,WAAW,CAAoB;IACzC,CAAC;CACP;AARD,gDAQC;AAED;;;;;;;;GAQG;AACH,MAAa,UAAU;IAEN;IACA;IACA;IAEA;IALb,YACa,IAAY,EACZ,QAAiB,EACjB,WAAmB;IAC5B,oFAAoF;IAC3E,MAAgB;QAJhB,SAAI,GAAJ,IAAI,CAAQ;QACZ,aAAQ,GAAR,QAAQ,CAAS;QACjB,gBAAW,GAAX,WAAW,CAAQ;QAEnB,WAAM,GAAN,MAAM,CAAU;IAC1B,CAAC;CACP;AARD,gCAQC;AAED,qCA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ACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,IAAc,EACd,UAAmB;QAHnB,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAU;QACd,eAAU,GAAV,UAAU,CAAS;IAC7B,CAAC;CACP;AAPD,kCAOC;AAED,qCAAqC;AACrC,MAAa,OAAO;IAEH;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IARb,YACa,KAAa,EACb,OAAe,EACf,WAAmB,EACnB,OAA8B,EAC9B,QAA+B,EAC/B,eAA8C,EAC9C,OAA+B,EAC/B,oBAAuC;QAPvC,UAAK,GAAL,KAAK,CAAQ;QACb,YAAO,GAAP,OAAO,CAAQ;QACf,gBAAW,GAAX,WAAW,CAAQ;QACnB,YAAO,GAAP,OAAO,CAAuB;QAC9B,aAAQ,GAAR,QAAQ,CAAuB;QAC/B,oBAAe,GAAf,eAAe,CAA+B;QAC9C,YAAO,GAAP,OAAO,CAAwB;QAC/B,yBAAoB,GAApB,oBAAoB,CAAmB;IACjD,CAAC;IAEJ,8FAA8F;IAC9F,WAAW,CAAC,IAAY;QACpB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAmB,EAAW,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IACrF,CAAC;IAED,iEAAiE;IACjE,UAAU;QACN,MAAM,GAAG,GAAoB,EAAE,CAAC;QAChC,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YAClC,GAAG,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC;CACJ;AAzBD,0BAyBC","sourcesContent":["import { JsonNode } from './JsonNode';\n\n/**\n * The model this package renders. It is read from a document STRUCTURALLY (see {@link JsonNode}), so\n * it is deliberately NOT `@webpieces/openapi-generator`'s document classes even though it looks like\n * them: a compile-time dependency on the generator would make \"generated by us\" a precondition for\n * \"renderable by us\", and #985 is explicit that any conforming 3.0 or 3.1 document renders here.\n *\n * Everything below is data, so everything below is a class (`CLAUDE.md` §1).\n */\n\n/** One entry of the document's `servers[]`. The first one is what the code samples call. */\nexport class ServerInfo {\n constructor(\n readonly url: string,\n readonly description: string | undefined,\n ) {}\n}\n\n/**\n * One published security scheme. Only the fields a partner has to ACT on are carried: what to send\n * and where. `headerName` is empty for a scheme that is not sent in a header, and the code samples\n * then omit it rather than inventing a header name the server never reads.\n */\nexport class SecuritySchemeInfo {\n constructor(\n readonly key: string,\n readonly kind: string,\n readonly sentIn: string,\n readonly headerName: string,\n readonly description: string | undefined,\n ) {}\n}\n\n/**\n * One HTTP header a page documents: a response's `headers` entry, or a request parameter declared\n * `in: \"header\"` (#1292). A `$ref` — into `components.headers` or `components.parameters` — is resolved\n * when the document is read, so a renderer never follows a pointer.\n *\n * `schema` is kept as the node rather than a label, because the type label is the same\n * `SchemaLens` reading every body field gets — a header typed by a named schema reads exactly like a\n * field typed by one.\n */\nexport class HeaderInfo {\n constructor(\n readonly name: string,\n readonly required: boolean,\n readonly description: string,\n /** The header's `schema`; a node over `undefined` when the document states none. */\n readonly schema: JsonNode,\n ) {}\n}\n\n/** One response of one operation. */\nexport class ResponseInfo {\n constructor(\n readonly status: string,\n readonly description: string,\n readonly schema: JsonNode | undefined,\n /** Its `headers`, in document order — rendered on the card beside the body (#1292). */\n readonly headers: readonly HeaderInfo[],\n ) {}\n}\n\n/**\n * One rendered page's worth of operation.\n *\n * A WEBHOOK carries `isWebhook`, and with it no method, no path and no code samples. The url belongs\n * to the PARTNER, so a curl of ours against one would invite them to call something that does not\n * exist — see `responsibilities.md`.\n */\nexport class OperationInfo {\n constructor(\n readonly name: string,\n readonly slug: string,\n readonly httpMethod: string,\n readonly path: string,\n readonly description: string,\n readonly tag: string,\n readonly requestSchema: JsonNode | undefined,\n /**\n * Every `in: \"header\"` parameter, the path item's and the operation's (#1292). A credential\n * header from a security scheme is not here: the authorization card documents those.\n */\n readonly requestHeaders: readonly HeaderInfo[],\n readonly responses: readonly ResponseInfo[],\n readonly isWebhook: boolean,\n readonly securityKeys: readonly string[],\n /**\n * The event NAME a webhook is keyed by in the document's `webhooks:` block, and the empty\n * string for an ordinary operation. It is carried separately from `name` because the two\n * are different published facts — `orderStateChanged` is what we call the method,\n * `order.state-changed` is what the partner matches on the wire.\n */\n readonly eventName: string,\n ) {}\n}\n\n/**\n * One nav section: an OpenAPI tag and the operations under it, webhooks appended after the\n * operations that share the tag. EVERY tag gets one — a tag missing from the sidebar is an operation\n * a partner cannot find, which reads exactly like an operation that does not exist.\n */\nexport class TagSection {\n constructor(\n readonly name: string,\n readonly description: string,\n readonly operations: readonly OperationInfo[],\n ) {}\n}\n\n/**\n * One named schema from `components.schemas`.\n *\n * `hasOwnPage` is true for an OBJECT only. A named enum or scalar alias stays inline at every use\n * site, because a page carrying one line of chips is a click that costs the reader the context they\n * were reading in.\n */\nexport class NamedSchema {\n constructor(\n readonly name: string,\n readonly slug: string,\n readonly node: JsonNode,\n readonly hasOwnPage: boolean,\n ) {}\n}\n\n/** The whole document, read once. */\nexport class ApiSpec {\n constructor(\n readonly title: string,\n readonly version: string,\n readonly description: string,\n readonly servers: readonly ServerInfo[],\n readonly sections: readonly TagSection[],\n readonly securitySchemes: readonly SecuritySchemeInfo[],\n readonly schemas: readonly NamedSchema[],\n readonly documentSecurityKeys: readonly string[],\n ) {}\n\n /** The named schema `name` refers to, or `undefined` when the document does not define it. */\n schemaNamed(name: string): NamedSchema | undefined {\n return this.schemas.find((schema: NamedSchema): boolean => schema.name === name);\n }\n\n /** Every operation, across every section, in published order. */\n operations(): readonly OperationInfo[] {\n const all: OperationInfo[] = [];\n for (const section of this.sections) {\n all.push(...section.operations);\n }\n return all;\n }\n}\n"]}
|
package/src/spec/SpecReader.d.ts
CHANGED
|
@@ -36,6 +36,20 @@ export declare class SpecReader {
|
|
|
36
36
|
private tagOf;
|
|
37
37
|
private requestSchemaOf;
|
|
38
38
|
private responsesOf;
|
|
39
|
+
/** A response's `headers` map, each entry resolved through a `$ref` into `components.headers`. */
|
|
40
|
+
private responseHeadersOf;
|
|
41
|
+
/**
|
|
42
|
+
* Every `in: "header"` parameter: the PATH ITEM's first, then the operation's — an operation
|
|
43
|
+
* parameter of the same name overrides the path item's, which is OpenAPI's own rule.
|
|
44
|
+
*/
|
|
45
|
+
private requestHeadersOf;
|
|
46
|
+
/**
|
|
47
|
+
* The object a LOCAL `$ref` (`#/components/headers/x-request-id`) points at, or the node itself
|
|
48
|
+
* when it is no reference. A dangling or foreign reference also reads as the node itself, so the
|
|
49
|
+
* header still renders under its own name rather than vanishing — the same total-reading choice
|
|
50
|
+
* `JsonNode` makes everywhere.
|
|
51
|
+
*/
|
|
52
|
+
private dereference;
|
|
39
53
|
/**
|
|
40
54
|
* The credentials this operation needs: its own `security` when it states one, the document's
|
|
41
55
|
* otherwise. An operation stating `security: []` needs none, and that empty array is the
|
package/src/spec/SpecReader.js
CHANGED
|
@@ -104,7 +104,7 @@ class SpecReader {
|
|
|
104
104
|
if (!HTTP_METHODS.includes(methodEntry.key)) {
|
|
105
105
|
continue;
|
|
106
106
|
}
|
|
107
|
-
found.push(this.readOperation(root, methodEntry.value, slugs, methodEntry.key.toUpperCase(), pathEntry.key, false));
|
|
107
|
+
found.push(this.readOperation(root, methodEntry.value, slugs, methodEntry.key.toUpperCase(), pathEntry.key, false, pathEntry.value));
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
return found;
|
|
@@ -116,14 +116,14 @@ class SpecReader {
|
|
|
116
116
|
if (!HTTP_METHODS.includes(methodEntry.key)) {
|
|
117
117
|
continue;
|
|
118
118
|
}
|
|
119
|
-
found.push(this.readOperation(root, methodEntry.value, slugs, '', eventEntry.key, true));
|
|
119
|
+
found.push(this.readOperation(root, methodEntry.value, slugs, '', eventEntry.key, true, eventEntry.value));
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
return found;
|
|
123
123
|
}
|
|
124
|
-
readOperation(root, node, slugs, httpMethod, pathOrEvent, isWebhook) {
|
|
124
|
+
readOperation(root, node, slugs, httpMethod, pathOrEvent, isWebhook, pathItem) {
|
|
125
125
|
const name = node.text('summary') ?? node.text('operationId') ?? pathOrEvent;
|
|
126
|
-
return new ApiSpec_1.OperationInfo(name, slugs.unique(name), httpMethod, isWebhook ? '' : pathOrEvent, node.text('description') ?? '', this.tagOf(node), this.requestSchemaOf(node), this.responsesOf(node), isWebhook, isWebhook ? [] : this.operationSecurityKeys(root, node), isWebhook ? pathOrEvent : '');
|
|
126
|
+
return new ApiSpec_1.OperationInfo(name, slugs.unique(name), httpMethod, isWebhook ? '' : pathOrEvent, node.text('description') ?? '', this.tagOf(node), this.requestSchemaOf(node), this.requestHeadersOf(root, pathItem, node), this.responsesOf(root, node), isWebhook, isWebhook ? [] : this.operationSecurityKeys(root, node), isWebhook ? pathOrEvent : '');
|
|
127
127
|
}
|
|
128
128
|
tagOf(node) {
|
|
129
129
|
for (const tag of node.list('tags')) {
|
|
@@ -138,15 +138,61 @@ class SpecReader {
|
|
|
138
138
|
const schema = node.at('requestBody').at('content').at('application/json').at('schema');
|
|
139
139
|
return schema.isObject() ? schema : undefined;
|
|
140
140
|
}
|
|
141
|
-
responsesOf(node) {
|
|
141
|
+
responsesOf(root, node) {
|
|
142
142
|
return node
|
|
143
143
|
.at('responses')
|
|
144
144
|
.entries()
|
|
145
145
|
.map((entry) => {
|
|
146
|
-
const
|
|
147
|
-
|
|
146
|
+
const response = this.dereference(root, entry.value);
|
|
147
|
+
const schema = response.at('content').at('application/json').at('schema');
|
|
148
|
+
return new ApiSpec_1.ResponseInfo(entry.key, response.text('description') ?? '', schema.isObject() ? schema : undefined, this.responseHeadersOf(root, response));
|
|
148
149
|
});
|
|
149
150
|
}
|
|
151
|
+
/** A response's `headers` map, each entry resolved through a `$ref` into `components.headers`. */
|
|
152
|
+
responseHeadersOf(root, response) {
|
|
153
|
+
return response
|
|
154
|
+
.at('headers')
|
|
155
|
+
.entries()
|
|
156
|
+
.map((entry) => {
|
|
157
|
+
const header = this.dereference(root, entry.value);
|
|
158
|
+
return new ApiSpec_1.HeaderInfo(entry.key, header.flag('required') === true, header.text('description') ?? '', header.at('schema'));
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Every `in: "header"` parameter: the PATH ITEM's first, then the operation's — an operation
|
|
163
|
+
* parameter of the same name overrides the path item's, which is OpenAPI's own rule.
|
|
164
|
+
*/
|
|
165
|
+
requestHeadersOf(root, pathItem, node) {
|
|
166
|
+
const byName = new Map();
|
|
167
|
+
for (const holder of [pathItem, node]) {
|
|
168
|
+
for (const listed of holder.list('parameters')) {
|
|
169
|
+
const parameter = this.dereference(root, listed);
|
|
170
|
+
const name = parameter.text('name');
|
|
171
|
+
if (parameter.text('in') !== 'header' || name === undefined) {
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
byName.set(name.toLowerCase(), new ApiSpec_1.HeaderInfo(name, parameter.flag('required') === true, parameter.text('description') ?? '', parameter.at('schema')));
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
return Array.from(byName.values());
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* The object a LOCAL `$ref` (`#/components/headers/x-request-id`) points at, or the node itself
|
|
181
|
+
* when it is no reference. A dangling or foreign reference also reads as the node itself, so the
|
|
182
|
+
* header still renders under its own name rather than vanishing — the same total-reading choice
|
|
183
|
+
* `JsonNode` makes everywhere.
|
|
184
|
+
*/
|
|
185
|
+
dereference(root, node) {
|
|
186
|
+
const pointer = node.text('$ref');
|
|
187
|
+
if (pointer === undefined || !pointer.startsWith('#/')) {
|
|
188
|
+
return node;
|
|
189
|
+
}
|
|
190
|
+
let current = root;
|
|
191
|
+
for (const step of pointer.slice(2).split('/')) {
|
|
192
|
+
current = current.at(step.replace(/~1/g, '/').replace(/~0/g, '~'));
|
|
193
|
+
}
|
|
194
|
+
return current.isObject() ? current : node;
|
|
195
|
+
}
|
|
150
196
|
/**
|
|
151
197
|
* The credentials this operation needs: its own `security` when it states one, the document's
|
|
152
198
|
* otherwise. An operation stating `security: []` needs none, and that empty array is the
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SpecReader.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/spec/SpecReader.ts"],"names":[],"mappings":";;;AAAA,uCAQmB;AAEnB,+CAA4C;AAC5C,iCAA8B;AAE9B,MAAM,YAAY,GAAsB;IACpC,KAAK;IACL,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACT,MAAM;IACN,OAAO;IACP,OAAO;CACV,CAAC;AAEF,kGAAkG;AACrF,QAAA,gBAAgB,GAAG,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,UAAU;IACF,KAAK,GAAG,IAAI,yBAAW,EAAE,CAAC;IAE3C,IAAI,CAAC,IAAc;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QACzC,OAAO,IAAI,iBAAO,CACd,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,eAAe,EAChD,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,EACrC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,IAAI,EAAE,EACzC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EACtB,QAAQ,EACR,IAAI,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAC9B,OAAO,EACP,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAC5B,CAAC;IACN,CAAC;IAEO,WAAW,CAAC,IAAc;Q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Q,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CACzC,CAAC;QACN,CAAC,CAAC,CAAC;IACX,CAAC;IAED;;;;OAIG;IACK,qBAAqB,CAAC,IAAc,EAAE,IAAc;QACxD,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;QACrC,CAAC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;IAEO,cAAc,CAAC,MAAgB;QACnC,MAAM,IAAI,GAAa,EAAE,CAAC;QAC1B,KAAK,MAAM,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAChD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;gBACnC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBACtB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA7ND,gCA6NC","sourcesContent":["import {\n ApiSpec,\n NamedSchema,\n OperationInfo,\n ResponseInfo,\n SecuritySchemeInfo,\n ServerInfo,\n TagSection,\n} from './ApiSpec';\nimport { JsonEntry, JsonNode } from './JsonNode';\nimport { SchemaShape } from './SchemaShape';\nimport { Slug } from './Slug';\n\nconst HTTP_METHODS: readonly string[] = [\n 'get',\n 'put',\n 'post',\n 'delete',\n 'options',\n 'head',\n 'patch',\n 'trace',\n];\n\n/** The section untagged operations land in, so an operation is never unreachable from the nav. */\nexport const UNTAGGED_SECTION = 'Operations';\n\n/**\n * Reads one OpenAPI 3.0-or-3.1 document into an {@link ApiSpec}.\n *\n * ## Nothing here is SORTED\n *\n * Both orders in the finished site are published decisions somebody made, so neither is re-derived:\n * the reference order is the document's own `tags[]`, and the prose order is `docs.manifest.json`.\n * Alphabetising either is not a cleanup — it reorders partner-facing navigation.\n *\n * A tag that appears on an operation without being declared in `tags[]` still gets its own section,\n * appended in first-seen order. A tag missing from the sidebar is an operation a partner cannot\n * find, which reads exactly like an operation that does not exist.\n *\n * ## Webhooks\n *\n * A top-level `webhooks:` entry files into the SAME section as the operations sharing its tag, and\n * is APPENDED after them, because the events are what happens as a result of the calls above.\n */\nexport class SpecReader {\n private readonly shape = new SchemaShape();\n\n read(root: JsonNode): ApiSpec {\n const schemas = this.readSchemas(root);\n const sections = this.readSections(root);\n return new ApiSpec(\n root.at('info').text('title') ?? 'API reference',\n root.at('info').text('version') ?? '',\n root.at('info').text('description') ?? '',\n this.readServers(root),\n sections,\n this.readSecuritySchemes(root),\n schemas,\n this.securityKeysIn(root),\n );\n }\n\n private readServers(root: JsonNode): readonly ServerInfo[] {\n return root\n .list('servers')\n .map(\n (entry: JsonNode): ServerInfo =>\n new ServerInfo(entry.text('url') ?? '', entry.text('description')),\n );\n }\n\n private readSecuritySchemes(root: JsonNode): readonly SecuritySchemeInfo[] {\n const declared = root.at('components').at('securitySchemes');\n return declared\n .entries()\n .map(\n (entry: JsonEntry): SecuritySchemeInfo =>\n new SecuritySchemeInfo(\n entry.key,\n entry.value.text('type') ?? '',\n entry.value.text('in') ?? '',\n entry.value.text('name') ?? '',\n entry.value.text('description'),\n ),\n );\n }\n\n private readSchemas(root: JsonNode): readonly NamedSchema[] {\n const slugs = new Slug();\n return root\n .at('components')\n .at('schemas')\n .entries()\n .map(\n (entry: JsonEntry): NamedSchema =>\n new NamedSchema(\n entry.key,\n slugs.unique(entry.key),\n entry.value,\n this.shape.hasOwnPage(entry.value),\n ),\n );\n }\n\n private readSections(root: JsonNode): readonly TagSection[] {\n const slugs = new Slug();\n const operations = this.readOperations(root, slugs);\n const webhooks = this.readWebhooks(root, slugs);\n const order = this.sectionOrder(root, operations, webhooks);\n const sections: TagSection[] = [];\n for (const tag of order) {\n const inTag = operations.filter((one: OperationInfo): boolean => one.tag === tag);\n const eventsInTag = webhooks.filter((one: OperationInfo): boolean => one.tag === tag);\n sections.push(\n new TagSection(tag, this.tagDescription(root, tag), [...inTag, ...eventsInTag]),\n );\n }\n return sections;\n }\n\n /** `tags[]` first, in its published order, then any tag only an operation mentions. */\n private sectionOrder(\n root: JsonNode,\n operations: readonly OperationInfo[],\n webhooks: readonly OperationInfo[],\n ): readonly string[] {\n const order: string[] = [];\n for (const declared of root.list('tags')) {\n const name = declared.text('name');\n if (name !== undefined && !order.includes(name)) {\n order.push(name);\n }\n }\n for (const one of [...operations, ...webhooks]) {\n if (!order.includes(one.tag)) {\n order.push(one.tag);\n }\n }\n return order.filter((tag: string): boolean =>\n [...operations, ...webhooks].some((one: OperationInfo): boolean => one.tag === tag),\n );\n }\n\n private tagDescription(root: JsonNode, tag: string): string {\n for (const declared of root.list('tags')) {\n if (declared.text('name') === tag) {\n return declared.text('description') ?? '';\n }\n }\n return '';\n }\n\n private readOperations(root: JsonNode, slugs: Slug): readonly OperationInfo[] {\n const found: OperationInfo[] = [];\n for (const pathEntry of root.at('paths').entries()) {\n for (const methodEntry of pathEntry.value.entries()) {\n if (!HTTP_METHODS.includes(methodEntry.key)) {\n continue;\n }\n found.push(\n this.readOperation(\n root,\n methodEntry.value,\n slugs,\n methodEntry.key.toUpperCase(),\n pathEntry.key,\n false,\n ),\n );\n }\n }\n return found;\n }\n\n private readWebhooks(root: JsonNode, slugs: Slug): readonly OperationInfo[] {\n const found: OperationInfo[] = [];\n for (const eventEntry of root.at('webhooks').entries()) {\n for (const methodEntry of eventEntry.value.entries()) {\n if (!HTTP_METHODS.includes(methodEntry.key)) {\n continue;\n }\n found.push(\n this.readOperation(root, methodEntry.value, slugs, '', eventEntry.key, true),\n );\n }\n }\n return found;\n }\n\n private readOperation(\n root: JsonNode,\n node: JsonNode,\n slugs: Slug,\n httpMethod: string,\n pathOrEvent: string,\n isWebhook: boolean,\n ): OperationInfo {\n const name = node.text('summary') ?? node.text('operationId') ?? pathOrEvent;\n return new OperationInfo(\n name,\n slugs.unique(name),\n httpMethod,\n isWebhook ? '' : pathOrEvent,\n node.text('description') ?? '',\n this.tagOf(node),\n this.requestSchemaOf(node),\n this.responsesOf(node),\n isWebhook,\n isWebhook ? [] : this.operationSecurityKeys(root, node),\n isWebhook ? pathOrEvent : '',\n );\n }\n\n private tagOf(node: JsonNode): string {\n for (const tag of node.list('tags')) {\n const name = tag.asText();\n if (name !== undefined) {\n return name;\n }\n }\n return UNTAGGED_SECTION;\n }\n\n private requestSchemaOf(node: JsonNode): JsonNode | undefined {\n const schema = node.at('requestBody').at('content').at('application/json').at('schema');\n return schema.isObject() ? schema : undefined;\n }\n\n private responsesOf(node: JsonNode): readonly ResponseInfo[] {\n return node\n .at('responses')\n .entries()\n .map((entry: JsonEntry): ResponseInfo => {\n const schema = entry.value.at('content').at('application/json').at('schema');\n return new ResponseInfo(\n entry.key,\n entry.value.text('description') ?? '',\n schema.isObject() ? schema : undefined,\n );\n });\n }\n\n /**\n * The credentials this operation needs: its own `security` when it states one, the document's\n * otherwise. An operation stating `security: []` needs none, and that empty array is the\n * OpenAPI spelling of \"no credential\" rather than of \"inherit\" — so it must not fall back.\n */\n private operationSecurityKeys(root: JsonNode, node: JsonNode): readonly string[] {\n if (Array.isArray(node.at('security').raw)) {\n return this.securityKeysIn(node);\n }\n return this.securityKeysIn(root);\n }\n\n private securityKeysIn(holder: JsonNode): readonly string[] {\n const keys: string[] = [];\n for (const requirement of holder.list('security')) {\n for (const key of requirement.keys()) {\n if (!keys.includes(key)) {\n keys.push(key);\n }\n }\n }\n return keys;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SpecReader.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/spec/SpecReader.ts"],"names":[],"mappings":";;;AAAA,uCASmB;AAEnB,+CAA4C;AAC5C,iCAA8B;AAE9B,MAAM,Y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AAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,CAAC;YAChD,KAAK,MAAM,GAAG,IAAI,WAAW,CAAC,IAAI,EAAE,EAAE,CAAC;gBACnC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;oBACtB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AA3SD,gCA2SC","sourcesContent":["import {\n ApiSpec,\n HeaderInfo,\n NamedSchema,\n OperationInfo,\n ResponseInfo,\n SecuritySchemeInfo,\n ServerInfo,\n TagSection,\n} from './ApiSpec';\nimport { JsonEntry, JsonNode } from './JsonNode';\nimport { SchemaShape } from './SchemaShape';\nimport { Slug } from './Slug';\n\nconst HTTP_METHODS: readonly string[] = [\n 'get',\n 'put',\n 'post',\n 'delete',\n 'options',\n 'head',\n 'patch',\n 'trace',\n];\n\n/** The section untagged operations land in, so an operation is never unreachable from the nav. */\nexport const UNTAGGED_SECTION = 'Operations';\n\n/**\n * Reads one OpenAPI 3.0-or-3.1 document into an {@link ApiSpec}.\n *\n * ## Nothing here is SORTED\n *\n * Both orders in the finished site are published decisions somebody made, so neither is re-derived:\n * the reference order is the document's own `tags[]`, and the prose order is `docs.manifest.json`.\n * Alphabetising either is not a cleanup — it reorders partner-facing navigation.\n *\n * A tag that appears on an operation without being declared in `tags[]` still gets its own section,\n * appended in first-seen order. A tag missing from the sidebar is an operation a partner cannot\n * find, which reads exactly like an operation that does not exist.\n *\n * ## Webhooks\n *\n * A top-level `webhooks:` entry files into the SAME section as the operations sharing its tag, and\n * is APPENDED after them, because the events are what happens as a result of the calls above.\n */\nexport class SpecReader {\n private readonly shape = new SchemaShape();\n\n read(root: JsonNode): ApiSpec {\n const schemas = this.readSchemas(root);\n const sections = this.readSections(root);\n return new ApiSpec(\n root.at('info').text('title') ?? 'API reference',\n root.at('info').text('version') ?? '',\n root.at('info').text('description') ?? '',\n this.readServers(root),\n sections,\n this.readSecuritySchemes(root),\n schemas,\n this.securityKeysIn(root),\n );\n }\n\n private readServers(root: JsonNode): readonly ServerInfo[] {\n return root\n .list('servers')\n .map(\n (entry: JsonNode): ServerInfo =>\n new ServerInfo(entry.text('url') ?? '', entry.text('description')),\n );\n }\n\n private readSecuritySchemes(root: JsonNode): readonly SecuritySchemeInfo[] {\n const declared = root.at('components').at('securitySchemes');\n return declared\n .entries()\n .map(\n (entry: JsonEntry): SecuritySchemeInfo =>\n new SecuritySchemeInfo(\n entry.key,\n entry.value.text('type') ?? '',\n entry.value.text('in') ?? '',\n entry.value.text('name') ?? '',\n entry.value.text('description'),\n ),\n );\n }\n\n private readSchemas(root: JsonNode): readonly NamedSchema[] {\n const slugs = new Slug();\n return root\n .at('components')\n .at('schemas')\n .entries()\n .map(\n (entry: JsonEntry): NamedSchema =>\n new NamedSchema(\n entry.key,\n slugs.unique(entry.key),\n entry.value,\n this.shape.hasOwnPage(entry.value),\n ),\n );\n }\n\n private readSections(root: JsonNode): readonly TagSection[] {\n const slugs = new Slug();\n const operations = this.readOperations(root, slugs);\n const webhooks = this.readWebhooks(root, slugs);\n const order = this.sectionOrder(root, operations, webhooks);\n const sections: TagSection[] = [];\n for (const tag of order) {\n const inTag = operations.filter((one: OperationInfo): boolean => one.tag === tag);\n const eventsInTag = webhooks.filter((one: OperationInfo): boolean => one.tag === tag);\n sections.push(\n new TagSection(tag, this.tagDescription(root, tag), [...inTag, ...eventsInTag]),\n );\n }\n return sections;\n }\n\n /** `tags[]` first, in its published order, then any tag only an operation mentions. */\n private sectionOrder(\n root: JsonNode,\n operations: readonly OperationInfo[],\n webhooks: readonly OperationInfo[],\n ): readonly string[] {\n const order: string[] = [];\n for (const declared of root.list('tags')) {\n const name = declared.text('name');\n if (name !== undefined && !order.includes(name)) {\n order.push(name);\n }\n }\n for (const one of [...operations, ...webhooks]) {\n if (!order.includes(one.tag)) {\n order.push(one.tag);\n }\n }\n return order.filter((tag: string): boolean =>\n [...operations, ...webhooks].some((one: OperationInfo): boolean => one.tag === tag),\n );\n }\n\n private tagDescription(root: JsonNode, tag: string): string {\n for (const declared of root.list('tags')) {\n if (declared.text('name') === tag) {\n return declared.text('description') ?? '';\n }\n }\n return '';\n }\n\n private readOperations(root: JsonNode, slugs: Slug): readonly OperationInfo[] {\n const found: OperationInfo[] = [];\n for (const pathEntry of root.at('paths').entries()) {\n for (const methodEntry of pathEntry.value.entries()) {\n if (!HTTP_METHODS.includes(methodEntry.key)) {\n continue;\n }\n found.push(\n this.readOperation(\n root,\n methodEntry.value,\n slugs,\n methodEntry.key.toUpperCase(),\n pathEntry.key,\n false,\n pathEntry.value,\n ),\n );\n }\n }\n return found;\n }\n\n private readWebhooks(root: JsonNode, slugs: Slug): readonly OperationInfo[] {\n const found: OperationInfo[] = [];\n for (const eventEntry of root.at('webhooks').entries()) {\n for (const methodEntry of eventEntry.value.entries()) {\n if (!HTTP_METHODS.includes(methodEntry.key)) {\n continue;\n }\n found.push(\n this.readOperation(\n root,\n methodEntry.value,\n slugs,\n '',\n eventEntry.key,\n true,\n eventEntry.value,\n ),\n );\n }\n }\n return found;\n }\n\n private readOperation(\n root: JsonNode,\n node: JsonNode,\n slugs: Slug,\n httpMethod: string,\n pathOrEvent: string,\n isWebhook: boolean,\n pathItem: JsonNode,\n ): OperationInfo {\n const name = node.text('summary') ?? node.text('operationId') ?? pathOrEvent;\n return new OperationInfo(\n name,\n slugs.unique(name),\n httpMethod,\n isWebhook ? '' : pathOrEvent,\n node.text('description') ?? '',\n this.tagOf(node),\n this.requestSchemaOf(node),\n this.requestHeadersOf(root, pathItem, node),\n this.responsesOf(root, node),\n isWebhook,\n isWebhook ? [] : this.operationSecurityKeys(root, node),\n isWebhook ? pathOrEvent : '',\n );\n }\n\n private tagOf(node: JsonNode): string {\n for (const tag of node.list('tags')) {\n const name = tag.asText();\n if (name !== undefined) {\n return name;\n }\n }\n return UNTAGGED_SECTION;\n }\n\n private requestSchemaOf(node: JsonNode): JsonNode | undefined {\n const schema = node.at('requestBody').at('content').at('application/json').at('schema');\n return schema.isObject() ? schema : undefined;\n }\n\n private responsesOf(root: JsonNode, node: JsonNode): readonly ResponseInfo[] {\n return node\n .at('responses')\n .entries()\n .map((entry: JsonEntry): ResponseInfo => {\n const response = this.dereference(root, entry.value);\n const schema = response.at('content').at('application/json').at('schema');\n return new ResponseInfo(\n entry.key,\n response.text('description') ?? '',\n schema.isObject() ? schema : undefined,\n this.responseHeadersOf(root, response),\n );\n });\n }\n\n /** A response's `headers` map, each entry resolved through a `$ref` into `components.headers`. */\n private responseHeadersOf(root: JsonNode, response: JsonNode): readonly HeaderInfo[] {\n return response\n .at('headers')\n .entries()\n .map((entry: JsonEntry): HeaderInfo => {\n const header = this.dereference(root, entry.value);\n return new HeaderInfo(\n entry.key,\n header.flag('required') === true,\n header.text('description') ?? '',\n header.at('schema'),\n );\n });\n }\n\n /**\n * Every `in: \"header\"` parameter: the PATH ITEM's first, then the operation's — an operation\n * parameter of the same name overrides the path item's, which is OpenAPI's own rule.\n */\n private requestHeadersOf(\n root: JsonNode,\n pathItem: JsonNode,\n node: JsonNode,\n ): readonly HeaderInfo[] {\n const byName = new Map<string, HeaderInfo>();\n for (const holder of [pathItem, node]) {\n for (const listed of holder.list('parameters')) {\n const parameter = this.dereference(root, listed);\n const name = parameter.text('name');\n if (parameter.text('in') !== 'header' || name === undefined) {\n continue;\n }\n byName.set(\n name.toLowerCase(),\n new HeaderInfo(\n name,\n parameter.flag('required') === true,\n parameter.text('description') ?? '',\n parameter.at('schema'),\n ),\n );\n }\n }\n return Array.from(byName.values());\n }\n\n /**\n * The object a LOCAL `$ref` (`#/components/headers/x-request-id`) points at, or the node itself\n * when it is no reference. A dangling or foreign reference also reads as the node itself, so the\n * header still renders under its own name rather than vanishing — the same total-reading choice\n * `JsonNode` makes everywhere.\n */\n private dereference(root: JsonNode, node: JsonNode): JsonNode {\n const pointer = node.text('$ref');\n if (pointer === undefined || !pointer.startsWith('#/')) {\n return node;\n }\n let current = root;\n for (const step of pointer.slice(2).split('/')) {\n current = current.at(step.replace(/~1/g, '/').replace(/~0/g, '~'));\n }\n return current.isObject() ? current : node;\n }\n\n /**\n * The credentials this operation needs: its own `security` when it states one, the document's\n * otherwise. An operation stating `security: []` needs none, and that empty array is the\n * OpenAPI spelling of \"no credential\" rather than of \"inherit\" — so it must not fall back.\n */\n private operationSecurityKeys(root: JsonNode, node: JsonNode): readonly string[] {\n if (Array.isArray(node.at('security').raw)) {\n return this.securityKeysIn(node);\n }\n return this.securityKeysIn(root);\n }\n\n private securityKeysIn(holder: JsonNode): readonly string[] {\n const keys: string[] = [];\n for (const requirement of holder.list('security')) {\n for (const key of requirement.keys()) {\n if (!keys.includes(key)) {\n keys.push(key);\n }\n }\n }\n return keys;\n }\n}\n"]}
|