@webpieces/docs-site 0.4.957 → 0.4.959
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/render/OperationPageRenderer.d.ts +1 -1
- package/src/render/OperationPageRenderer.js +7 -1
- package/src/render/OperationPageRenderer.js.map +1 -1
- package/src/samples/CodeSamples.d.ts +2 -0
- package/src/samples/CodeSamples.js +9 -1
- package/src/samples/CodeSamples.js.map +1 -1
- package/src/spec/ApiSpec.d.ts +9 -1
- package/src/spec/ApiSpec.js +9 -1
- package/src/spec/ApiSpec.js.map +1 -1
- package/src/spec/SpecReader.d.ts +4 -3
- package/src/spec/SpecReader.js +7 -6
- 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.959",
|
|
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",
|
|
@@ -42,7 +42,7 @@ export declare class OperationPageRenderer {
|
|
|
42
42
|
* the method, which is what a developer searches their code for.
|
|
43
43
|
*/
|
|
44
44
|
private head;
|
|
45
|
-
/** The request's
|
|
45
|
+
/** The request's path, query and header parameters, then its body — each only when there is one. */
|
|
46
46
|
private requestSection;
|
|
47
47
|
private responseSection;
|
|
48
48
|
private response;
|
|
@@ -67,9 +67,15 @@ class OperationPageRenderer {
|
|
|
67
67
|
}
|
|
68
68
|
return `<div class="op-head"><span class="badge">${this.html.escape(operation.httpMethod)}</span><code class="op-path">${this.html.escape(operation.path)}</code>${id}</div>`;
|
|
69
69
|
}
|
|
70
|
-
/** The request's
|
|
70
|
+
/** The request's path, query and header parameters, then its body — each only when there is one. */
|
|
71
71
|
requestSection(operation, prefix) {
|
|
72
72
|
const parts = [];
|
|
73
|
+
if (operation.pathParameters.length > 0) {
|
|
74
|
+
parts.push(`<h2>Path parameters</h2>${this.headers.render(operation.pathParameters, prefix)}`);
|
|
75
|
+
}
|
|
76
|
+
if (operation.queryParameters.length > 0) {
|
|
77
|
+
parts.push(`<h2>Query parameters</h2>${this.headers.render(operation.queryParameters, prefix)}`);
|
|
78
|
+
}
|
|
73
79
|
if (operation.requestHeaders.length > 0) {
|
|
74
80
|
parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders, prefix)}`);
|
|
75
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OperationPageRenderer.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/render/OperationPageRenderer.ts"],"names":[],"mappings":";;;AAOA,iCAA8B;AAK9B,yCAAsC;AAEtC,yDAAyD;AAC5C,QAAA,aAAa,GAAG,SAAS,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAa,qBAAqB;IAIT;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IAZJ,IAAI,GAAG,IAAI,WAAI,EAAE,CAAC;IAEnC,YACqB,IAAa,EACb,MAAwB,EACxB,KAAwB,EACxB,QAAkB,EAClB,KAAmB,EACnB,OAA0B,EAC1B,QAAwB,EACxB,MAAc,EACd,IAAc,EACd,OAA2B;QAT3B,SAAI,GAAJ,IAAI,CAAS;QACb,WAAM,GAAN,MAAM,CAAkB;QACxB,UAAK,GAAL,KAAK,CAAmB;QACxB,aAAQ,GAAR,QAAQ,CAAU;QAClB,UAAK,GAAL,KAAK,CAAc;QACnB,YAAO,GAAP,OAAO,CAAmB;QAC1B,aAAQ,GAAR,QAAQ,CAAgB;QACxB,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAU;QACd,YAAO,GAAP,OAAO,CAAoB;IAC7C,CAAC;IAEJ,IAAI,CAAC,SAAwB;QACzB,MAAM,GAAG,GA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import { ApiSpec, OperationInfo, ResponseInfo } from '../spec/ApiSpec';\nimport { CardRenderer } from './CardRenderer';\nimport { CodeSampleBuilder } from '../samples/CodeSamples';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\nimport { FieldTreeBuilder } from '../spec/FieldTree';\nimport { FieldTreeRenderer } from './FieldTreeRenderer';\nimport { HeaderListRenderer } from './HeaderListRenderer';\nimport { Html } from './Html';\nimport { JsonNode } from '../spec/JsonNode';\nimport { Layout } from './Layout';\nimport { Markdown } from '../markdown/Markdown';\nimport { SiteUrls } from './SiteUrls';\nimport { SitePage } from './SitePage';\n\n/** The badge a webhook carries everywhere it appears. */\nexport const WEBHOOK_BADGE = 'WEBHOOK';\n\n/**\n * One pre-rendered page per operation, at `reference/<kebab-operation>/index.html`.\n *\n * ## What a WEBHOOK page leaves out, and why\n *\n * No method, no path, no code samples. The url is the PARTNER's — they host the endpoint wherever\n * they choose — so a `POST https://api.example.com/...` sample on a webhook page invites them to\n * call something that does not exist. What it keeps is the payload, because the payload is the part\n * that IS ours, and the event name, because that is what they match on the wire.\n */\nexport class OperationPageRenderer {\n private readonly html = new Html();\n\n constructor(\n private readonly spec: ApiSpec,\n private readonly fields: FieldTreeBuilder,\n private readonly trees: FieldTreeRenderer,\n private readonly markdown: Markdown,\n private readonly cards: CardRenderer,\n private readonly samples: CodeSampleBuilder,\n private readonly examples: ExampleBuilder,\n private readonly layout: Layout,\n private readonly urls: SiteUrls,\n private readonly headers: HeaderListRenderer,\n ) {}\n\n page(operation: OperationInfo): SitePage {\n const url = this.urls.operation(operation);\n const prefix = this.urls.prefixFor(url);\n return new SitePage(\n url,\n operation.name,\n this.layout.render(\n url,\n operation.name,\n this.body(operation, prefix),\n this.cardColumn(operation),\n ),\n );\n }\n\n private body(operation: OperationInfo, prefix: string): string {\n const parts = [this.head(operation), `<h1>${this.html.escape(operation.name)}</h1>`];\n if (operation.description !== '') {\n parts.push(this.markdown.forPage(prefix).render(operation.description));\n }\n parts.push(this.requestSection(operation, prefix));\n parts.push(this.responseSection(operation, prefix));\n return parts.join('\\n');\n }\n\n /**\n * The badge, the path (or event) and the `operationId`. The page HEADING is the operation's\n * summary (#1296); the operationId stays visible here because it is what a generated client names\n * the method, which is what a developer searches their code for.\n */\n private head(operation: OperationInfo): string {\n const id =\n operation.operationId === ''\n ? ''\n : `<code class=\"op-id\" title=\"operationId\">${this.html.escape(operation.operationId)}</code>`;\n if (operation.isWebhook) {\n return `<div class=\"op-head\"><span class=\"badge\">${WEBHOOK_BADGE}</span><code class=\"op-path\">${this.html.escape(operation.eventName)}</code>${id}</div>`;\n }\n return `<div class=\"op-head\"><span class=\"badge\">${this.html.escape(operation.httpMethod)}</span><code class=\"op-path\">${this.html.escape(operation.path)}</code>${id}</div>`;\n }\n\n /** The request's `in: \"header\"` parameters, then its body — each only when there is one. */\n private requestSection(operation: OperationInfo, prefix: string): string {\n const parts: string[] = [];\n if (operation.requestHeaders.length > 0) {\n parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders, prefix)}`);\n }\n if (operation.requestSchema !== undefined) {\n parts.push(`<h2>Request body</h2>${this.tree(operation.requestSchema, prefix)}`);\n }\n return parts.join('');\n }\n\n private responseSection(operation: OperationInfo, prefix: string): string {\n if (operation.responses.length === 0) {\n return '';\n }\n const blocks = operation.responses\n .map((response: ResponseInfo): string => this.response(response, prefix))\n .join('');\n return `<h2>Responses</h2>${blocks}`;\n }\n\n private response(response: ResponseInfo, prefix: string): string {\n // Inline markdown: a `{@link}` in `@returns` arrives as a code span, and may link (#1284).\n const summary = `${this.html.escape(response.status)} — ${this.markdown.forPage(prefix).inline(response.description)}`;\n const body =\n response.schema === undefined\n ? '<p class=\"field-doc\">No body.</p>'\n : this.tree(response.schema, prefix);\n // The headers ride the card beside the body (#1292) — the response a partner holds carries both.\n const headers = this.headers.render(response.headers, prefix);\n return `<details class=\"disclosure\" open><summary>${summary}</summary>${headers}${body}</details>`;\n }\n\n /**\n * A `oneOf` renders as expanded variants; anything else renders as one flat field tree. An INLINE\n * body (#1303) is headed by its `title` and `description` first: it has no schema page, so this\n * page is the only place a reader can see the name a generated client gives it, or its prose.\n */\n private tree(schema: JsonNode, prefix: string): string {\n return this.inlineHead(schema) + this.fieldTree(schema, prefix);\n }\n\n private inlineHead(schema: JsonNode): string {\n const head = this.fields.inlineHeadOf(schema);\n if (head === undefined) {\n return '';\n }\n const title =\n head.title === ''\n ? ''\n : `<p class=\"body-type\"><code title=\"schema title\">${this.html.escape(head.title)}</code></p>`;\n const description =\n head.description === ''\n ? ''\n : `<div class=\"field-doc\">${this.markdown.render(head.description)}</div>`;\n return title + description;\n }\n\n private fieldTree(schema: JsonNode, prefix: string): string {\n const variants = this.fields.variantsOf(schema);\n if (variants.length > 0) {\n return this.trees.renderVariants(\n variants,\n this.fields.discriminatorPropertyOf(schema),\n prefix,\n );\n }\n return this.trees.render(this.fields.fieldsOf(schema), prefix);\n }\n\n private cardColumn(operation: OperationInfo): string {\n const payload = this.examples.render(this.examples.build(operation.requestSchema));\n if (operation.isWebhook) {\n return this.cards.example('EVENT PAYLOAD', payload);\n }\n return [\n this.cards.authorization(operation, this.spec.securitySchemes),\n this.cards.samples(this.samples.samplesFor(operation)),\n ].join('\\n');\n }\n}\n"]}
|
|
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,OAA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AI,CAAC,MAAM,CAAC,uBAAuB,CAAC,MAAM,CAAC,EAC3C,MAAM,CACT,CAAC;QACN,CAAC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;IACnE,CAAC;IAEO,UAAU,CAAC,SAAwB;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC;QACnF,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC;QACxD,CAAC;QACD,OAAO;YACH,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;YAC9D,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;SACzD,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC;CACJ;AAhJD,sDAgJC","sourcesContent":["import { ApiSpec, OperationInfo, ResponseInfo } from '../spec/ApiSpec';\nimport { CardRenderer } from './CardRenderer';\nimport { CodeSampleBuilder } from '../samples/CodeSamples';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\nimport { FieldTreeBuilder } from '../spec/FieldTree';\nimport { FieldTreeRenderer } from './FieldTreeRenderer';\nimport { HeaderListRenderer } from './HeaderListRenderer';\nimport { Html } from './Html';\nimport { JsonNode } from '../spec/JsonNode';\nimport { Layout } from './Layout';\nimport { Markdown } from '../markdown/Markdown';\nimport { SiteUrls } from './SiteUrls';\nimport { SitePage } from './SitePage';\n\n/** The badge a webhook carries everywhere it appears. */\nexport const WEBHOOK_BADGE = 'WEBHOOK';\n\n/**\n * One pre-rendered page per operation, at `reference/<kebab-operation>/index.html`.\n *\n * ## What a WEBHOOK page leaves out, and why\n *\n * No method, no path, no code samples. The url is the PARTNER's — they host the endpoint wherever\n * they choose — so a `POST https://api.example.com/...` sample on a webhook page invites them to\n * call something that does not exist. What it keeps is the payload, because the payload is the part\n * that IS ours, and the event name, because that is what they match on the wire.\n */\nexport class OperationPageRenderer {\n private readonly html = new Html();\n\n constructor(\n private readonly spec: ApiSpec,\n private readonly fields: FieldTreeBuilder,\n private readonly trees: FieldTreeRenderer,\n private readonly markdown: Markdown,\n private readonly cards: CardRenderer,\n private readonly samples: CodeSampleBuilder,\n private readonly examples: ExampleBuilder,\n private readonly layout: Layout,\n private readonly urls: SiteUrls,\n private readonly headers: HeaderListRenderer,\n ) {}\n\n page(operation: OperationInfo): SitePage {\n const url = this.urls.operation(operation);\n const prefix = this.urls.prefixFor(url);\n return new SitePage(\n url,\n operation.name,\n this.layout.render(\n url,\n operation.name,\n this.body(operation, prefix),\n this.cardColumn(operation),\n ),\n );\n }\n\n private body(operation: OperationInfo, prefix: string): string {\n const parts = [this.head(operation), `<h1>${this.html.escape(operation.name)}</h1>`];\n if (operation.description !== '') {\n parts.push(this.markdown.forPage(prefix).render(operation.description));\n }\n parts.push(this.requestSection(operation, prefix));\n parts.push(this.responseSection(operation, prefix));\n return parts.join('\\n');\n }\n\n /**\n * The badge, the path (or event) and the `operationId`. The page HEADING is the operation's\n * summary (#1296); the operationId stays visible here because it is what a generated client names\n * the method, which is what a developer searches their code for.\n */\n private head(operation: OperationInfo): string {\n const id =\n operation.operationId === ''\n ? ''\n : `<code class=\"op-id\" title=\"operationId\">${this.html.escape(operation.operationId)}</code>`;\n if (operation.isWebhook) {\n return `<div class=\"op-head\"><span class=\"badge\">${WEBHOOK_BADGE}</span><code class=\"op-path\">${this.html.escape(operation.eventName)}</code>${id}</div>`;\n }\n return `<div class=\"op-head\"><span class=\"badge\">${this.html.escape(operation.httpMethod)}</span><code class=\"op-path\">${this.html.escape(operation.path)}</code>${id}</div>`;\n }\n\n /** The request's path, query and 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.pathParameters.length > 0) {\n parts.push(`<h2>Path parameters</h2>${this.headers.render(operation.pathParameters, prefix)}`);\n }\n if (operation.queryParameters.length > 0) {\n parts.push(`<h2>Query parameters</h2>${this.headers.render(operation.queryParameters, prefix)}`);\n }\n if (operation.requestHeaders.length > 0) {\n parts.push(`<h2>Request headers</h2>${this.headers.render(operation.requestHeaders, prefix)}`);\n }\n if (operation.requestSchema !== undefined) {\n parts.push(`<h2>Request body</h2>${this.tree(operation.requestSchema, prefix)}`);\n }\n return parts.join('');\n }\n\n private responseSection(operation: OperationInfo, prefix: string): string {\n if (operation.responses.length === 0) {\n return '';\n }\n const blocks = operation.responses\n .map((response: ResponseInfo): string => this.response(response, prefix))\n .join('');\n return `<h2>Responses</h2>${blocks}`;\n }\n\n private response(response: ResponseInfo, prefix: string): string {\n // Inline markdown: a `{@link}` in `@returns` arrives as a code span, and may link (#1284).\n const summary = `${this.html.escape(response.status)} — ${this.markdown.forPage(prefix).inline(response.description)}`;\n const body =\n response.schema === undefined\n ? '<p class=\"field-doc\">No body.</p>'\n : this.tree(response.schema, prefix);\n // The headers ride the card beside the body (#1292) — the response a partner holds carries both.\n const headers = this.headers.render(response.headers, prefix);\n return `<details class=\"disclosure\" open><summary>${summary}</summary>${headers}${body}</details>`;\n }\n\n /**\n * A `oneOf` renders as expanded variants; anything else renders as one flat field tree. An INLINE\n * body (#1303) is headed by its `title` and `description` first: it has no schema page, so this\n * page is the only place a reader can see the name a generated client gives it, or its prose.\n */\n private tree(schema: JsonNode, prefix: string): string {\n return this.inlineHead(schema) + this.fieldTree(schema, prefix);\n }\n\n private inlineHead(schema: JsonNode): string {\n const head = this.fields.inlineHeadOf(schema);\n if (head === undefined) {\n return '';\n }\n const title =\n head.title === ''\n ? ''\n : `<p class=\"body-type\"><code title=\"schema title\">${this.html.escape(head.title)}</code></p>`;\n const description =\n head.description === ''\n ? ''\n : `<div class=\"field-doc\">${this.markdown.render(head.description)}</div>`;\n return title + description;\n }\n\n private fieldTree(schema: JsonNode, prefix: string): string {\n const variants = this.fields.variantsOf(schema);\n if (variants.length > 0) {\n return this.trees.renderVariants(\n variants,\n this.fields.discriminatorPropertyOf(schema),\n prefix,\n );\n }\n return this.trees.render(this.fields.fieldsOf(schema), prefix);\n }\n\n private cardColumn(operation: OperationInfo): string {\n const payload = this.examples.render(this.examples.build(operation.requestSchema));\n if (operation.isWebhook) {\n return this.cards.example('EVENT PAYLOAD', payload);\n }\n return [\n this.cards.authorization(operation, this.spec.securitySchemes),\n this.cards.samples(this.samples.samplesFor(operation)),\n ].join('\\n');\n }\n}\n"]}
|
|
@@ -115,9 +115,17 @@ class CodeSampleBuilder {
|
|
|
115
115
|
lines.push(` body: JSON.stringify(${this.indent(body, ' ')}),`);
|
|
116
116
|
}
|
|
117
117
|
lines.push('});');
|
|
118
|
-
|
|
118
|
+
// A success with no body (a 204) has nothing to parse (#1339).
|
|
119
|
+
if (this.successHasBody(operation)) {
|
|
120
|
+
lines.push('const result = await response.json();');
|
|
121
|
+
}
|
|
119
122
|
return lines.join('\n');
|
|
120
123
|
}
|
|
124
|
+
/** True unless the operation's only 2xx response documents no body. */
|
|
125
|
+
successHasBody(operation) {
|
|
126
|
+
const success = operation.responses.find((response) => response.status.startsWith('2'));
|
|
127
|
+
return success === undefined || success.schema !== undefined;
|
|
128
|
+
}
|
|
121
129
|
go(operation, url, headers, body) {
|
|
122
130
|
const lines = [];
|
|
123
131
|
if (body === '') {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeSamples.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/samples/CodeSamples.ts"],"names":[],"mappings":";;;AAGA,uGAAuG;AACvG,MAAa,UAAU;IAEN;IACA;IACA;IAHb,YACa,EAAU,EACV,KAAa,EACb,MAAc;QAFd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,CAAC,IAAI,CACN,gBAAgB,SAAS,CAAC,UAAU,yCAAyC,CAChF,CAAC;QACN,CAAC;aAAM,CAAC;YACJ,KAAK,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;YAC9D,KAAK,CAAC,IAAI,CACN,gBAAgB,SAAS,CAAC,UAAU,4CAA4C,CACnF,CAAC;YACF,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACjB,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACxB,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QAC5B,KAAK,CAAC,IAAI,CACN,gFAAgF,CACnF,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,MAAc;QACvC,OAAO,IAAI;aACN,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC;aACvF,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACJ;AA1JD,8CA0JC","sourcesContent":["import { ApiSpec, OperationInfo, SecuritySchemeInfo } from '../spec/ApiSpec';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\n\n/** One language's sample for one operation. `id` is the tab's value, `label` is what a reader sees. */\nexport class CodeSample {\n constructor(\n readonly id: string,\n readonly label: string,\n readonly source: string,\n ) {}\n}\n\n/** One header a sample sends: the name the document declares, and a placeholder for the value. */\nexport class SampleHeader {\n constructor(\n readonly name: string,\n readonly value: string,\n ) {}\n}\n\n/**\n * Builds the code samples FROM THE SPEC: the server url, the path, the header names the document's\n * own security schemes declare, and an example body generated from the request schema.\n *\n * Nothing here is authored per operation, which is the point. A sample somebody wrote by hand is a\n * copy of the contract that no build can contradict, so the first rename leaves a partner pasting a\n * header the server stopped reading.\n *\n * ## No samples for a webhook\n *\n * A webhook's url belongs to the PARTNER. A curl of ours against one would invite them to call\n * something that does not exist, so the whole card is absent rather than present-and-wrong.\n *\n * ## No vendor logos\n *\n * The languages are labelled in words. The gopher and the Java cup are other companies'\n * trademarks, and a docs generator that ships them hands every consumer that problem too.\n */\nexport class CodeSampleBuilder {\n constructor(\n private readonly spec: ApiSpec,\n private readonly examples: ExampleBuilder,\n ) {}\n\n /** Every sample for an operation, in published tab order. Empty for a webhook. */\n samplesFor(operation: OperationInfo): readonly CodeSample[] {\n if (operation.isWebhook) {\n return [];\n }\n const url = `${this.baseUrl()}${operation.path}`;\n const headers = this.headersFor(operation);\n const body = this.examples.render(this.examples.build(operation.requestSchema));\n return [\n new CodeSample('http', 'HTTP', this.http(operation, headers, body)),\n new CodeSample(\n 'javascript',\n 'JavaScript',\n this.javascript(operation, url, headers, body),\n ),\n new CodeSample('go', 'Go', this.go(operation, url, headers, body)),\n new CodeSample('java', 'Java', this.java(operation, url, headers, body)),\n ];\n }\n\n /** The header each security scheme this operation requires is sent in. */\n headersFor(operation: OperationInfo): readonly SampleHeader[] {\n const headers: SampleHeader[] = [];\n for (const key of operation.securityKeys) {\n const scheme = this.spec.securitySchemes.find(\n (one: SecuritySchemeInfo): boolean => one.key === key,\n );\n if (scheme !== undefined && scheme.sentIn === 'header' && scheme.headerName !== '') {\n headers.push(new SampleHeader(scheme.headerName, `<your ${scheme.key}>`));\n }\n }\n return headers;\n }\n\n private baseUrl(): string {\n const first = this.spec.servers[0];\n return first === undefined ? '' : first.url.replace(/\\/$/, '');\n }\n\n private hostName(): string {\n const host = this.baseUrl().replace(/^https?:\\/\\//, '');\n return host === '' ? 'your-api-host' : host;\n }\n\n private http(operation: OperationInfo, headers: readonly SampleHeader[], body: string): string {\n const lines = [\n `${operation.httpMethod} ${operation.path} HTTP/1.1`,\n `Host: ${this.hostName()}`,\n ];\n for (const header of headers) {\n lines.push(`${header.name}: ${header.value}`);\n }\n if (body !== '') {\n lines.push('Content-Type: application/json');\n lines.push('');\n lines.push(body);\n }\n return lines.join('\\n');\n }\n\n private javascript(\n operation: OperationInfo,\n url: string,\n headers: readonly SampleHeader[],\n body: string,\n ): string {\n const lines = [\n // webpieces-disable no-fetch -- sample TEXT a partner pastes into their own client; nothing here calls anything\n `const response = await fetch('${url}', {`,\n ` method: '${operation.httpMethod}',`,\n ' headers: {',\n ];\n for (const header of headers) {\n lines.push(` '${header.name}': '${header.value}',`);\n }\n if (body !== '') {\n lines.push(\" 'Content-Type': 'application/json',\");\n }\n lines.push(' },');\n if (body !== '') {\n lines.push(` body: JSON.stringify(${this.indent(body, ' ')}),`);\n }\n lines.push('});');\n lines.push('const result = await response.json();');\n return lines.join('\\n');\n }\n\n private go(\n operation: OperationInfo,\n url: string,\n headers: readonly SampleHeader[],\n body: string,\n ): string {\n const lines: string[] = [];\n if (body === '') {\n lines.push(`req, _ := http.NewRequest(\"${operation.httpMethod}\", \"${url}\", nil)`);\n } else {\n lines.push(`body := []byte(\\`${body}\\`)`);\n lines.push(\n `req, _ := http.NewRequest(\"${operation.httpMethod}\", \"${url}\", bytes.NewReader(body))`,\n );\n lines.push('req.Header.Set(\"Content-Type\", \"application/json\")');\n }\n for (const header of headers) {\n lines.push(`req.Header.Set(\"${header.name}\", \"${header.value}\")`);\n }\n lines.push('resp, err := http.DefaultClient.Do(req)');\n return lines.join('\\n');\n }\n\n private java(\n operation: OperationInfo,\n url: string,\n headers: readonly SampleHeader[],\n body: string,\n ): string {\n const lines = [\n 'HttpRequest request = HttpRequest.newBuilder()',\n ` .uri(URI.create(\"${url}\"))`,\n ];\n for (const header of headers) {\n lines.push(` .header(\"${header.name}\", \"${header.value}\")`);\n }\n if (body === '') {\n lines.push(\n ` .method(\"${operation.httpMethod}\", HttpRequest.BodyPublishers.noBody())`,\n );\n } else {\n lines.push(' .header(\"Content-Type\", \"application/json\")');\n lines.push(\n ` .method(\"${operation.httpMethod}\", HttpRequest.BodyPublishers.ofString(\"\"\"`,\n );\n lines.push(body);\n lines.push('\"\"\"))');\n }\n lines.push(' .build();');\n lines.push(\n 'HttpResponse<String> response = client.send(request, BodyHandlers.ofString());',\n );\n return lines.join('\\n');\n }\n\n private indent(body: string, prefix: string): string {\n return body\n .split('\\n')\n .map((line: string, index: number): string => (index === 0 ? line : `${prefix}${line}`))\n .join('\\n');\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"CodeSamples.js","sourceRoot":"","sources":["../../../../../../packages/docs/docs-site/src/samples/CodeSamples.ts"],"names":[],"mappings":";;;AAGA,uGAAuG;AACvG,MAAa,UAAU;IAEN;IACA;IACA;IAHb,YACa,EAAU,EACV,KAAa,EACb,MAAc;QAFd,OAAE,GAAF,EAAE,CAAQ;QACV,UAAK,GAAL,KAAK,CAAQ;QACb,WAAM,GAAN,MAAM,CAAQ;IACxB,CAAC;CACP;AAND,gCAMC;AAED,kGAAkG;AAClG,MAAa,YAAY;IAER;IACA;IAFb,YACa,IAAY,EACZ,KAAa;QADb,SAAI,GAAJ,IAAI,CAAQ;QACZ,UAAK,GAAL,KAAK,CAAQ;IACvB,CAAC;CACP;AALD,oCAKC;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,iBAAiB;IAEL;IACA;IAFrB,YACqB,IAAa,EACb,QAAwB;QADxB,SAAI,GAAJ,IAAI,CAAS;QACb,aAAQ,GAAR,QAAQ,CAAgB;IAC1C,CAAC;IAEJ,kFAAkF;IAClF,UAAU,CAAC,SAAwB;QAC/B,IAAI,SAAS,CAAC,SAAS,EAAE,CAAC;YACtB,OAAO,EAAE,CAAC;QACd,CAAC;QACD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,SAAS,CAAC,IAAI,EAAE,CAAC;QACjD,MAAM,OAAO,GAAG,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,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FAAgF,CACnF,CAAC;QACF,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;IAEO,MAAM,CAAC,IAAY,EAAE,MAAc;QACvC,OAAO,IAAI;aACN,KAAK,CAAC,IAAI,CAAC;aACX,GAAG,CAAC,CAAC,IAAY,EAAE,KAAa,EAAU,EAAE,CAAC,CAAC,KAAK,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,IAAI,EAAE,CAAC,CAAC;aACvF,IAAI,CAAC,IAAI,CAAC,CAAC;IACpB,CAAC;CACJ;AAnKD,8CAmKC","sourcesContent":["import { ApiSpec, OperationInfo, ResponseInfo, SecuritySchemeInfo } from '../spec/ApiSpec';\nimport { ExampleBuilder } from '../spec/ExampleBuilder';\n\n/** One language's sample for one operation. `id` is the tab's value, `label` is what a reader sees. */\nexport class CodeSample {\n constructor(\n readonly id: string,\n readonly label: string,\n readonly source: string,\n ) {}\n}\n\n/** One header a sample sends: the name the document declares, and a placeholder for the value. */\nexport class SampleHeader {\n constructor(\n readonly name: string,\n readonly value: string,\n ) {}\n}\n\n/**\n * Builds the code samples FROM THE SPEC: the server url, the path, the header names the document's\n * own security schemes declare, and an example body generated from the request schema.\n *\n * Nothing here is authored per operation, which is the point. A sample somebody wrote by hand is a\n * copy of the contract that no build can contradict, so the first rename leaves a partner pasting a\n * header the server stopped reading.\n *\n * ## No samples for a webhook\n *\n * A webhook's url belongs to the PARTNER. A curl of ours against one would invite them to call\n * something that does not exist, so the whole card is absent rather than present-and-wrong.\n *\n * ## No vendor logos\n *\n * The languages are labelled in words. The gopher and the Java cup are other companies'\n * trademarks, and a docs generator that ships them hands every consumer that problem too.\n */\nexport class CodeSampleBuilder {\n constructor(\n private readonly spec: ApiSpec,\n private readonly examples: ExampleBuilder,\n ) {}\n\n /** Every sample for an operation, in published tab order. Empty for a webhook. */\n samplesFor(operation: OperationInfo): readonly CodeSample[] {\n if (operation.isWebhook) {\n return [];\n }\n const url = `${this.baseUrl()}${operation.path}`;\n const headers = this.headersFor(operation);\n const body = this.examples.render(this.examples.build(operation.requestSchema));\n return [\n new CodeSample('http', 'HTTP', this.http(operation, headers, body)),\n new CodeSample(\n 'javascript',\n 'JavaScript',\n this.javascript(operation, url, headers, body),\n ),\n new CodeSample('go', 'Go', this.go(operation, url, headers, body)),\n new CodeSample('java', 'Java', this.java(operation, url, headers, body)),\n ];\n }\n\n /** The header each security scheme this operation requires is sent in. */\n headersFor(operation: OperationInfo): readonly SampleHeader[] {\n const headers: SampleHeader[] = [];\n for (const key of operation.securityKeys) {\n const scheme = this.spec.securitySchemes.find(\n (one: SecuritySchemeInfo): boolean => one.key === key,\n );\n if (scheme !== undefined && scheme.sentIn === 'header' && scheme.headerName !== '') {\n headers.push(new SampleHeader(scheme.headerName, `<your ${scheme.key}>`));\n }\n }\n return headers;\n }\n\n private baseUrl(): string {\n const first = this.spec.servers[0];\n return first === undefined ? '' : first.url.replace(/\\/$/, '');\n }\n\n private hostName(): string {\n const host = this.baseUrl().replace(/^https?:\\/\\//, '');\n return host === '' ? 'your-api-host' : host;\n }\n\n private http(operation: OperationInfo, headers: readonly SampleHeader[], body: string): string {\n const lines = [\n `${operation.httpMethod} ${operation.path} HTTP/1.1`,\n `Host: ${this.hostName()}`,\n ];\n for (const header of headers) {\n lines.push(`${header.name}: ${header.value}`);\n }\n if (body !== '') {\n lines.push('Content-Type: application/json');\n lines.push('');\n lines.push(body);\n }\n return lines.join('\\n');\n }\n\n private javascript(\n operation: OperationInfo,\n url: string,\n headers: readonly SampleHeader[],\n body: string,\n ): string {\n const lines = [\n // webpieces-disable no-fetch -- sample TEXT a partner pastes into their own client; nothing here calls anything\n `const response = await fetch('${url}', {`,\n ` method: '${operation.httpMethod}',`,\n ' headers: {',\n ];\n for (const header of headers) {\n lines.push(` '${header.name}': '${header.value}',`);\n }\n if (body !== '') {\n lines.push(\" 'Content-Type': 'application/json',\");\n }\n lines.push(' },');\n if (body !== '') {\n lines.push(` body: JSON.stringify(${this.indent(body, ' ')}),`);\n }\n lines.push('});');\n // A success with no body (a 204) has nothing to parse (#1339).\n if (this.successHasBody(operation)) {\n lines.push('const result = await response.json();');\n }\n return lines.join('\\n');\n }\n\n /** True unless the operation's only 2xx response documents no body. */\n private successHasBody(operation: OperationInfo): boolean {\n const success = operation.responses.find((response: ResponseInfo) => response.status.startsWith('2'));\n return success === undefined || success.schema !== undefined;\n }\n\n private go(\n operation: OperationInfo,\n url: string,\n headers: readonly SampleHeader[],\n body: string,\n ): string {\n const lines: string[] = [];\n if (body === '') {\n lines.push(`req, _ := http.NewRequest(\"${operation.httpMethod}\", \"${url}\", nil)`);\n } else {\n lines.push(`body := []byte(\\`${body}\\`)`);\n lines.push(\n `req, _ := http.NewRequest(\"${operation.httpMethod}\", \"${url}\", bytes.NewReader(body))`,\n );\n lines.push('req.Header.Set(\"Content-Type\", \"application/json\")');\n }\n for (const header of headers) {\n lines.push(`req.Header.Set(\"${header.name}\", \"${header.value}\")`);\n }\n lines.push('resp, err := http.DefaultClient.Do(req)');\n return lines.join('\\n');\n }\n\n private java(\n operation: OperationInfo,\n url: string,\n headers: readonly SampleHeader[],\n body: string,\n ): string {\n const lines = [\n 'HttpRequest request = HttpRequest.newBuilder()',\n ` .uri(URI.create(\"${url}\"))`,\n ];\n for (const header of headers) {\n lines.push(` .header(\"${header.name}\", \"${header.value}\")`);\n }\n if (body === '') {\n lines.push(\n ` .method(\"${operation.httpMethod}\", HttpRequest.BodyPublishers.noBody())`,\n );\n } else {\n lines.push(' .header(\"Content-Type\", \"application/json\")');\n lines.push(\n ` .method(\"${operation.httpMethod}\", HttpRequest.BodyPublishers.ofString(\"\"\"`,\n );\n lines.push(body);\n lines.push('\"\"\"))');\n }\n lines.push(' .build();');\n lines.push(\n 'HttpResponse<String> response = client.send(request, BodyHandlers.ofString());',\n );\n return lines.join('\\n');\n }\n\n private indent(body: string, prefix: string): string {\n return body\n .split('\\n')\n .map((line: string, index: number): string => (index === 0 ? line : `${prefix}${line}`))\n .join('\\n');\n }\n}\n"]}
|
package/src/spec/ApiSpec.d.ts
CHANGED
|
@@ -90,6 +90,10 @@ export declare class OperationInfo {
|
|
|
90
90
|
* header from a security scheme is not here: the authorization card documents those.
|
|
91
91
|
*/
|
|
92
92
|
readonly requestHeaders: readonly HeaderInfo[];
|
|
93
|
+
/** Every `in: "path"` parameter, the path item's and the operation's. */
|
|
94
|
+
readonly pathParameters: readonly HeaderInfo[];
|
|
95
|
+
/** Every `in: "query"` parameter, the path item's and the operation's. */
|
|
96
|
+
readonly queryParameters: readonly HeaderInfo[];
|
|
93
97
|
readonly responses: readonly ResponseInfo[];
|
|
94
98
|
readonly isWebhook: boolean;
|
|
95
99
|
readonly securityKeys: readonly string[];
|
|
@@ -121,7 +125,11 @@ export declare class OperationInfo {
|
|
|
121
125
|
* Every `in: "header"` parameter, the path item's and the operation's (#1292). A credential
|
|
122
126
|
* header from a security scheme is not here: the authorization card documents those.
|
|
123
127
|
*/
|
|
124
|
-
requestHeaders: readonly HeaderInfo[],
|
|
128
|
+
requestHeaders: readonly HeaderInfo[],
|
|
129
|
+
/** Every `in: "path"` parameter, the path item's and the operation's. */
|
|
130
|
+
pathParameters: readonly HeaderInfo[],
|
|
131
|
+
/** Every `in: "query"` parameter, the path item's and the operation's. */
|
|
132
|
+
queryParameters: readonly HeaderInfo[], responses: readonly ResponseInfo[], isWebhook: boolean, securityKeys: readonly string[],
|
|
125
133
|
/**
|
|
126
134
|
* The event NAME a webhook is keyed by in the document's `webhooks:` block, and the empty
|
|
127
135
|
* string for an ordinary operation. It is carried separately from `name` because the two
|
package/src/spec/ApiSpec.js
CHANGED
|
@@ -96,6 +96,8 @@ class OperationInfo {
|
|
|
96
96
|
tag;
|
|
97
97
|
requestSchema;
|
|
98
98
|
requestHeaders;
|
|
99
|
+
pathParameters;
|
|
100
|
+
queryParameters;
|
|
99
101
|
responses;
|
|
100
102
|
isWebhook;
|
|
101
103
|
securityKeys;
|
|
@@ -121,7 +123,11 @@ class OperationInfo {
|
|
|
121
123
|
* Every `in: "header"` parameter, the path item's and the operation's (#1292). A credential
|
|
122
124
|
* header from a security scheme is not here: the authorization card documents those.
|
|
123
125
|
*/
|
|
124
|
-
requestHeaders,
|
|
126
|
+
requestHeaders,
|
|
127
|
+
/** Every `in: "path"` parameter, the path item's and the operation's. */
|
|
128
|
+
pathParameters,
|
|
129
|
+
/** Every `in: "query"` parameter, the path item's and the operation's. */
|
|
130
|
+
queryParameters, responses, isWebhook, securityKeys,
|
|
125
131
|
/**
|
|
126
132
|
* The event NAME a webhook is keyed by in the document's `webhooks:` block, and the empty
|
|
127
133
|
* string for an ordinary operation. It is carried separately from `name` because the two
|
|
@@ -138,6 +144,8 @@ class OperationInfo {
|
|
|
138
144
|
this.tag = tag;
|
|
139
145
|
this.requestSchema = requestSchema;
|
|
140
146
|
this.requestHeaders = requestHeaders;
|
|
147
|
+
this.pathParameters = pathParameters;
|
|
148
|
+
this.queryParameters = queryParameters;
|
|
141
149
|
this.responses = responses;
|
|
142
150
|
this.isWebhook = isWebhook;
|
|
143
151
|
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,I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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;AA3BD,0BA2BC","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 /**\n * The operation's short TITLE — its `summary`, which is the page heading and the sidebar label\n * (#1296). A document that states none falls back to the `operationId`, then the path or event.\n */\n readonly name: string,\n /**\n * The `operationId` — the CODE identifier a generated client names the method by — shown on the\n * page beside the method and path. Empty when the document states none.\n */\n readonly operationId: string,\n /**\n * The page's URL segment. Kebabed from the `operationId` when there is one, because a title\n * is prose an author rewords and a bookmarked URL should not move when they do; otherwise from\n * the title.\n */\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 /** `info.summary` (OpenAPI 3.1) — the one-line pitch shown under the title. Empty when absent. */\n readonly summary: 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"]}
|
|
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,UA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,CAAQ;QACf,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;AA3BD,0BA2BC","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 /**\n * The operation's short TITLE — its `summary`, which is the page heading and the sidebar label\n * (#1296). A document that states none falls back to the `operationId`, then the path or event.\n */\n readonly name: string,\n /**\n * The `operationId` — the CODE identifier a generated client names the method by — shown on the\n * page beside the method and path. Empty when the document states none.\n */\n readonly operationId: string,\n /**\n * The page's URL segment. Kebabed from the `operationId` when there is one, because a title\n * is prose an author rewords and a bookmarked URL should not move when they do; otherwise from\n * the title.\n */\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 /** Every `in: \"path\"` parameter, the path item's and the operation's. */\n readonly pathParameters: readonly HeaderInfo[],\n /** Every `in: \"query\"` parameter, the path item's and the operation's. */\n readonly queryParameters: 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 /** `info.summary` (OpenAPI 3.1) — the one-line pitch shown under the title. Empty when absent. */\n readonly summary: 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
|
@@ -39,10 +39,11 @@ export declare class SpecReader {
|
|
|
39
39
|
/** A response's `headers` map, each entry resolved through a `$ref` into `components.headers`. */
|
|
40
40
|
private responseHeadersOf;
|
|
41
41
|
/**
|
|
42
|
-
* Every `in
|
|
43
|
-
* parameter of the same name overrides the path item's, which is
|
|
42
|
+
* Every parameter `in` one location (`header`, `path` or `query`): the PATH ITEM's first, then the
|
|
43
|
+
* operation's — an operation parameter of the same name overrides the path item's, which is
|
|
44
|
+
* OpenAPI's own rule. A header name compares case-insensitively; a path or query name does not.
|
|
44
45
|
*/
|
|
45
|
-
private
|
|
46
|
+
private requestParametersOf;
|
|
46
47
|
/**
|
|
47
48
|
* The object a LOCAL `$ref` (`#/components/headers/x-request-id`) points at, or the node itself
|
|
48
49
|
* when it is no reference. A dangling or foreign reference also reads as the node itself, so the
|
package/src/spec/SpecReader.js
CHANGED
|
@@ -124,7 +124,7 @@ class SpecReader {
|
|
|
124
124
|
readOperation(root, node, slugs, httpMethod, pathOrEvent, isWebhook, pathItem) {
|
|
125
125
|
const operationId = node.text('operationId');
|
|
126
126
|
const name = node.text('summary') ?? operationId ?? pathOrEvent;
|
|
127
|
-
return new ApiSpec_1.OperationInfo(name, operationId ?? '', slugs.unique(operationId ?? name), httpMethod, isWebhook ? '' : pathOrEvent, node.text('description') ?? '', this.tagOf(node), this.requestSchemaOf(node), this.
|
|
127
|
+
return new ApiSpec_1.OperationInfo(name, operationId ?? '', slugs.unique(operationId ?? name), httpMethod, isWebhook ? '' : pathOrEvent, node.text('description') ?? '', this.tagOf(node), this.requestSchemaOf(node), this.requestParametersOf(root, pathItem, node, 'header'), this.requestParametersOf(root, pathItem, node, 'path'), this.requestParametersOf(root, pathItem, node, 'query'), this.responsesOf(root, node), isWebhook, isWebhook ? [] : this.operationSecurityKeys(root, node), isWebhook ? pathOrEvent : '');
|
|
128
128
|
}
|
|
129
129
|
tagOf(node) {
|
|
130
130
|
for (const tag of node.list('tags')) {
|
|
@@ -160,19 +160,20 @@ class SpecReader {
|
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
162
|
/**
|
|
163
|
-
* Every `in
|
|
164
|
-
* parameter of the same name overrides the path item's, which is
|
|
163
|
+
* Every parameter `in` one location (`header`, `path` or `query`): the PATH ITEM's first, then the
|
|
164
|
+
* operation's — an operation parameter of the same name overrides the path item's, which is
|
|
165
|
+
* OpenAPI's own rule. A header name compares case-insensitively; a path or query name does not.
|
|
165
166
|
*/
|
|
166
|
-
|
|
167
|
+
requestParametersOf(root, pathItem, node, location) {
|
|
167
168
|
const byName = new Map();
|
|
168
169
|
for (const holder of [pathItem, node]) {
|
|
169
170
|
for (const listed of holder.list('parameters')) {
|
|
170
171
|
const parameter = this.dereference(root, listed);
|
|
171
172
|
const name = parameter.text('name');
|
|
172
|
-
if (parameter.text('in') !==
|
|
173
|
+
if (parameter.text('in') !== location || name === undefined) {
|
|
173
174
|
continue;
|
|
174
175
|
}
|
|
175
|
-
byName.set(name.toLowerCase(), new ApiSpec_1.HeaderInfo(name, parameter.flag('required') === true, parameter.text('description') ?? '', parameter.at('schema')));
|
|
176
|
+
byName.set(location === 'header' ? name.toLowerCase() : name, new ApiSpec_1.HeaderInfo(name, parameter.flag('required') === true, parameter.text('description') ?? '', parameter.at('schema')));
|
|
176
177
|
}
|
|
177
178
|
}
|
|
178
179
|
return Array.from(byName.values());
|
|
@@ -1 +1 @@
|
|
|
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,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,yB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AAC,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;AA9SD,gCA8SC","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('summary') ?? '',\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 operationId = node.text('operationId');\n const name = node.text('summary') ?? operationId ?? pathOrEvent;\n return new OperationInfo(\n name,\n operationId ?? '',\n slugs.unique(operationId ?? 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"]}
|
|
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,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,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,CAAC,EAAE,CAAC;oBACtB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;gBACnB,CAAC;YACL,CAAC;QACL,CAAC;QACD,OAAO,IAAI,CAAC;IAChB,CAAC;CACJ;AAlTD,gCAkTC","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('summary') ?? '',\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 operationId = node.text('operationId');\n const name = node.text('summary') ?? operationId ?? pathOrEvent;\n return new OperationInfo(\n name,\n operationId ?? '',\n slugs.unique(operationId ?? name),\n httpMethod,\n isWebhook ? '' : pathOrEvent,\n node.text('description') ?? '',\n this.tagOf(node),\n this.requestSchemaOf(node),\n this.requestParametersOf(root, pathItem, node, 'header'),\n this.requestParametersOf(root, pathItem, node, 'path'),\n this.requestParametersOf(root, pathItem, node, 'query'),\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 parameter `in` one location (`header`, `path` or `query`): the PATH ITEM's first, then the\n * operation's — an operation parameter of the same name overrides the path item's, which is\n * OpenAPI's own rule. A header name compares case-insensitively; a path or query name does not.\n */\n private requestParametersOf(\n root: JsonNode,\n pathItem: JsonNode,\n node: JsonNode,\n location: string,\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') !== location || name === undefined) {\n continue;\n }\n byName.set(\n location === 'header' ? name.toLowerCase() : name,\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"]}
|