@stainless-api/docs-ui 0.1.0-beta.81 → 0.1.0-beta.83

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.
@@ -1,6 +1,6 @@
1
1
  import "../use-strict-context-L0c8JKg4.js";
2
2
  import { code, fence, heading, item, list, paragraph, parse, strong, text } from "./md.js";
3
- import { getDecl, getSnippet, stripMarkup } from "./utils.js";
3
+ import { getCustomSnippetTitle, getDecl, getSnippets, stripMarkup } from "./utils.js";
4
4
  import { declaration as declaration$1, methodSignature, t as printer_exports } from "./printer.js";
5
5
  import Markdoc from "@markdoc/markdoc";
6
6
 
@@ -27,7 +27,7 @@ function renderMethod(env, method) {
27
27
  const signature = methodSignature(env.language, decl);
28
28
  const [httpMethod, endpoint] = method.endpoint.split(" ");
29
29
  const output = [
30
- heading(2, method.title),
30
+ heading(2, method.summary ?? method.title),
31
31
  ...env.language === "http" ? [] : [paragraph(code(stripMarkup(signature)))],
32
32
  paragraph(strong(text(httpMethod)), text(" "), code(endpoint))
33
33
  ];
@@ -47,8 +47,14 @@ function renderMethod(env, method) {
47
47
  }
48
48
  if ("paramsChildren" in decl && Array.isArray(decl.paramsChildren) && decl.paramsChildren.length > 0) output.push(heading(3, "Parameters"), renderChildren(env, decl.paramsChildren));
49
49
  if ("responseChildren" in decl && decl.responseChildren && decl.responseChildren.length > 0) output.push(heading(3, "Returns"), renderChildren(env, decl.responseChildren));
50
- const snippet = getSnippet(env, method.stainlessPath);
51
- if (snippet) output.push(heading(3, "Example"), fence(env.language, snippet));
50
+ const snippetEntries = getSnippets(env, method.stainlessPath);
51
+ for (const [key, { snippet, response }] of Object.entries(snippetEntries)) {
52
+ if (!snippet) continue;
53
+ let title = getCustomSnippetTitle(key);
54
+ if (title.toLowerCase() === "default") title = "Example";
55
+ output.push(heading(3, title), fence(env.language, snippet));
56
+ if (response) output.push(heading(4, "Response"), fence("json", response));
57
+ }
52
58
  return output;
53
59
  }
54
60
  function renderModel(env, model) {
@@ -15,7 +15,14 @@ type EnvironmentType = {
15
15
  };
16
16
  };
17
17
  declare function getDecl(env: EnvironmentType, path: string): LanguageDeclNodes[SpecLanguage] | undefined;
18
- declare function getSnippet(env: EnvironmentType, path: string, snippetId?: 'default' | `custom:${string}`): string | undefined;
18
+ declare const customSnippetPrefix = "custom:";
19
+ declare const getCustomSnippetTitle: (snippetId: string) => string;
20
+ declare function getSnippets(env: EnvironmentType, path: string): {
21
+ [k: string]: {
22
+ snippet: string;
23
+ response: string | undefined;
24
+ };
25
+ };
19
26
  declare function stripMarkup(content: string): string;
20
27
  //#endregion
21
- export { EnvironmentType, getDecl, getSnippet, stripMarkup };
28
+ export { EnvironmentType, customSnippetPrefix, getCustomSnippetTitle, getDecl, getSnippets, stripMarkup };
@@ -10,14 +10,16 @@ function getDecl(env, path) {
10
10
  }
11
11
  return decl;
12
12
  }
13
- function getSnippet(env, path, snippetId = "default") {
13
+ const customSnippetPrefix = "custom:";
14
+ const getCustomSnippetTitle = (snippetId) => snippetId.startsWith(customSnippetPrefix) ? snippetId.slice(7) : snippetId;
15
+ function getSnippets(env, path) {
14
16
  const lang = env.language === "http" ? "http.curl" : `${env.language}.default`;
15
- let snippet = env.spec?.snippets?.[lang]?.[path]?.[snippetId]?.content;
16
- if (snippet && env.transforms?.transformRequestSnippet) snippet = env.transforms.transformRequestSnippet({
17
- snippet,
18
- language: env.language
19
- });
20
- return snippet;
17
+ const snippets = env.spec?.snippets?.[lang]?.[path];
18
+ const responses = env.spec?.snippetResponses?.http?.[path];
19
+ return Object.fromEntries(Object.entries(snippets ?? {}).map(([key, snippet]) => [key, {
20
+ snippet: snippet.content,
21
+ response: responses?.[key]?.[0]?.content
22
+ }]));
21
23
  }
22
24
  function stripMarkup(content) {
23
25
  let output = "";
@@ -28,4 +30,4 @@ function stripMarkup(content) {
28
30
  }
29
31
 
30
32
  //#endregion
31
- export { getDecl, getSnippet, stripMarkup };
33
+ export { customSnippetPrefix, getCustomSnippetTitle, getDecl, getSnippets, stripMarkup };
@@ -511,7 +511,7 @@
511
511
  }
512
512
 
513
513
  /* show link button when expander summary is hovered */
514
- & > .stldocs-expander:has(> .stldocs-expander-summary:is(:hover, :focus-within)) + .stldocs-deep-link-button,
514
+ & > .stldocs-expander:has(> .stldocs-expander-summary:hover) + .stldocs-deep-link-button,
515
515
  /* show link button when non-expander rows are hovered */
516
516
  &:not(:has(> .stldocs-expander)):hover > .stldocs-deep-link-button,
517
517
  /* keep it visible when it itself is hovered or focused */
package/dist/styles.css CHANGED
@@ -1903,7 +1903,7 @@ a.stl-ui-button {
1903
1903
  }
1904
1904
 
1905
1905
  /* show link button when expander summary is hovered */
1906
- & > .stldocs-expander:has(> .stldocs-expander-summary:is(:hover, :focus-within)) + .stldocs-deep-link-button,
1906
+ & > .stldocs-expander:has(> .stldocs-expander-summary:hover) + .stldocs-deep-link-button,
1907
1907
  /* show link button when non-expander rows are hovered */
1908
1908
  &:not(:has(> .stldocs-expander)):hover > .stldocs-deep-link-button,
1909
1909
  /* keep it visible when it itself is hovered or focused */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stainless-api/docs-ui",
3
3
  "private": false,
4
- "version": "0.1.0-beta.81",
4
+ "version": "0.1.0-beta.83",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },