doccupine 0.0.133 → 0.0.135

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.
Files changed (174) hide show
  1. package/README.md +50 -10
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +478 -45
  4. package/dist/lib/config-manager.d.ts +8 -1
  5. package/dist/lib/config-manager.js +98 -4
  6. package/dist/lib/metadata.d.ts +5 -0
  7. package/dist/lib/metadata.js +15 -4
  8. package/dist/lib/openapi-types.d.ts +120 -0
  9. package/dist/lib/openapi-types.js +14 -0
  10. package/dist/lib/openapi.d.ts +52 -0
  11. package/dist/lib/openapi.js +603 -0
  12. package/dist/lib/rss.d.ts +24 -0
  13. package/dist/lib/rss.js +137 -0
  14. package/dist/lib/structures.js +50 -4
  15. package/dist/lib/types.d.ts +22 -0
  16. package/dist/lib/utils.d.ts +8 -0
  17. package/dist/lib/utils.js +14 -0
  18. package/dist/templates/app/api/playground/route.d.ts +1 -0
  19. package/dist/templates/app/api/playground/route.js +199 -0
  20. package/dist/templates/app/rssRoute.d.ts +11 -0
  21. package/dist/templates/app/rssRoute.js +30 -0
  22. package/dist/templates/components/Docs.d.ts +1 -1
  23. package/dist/templates/components/Docs.js +15 -3
  24. package/dist/templates/components/MDXComponents.d.ts +1 -1
  25. package/dist/templates/components/MDXComponents.js +29 -0
  26. package/dist/templates/components/SideBar.d.ts +1 -1
  27. package/dist/templates/components/SideBar.js +13 -0
  28. package/dist/templates/components/layout/Accordion.d.ts +1 -1
  29. package/dist/templates/components/layout/Accordion.js +3 -2
  30. package/dist/templates/components/layout/ActionBar.d.ts +1 -1
  31. package/dist/templates/components/layout/ActionBar.js +65 -27
  32. package/dist/templates/components/layout/ApiPlayground.d.ts +1 -0
  33. package/dist/templates/components/layout/ApiPlayground.js +1075 -0
  34. package/dist/templates/components/layout/ApiPlaygroundDemo.d.ts +1 -0
  35. package/dist/templates/components/layout/ApiPlaygroundDemo.js +81 -0
  36. package/dist/templates/components/layout/Badge.d.ts +1 -0
  37. package/dist/templates/components/layout/Badge.js +455 -0
  38. package/dist/templates/components/layout/Code.d.ts +1 -1
  39. package/dist/templates/components/layout/Code.js +10 -22
  40. package/dist/templates/components/layout/CopyButton.d.ts +1 -0
  41. package/dist/templates/components/layout/CopyButton.js +68 -0
  42. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  43. package/dist/templates/components/layout/DocsComponents.js +14 -0
  44. package/dist/templates/components/layout/Mermaid.d.ts +1 -1
  45. package/dist/templates/components/layout/Mermaid.js +21 -3
  46. package/dist/templates/components/layout/Prompt.d.ts +1 -0
  47. package/dist/templates/components/layout/Prompt.js +149 -0
  48. package/dist/templates/components/layout/SharedStyles.d.ts +1 -1
  49. package/dist/templates/components/layout/SharedStyles.js +0 -4
  50. package/dist/templates/components/layout/Steps.d.ts +1 -1
  51. package/dist/templates/components/layout/Steps.js +0 -1
  52. package/dist/templates/components/layout/Tooltip.d.ts +1 -0
  53. package/dist/templates/components/layout/Tooltip.js +222 -0
  54. package/dist/templates/components/layout/Tree.d.ts +1 -0
  55. package/dist/templates/components/layout/Tree.js +322 -0
  56. package/dist/templates/components/layout/TreeData.d.ts +1 -0
  57. package/dist/templates/components/layout/TreeData.js +131 -0
  58. package/dist/templates/components/layout/Update.d.ts +1 -1
  59. package/dist/templates/components/layout/Update.js +5 -1
  60. package/dist/templates/lib/rss.d.ts +1 -0
  61. package/dist/templates/lib/rss.js +78 -0
  62. package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
  63. package/dist/templates/mdx/accordion.mdx.js +19 -1
  64. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  65. package/dist/templates/mdx/ai-assistant.mdx.js +3 -2
  66. package/dist/templates/mdx/analytics.mdx.d.ts +1 -1
  67. package/dist/templates/mdx/analytics.mdx.js +2 -2
  68. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -0
  69. package/dist/templates/mdx/api-playground.mdx.js +158 -0
  70. package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
  71. package/dist/templates/mdx/authentication.mdx.js +3 -3
  72. package/dist/templates/mdx/badges.mdx.d.ts +1 -0
  73. package/dist/templates/mdx/badges.mdx.js +237 -0
  74. package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
  75. package/dist/templates/mdx/buttons.mdx.js +1 -1
  76. package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
  77. package/dist/templates/mdx/callouts.mdx.js +1 -1
  78. package/dist/templates/mdx/cards.mdx.d.ts +1 -1
  79. package/dist/templates/mdx/cards.mdx.js +1 -1
  80. package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
  81. package/dist/templates/mdx/color-swatches.mdx.js +1 -1
  82. package/dist/templates/mdx/columns.mdx.d.ts +1 -1
  83. package/dist/templates/mdx/columns.mdx.js +1 -1
  84. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  85. package/dist/templates/mdx/commands.mdx.js +3 -2
  86. package/dist/templates/mdx/components.mdx.d.ts +1 -1
  87. package/dist/templates/mdx/components.mdx.js +25 -10
  88. package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
  89. package/dist/templates/mdx/deployment-and-hosting.mdx.js +4 -3
  90. package/dist/templates/mdx/fields.mdx.d.ts +1 -1
  91. package/dist/templates/mdx/fields.mdx.js +1 -1
  92. package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
  93. package/dist/templates/mdx/fonts.mdx.js +2 -2
  94. package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
  95. package/dist/templates/mdx/footer-links.mdx.js +1 -1
  96. package/dist/templates/mdx/frames.mdx.d.ts +1 -1
  97. package/dist/templates/mdx/frames.mdx.js +1 -1
  98. package/dist/templates/mdx/globals.mdx.d.ts +1 -1
  99. package/dist/templates/mdx/globals.mdx.js +1 -1
  100. package/dist/templates/mdx/icons.mdx.d.ts +1 -1
  101. package/dist/templates/mdx/icons.mdx.js +1 -1
  102. package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
  103. package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
  104. package/dist/templates/mdx/images-and-embeds.mdx.d.ts +1 -0
  105. package/dist/templates/mdx/images-and-embeds.mdx.js +118 -0
  106. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  107. package/dist/templates/mdx/media-and-assets.mdx.js +2 -2
  108. package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
  109. package/dist/templates/mdx/mermaid.mdx.js +1 -1
  110. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  111. package/dist/templates/mdx/model-context-protocol.mdx.js +2 -2
  112. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  113. package/dist/templates/mdx/navigation.mdx.js +27 -12
  114. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  115. package/dist/templates/mdx/platform/ai-assistant.mdx.js +4 -3
  116. package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
  117. package/dist/templates/mdx/platform/analytics.mdx.js +2 -2
  118. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -0
  119. package/dist/templates/mdx/platform/api-playground.mdx.js +62 -0
  120. package/dist/templates/mdx/platform/billing.mdx.d.ts +1 -1
  121. package/dist/templates/mdx/platform/billing.mdx.js +1 -1
  122. package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
  123. package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
  124. package/dist/templates/mdx/platform/creating-a-project.mdx.d.ts +1 -1
  125. package/dist/templates/mdx/platform/creating-a-project.mdx.js +12 -2
  126. package/dist/templates/mdx/platform/custom-domains.mdx.d.ts +1 -1
  127. package/dist/templates/mdx/platform/custom-domains.mdx.js +1 -1
  128. package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
  129. package/dist/templates/mdx/platform/fonts-settings.mdx.js +1 -1
  130. package/dist/templates/mdx/platform/footer-links.mdx.d.ts +1 -0
  131. package/dist/templates/mdx/platform/{external-links.mdx.js → footer-links.mdx.js} +5 -5
  132. package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -0
  133. package/dist/templates/mdx/platform/import-from-github.mdx.js +91 -0
  134. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  135. package/dist/templates/mdx/platform/mcp.mdx.js +3 -3
  136. package/dist/templates/mdx/platform/project-settings.mdx.d.ts +1 -1
  137. package/dist/templates/mdx/platform/project-settings.mdx.js +1 -1
  138. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -0
  139. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +113 -0
  140. package/dist/templates/mdx/platform/team-members.mdx.d.ts +1 -1
  141. package/dist/templates/mdx/platform/team-members.mdx.js +1 -1
  142. package/dist/templates/mdx/prompt.mdx.d.ts +1 -0
  143. package/dist/templates/mdx/prompt.mdx.js +69 -0
  144. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  145. package/dist/templates/mdx/sections.mdx.js +1 -1
  146. package/dist/templates/mdx/steps.mdx.d.ts +1 -1
  147. package/dist/templates/mdx/steps.mdx.js +1 -1
  148. package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
  149. package/dist/templates/mdx/tabs.mdx.js +1 -1
  150. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  151. package/dist/templates/mdx/theme.mdx.js +1 -1
  152. package/dist/templates/mdx/tooltips.mdx.d.ts +1 -0
  153. package/dist/templates/mdx/tooltips.mdx.js +57 -0
  154. package/dist/templates/mdx/tree.mdx.d.ts +1 -0
  155. package/dist/templates/mdx/tree.mdx.js +158 -0
  156. package/dist/templates/mdx/update.mdx.d.ts +1 -1
  157. package/dist/templates/mdx/update.mdx.js +42 -2
  158. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  159. package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
  160. package/dist/templates/package.js +7 -7
  161. package/dist/templates/services/openapi/playgroundAllowlistStub.d.ts +1 -0
  162. package/dist/templates/services/openapi/playgroundAllowlistStub.js +4 -0
  163. package/dist/templates/types/openapi.d.ts +1 -0
  164. package/dist/templates/types/openapi.js +93 -0
  165. package/dist/templates/utils/apiSnippets.d.ts +1 -0
  166. package/dist/templates/utils/apiSnippets.js +94 -0
  167. package/dist/templates/utils/orderNavItems.d.ts +1 -1
  168. package/dist/templates/utils/orderNavItems.js +3 -0
  169. package/dist/templates/utils/playgroundAllowlist.d.ts +1 -0
  170. package/dist/templates/utils/playgroundAllowlist.js +70 -0
  171. package/dist/templates/utils/ssrfGuard.d.ts +1 -0
  172. package/dist/templates/utils/ssrfGuard.js +217 -0
  173. package/package.json +4 -3
  174. package/dist/templates/mdx/platform/external-links.mdx.d.ts +0 -1
@@ -1,4 +1,11 @@
1
- import type { DoccupineConfig } from "./types.js";
1
+ import type { DoccupineConfig, NormalizedOpenApiSpec } from "./types.js";
2
+ /**
3
+ * Collapses every accepted `openapi` config shape (a single path, a list of
4
+ * paths, or named-spec objects) into a uniform `NormalizedOpenApiSpec[]`. Names
5
+ * default to the file basename and are de-duplicated with a numeric suffix so
6
+ * two specs never share a route namespace.
7
+ */
8
+ export declare function normalizeOpenApiConfig(openapi: DoccupineConfig["openapi"]): NormalizedOpenApiSpec[];
2
9
  /**
3
10
  * Rewrites a path as project-relative so `doccupine.json` stays portable
4
11
  * across machines, CI and containers (an absolute `/Users/you/...` breaks for
@@ -2,6 +2,70 @@ import fs from "fs-extra";
2
2
  import path from "path";
3
3
  import chalk from "chalk";
4
4
  import prompts from "prompts";
5
+ /** Strips a `.json`/`.yaml`/`.yml` extension to derive a spec's default name. */
6
+ function basenameWithoutExt(file) {
7
+ return path.basename(file).replace(/\.(json|ya?ml)$/i, "");
8
+ }
9
+ /**
10
+ * Collapses every accepted `openapi` config shape (a single path, a list of
11
+ * paths, or named-spec objects) into a uniform `NormalizedOpenApiSpec[]`. Names
12
+ * default to the file basename and are de-duplicated with a numeric suffix so
13
+ * two specs never share a route namespace.
14
+ */
15
+ export function normalizeOpenApiConfig(openapi) {
16
+ if (!openapi)
17
+ return [];
18
+ const entries = Array.isArray(openapi) ? openapi : [openapi];
19
+ const used = new Set();
20
+ const specs = [];
21
+ for (const entry of entries) {
22
+ let file;
23
+ let name;
24
+ if (typeof entry === "string") {
25
+ file = entry;
26
+ }
27
+ else if (entry &&
28
+ typeof entry === "object" &&
29
+ typeof entry.file === "string") {
30
+ file = entry.file;
31
+ name = entry.name;
32
+ }
33
+ if (!file)
34
+ continue;
35
+ const desired = name?.trim() || basenameWithoutExt(file) || "api";
36
+ let unique = desired;
37
+ let n = 2;
38
+ while (used.has(unique))
39
+ unique = `${desired}-${n++}`;
40
+ used.add(unique);
41
+ specs.push({ name: unique, file });
42
+ }
43
+ return specs;
44
+ }
45
+ /** Rewrites the spec file path(s) inside an `openapi` config to be portable. */
46
+ function rewriteOpenApiPaths(openapi, rootDir) {
47
+ if (typeof openapi === "string") {
48
+ const next = toProjectRelativePath(openapi, rootDir);
49
+ return { openapi: next, changed: next !== openapi };
50
+ }
51
+ let changed = false;
52
+ const next = openapi.map((entry) => {
53
+ if (typeof entry === "string") {
54
+ const rel = toProjectRelativePath(entry, rootDir);
55
+ if (rel !== entry)
56
+ changed = true;
57
+ return rel;
58
+ }
59
+ if (entry && typeof entry === "object" && typeof entry.file === "string") {
60
+ const rel = toProjectRelativePath(entry.file, rootDir);
61
+ if (rel !== entry.file)
62
+ changed = true;
63
+ return { ...entry, file: rel };
64
+ }
65
+ return entry;
66
+ });
67
+ return { openapi: next, changed };
68
+ }
5
69
  /**
6
70
  * Rewrites a path as project-relative so `doccupine.json` stays portable
7
71
  * across machines, CI and containers (an absolute `/Users/you/...` breaks for
@@ -39,8 +103,20 @@ export function toProjectRelativePath(targetPath, rootDir = process.cwd()) {
39
103
  export function normalizeConfigPaths(config, rootDir = process.cwd()) {
40
104
  const watchDir = toProjectRelativePath(config.watchDir, rootDir);
41
105
  const outputDir = toProjectRelativePath(config.outputDir, rootDir);
42
- const changed = watchDir !== config.watchDir || outputDir !== config.outputDir;
43
- return { config: { ...config, watchDir, outputDir }, changed };
106
+ let openapi = config.openapi;
107
+ let openapiChanged = false;
108
+ if (openapi !== undefined) {
109
+ const rewritten = rewriteOpenApiPaths(openapi, rootDir);
110
+ openapi = rewritten.openapi;
111
+ openapiChanged = rewritten.changed;
112
+ }
113
+ const changed = watchDir !== config.watchDir ||
114
+ outputDir !== config.outputDir ||
115
+ openapiChanged;
116
+ const next = { ...config, watchDir, outputDir };
117
+ if (openapi !== undefined)
118
+ next.openapi = openapi;
119
+ return { config: next, changed };
44
120
  }
45
121
  export class ConfigManager {
46
122
  configPath;
@@ -84,19 +160,37 @@ export class ConfigManager {
84
160
  message: "Enter output directory for Next.js app:",
85
161
  initial: existingConfig?.outputDir || "nextjs-app",
86
162
  },
163
+ {
164
+ type: "text",
165
+ name: "openapi",
166
+ message: "Path to an OpenAPI spec for an API reference (optional, blank to skip):",
167
+ initial: typeof existingConfig?.openapi === "string"
168
+ ? existingConfig.openapi
169
+ : "",
170
+ },
87
171
  ];
88
- const { watchDir, outputDir } = (await prompts(questions));
172
+ const { watchDir, outputDir, openapi } = (await prompts(questions));
89
173
  if (!watchDir || !outputDir) {
90
174
  console.log(chalk.yellow("\n⚠️ Setup cancelled."));
91
175
  process.exit(0);
92
176
  }
93
177
  // Resolve first so "./docs" and "docs/" collapse to the same value, then
94
178
  // store project-relative for portability.
95
- return {
179
+ const config = {
96
180
  watchDir: toProjectRelativePath(path.resolve(process.cwd(), watchDir)),
97
181
  outputDir: toProjectRelativePath(path.resolve(process.cwd(), outputDir)),
98
182
  port: existingConfig?.port || "3000",
99
183
  };
184
+ // Only attach `openapi` when a path was entered; otherwise preserve any
185
+ // existing value (including non-string, multi-spec forms) untouched.
186
+ const openapiValue = openapi?.trim();
187
+ if (openapiValue) {
188
+ config.openapi = openapiValue;
189
+ }
190
+ else if (existingConfig?.openapi !== undefined) {
191
+ config.openapi = existingConfig.openapi;
192
+ }
193
+ return config;
100
194
  }
101
195
  async getConfig(options = {}) {
102
196
  let config = null;
@@ -36,6 +36,11 @@ export interface MetadataOptions {
36
36
  * Resolves against `metadataBase` defined in the root layout.
37
37
  */
38
38
  canonicalPath?: string;
39
+ /**
40
+ * Path of this page's RSS feed, e.g. "/update/rss.xml". Emitted as an
41
+ * `alternates.types` entry so feed readers can autodiscover the feed.
42
+ */
43
+ rssPath?: string;
39
44
  }
40
45
  export declare function generateMetadataBlock(opts: MetadataOptions): string;
41
46
  export declare function generateRuntimeOnlyMetadataBlock(): string;
@@ -105,20 +105,31 @@ function buildTitleExpression(opts) {
105
105
  : `\${config.name ? config.name + " -" : "${DEFAULT_SITE_NAME} -"}`;
106
106
  return `${prefix} ${title}`;
107
107
  }
108
- function buildCanonicalLine(canonicalPath) {
108
+ function buildAlternatesBlock(canonicalPath, rssPath) {
109
109
  if (canonicalPath === undefined)
110
110
  return "";
111
111
  const safePath = canonicalPath.replace(/^\/+/, "");
112
- // Relative path resolves against `metadataBase` set in the root layout.
112
+ // Relative paths resolve against `metadataBase` set in the root layout.
113
113
  // Empty string means the homepage canonical equals the base URL itself.
114
- return `\n alternates: { canonical: ${JSON.stringify("/" + safePath)} },`;
114
+ const canonical = JSON.stringify("/" + safePath);
115
+ if (!rssPath)
116
+ return `\n alternates: { canonical: ${canonical} },`;
117
+ const rss = JSON.stringify(rssPath);
118
+ // Prettier preserves an object literal that already breaks after "{", so
119
+ // the expanded form is stable; only the inner `types` line can overflow
120
+ // the 80-col print width (long slugs) and needs the pre-wrap check.
121
+ const typesInline = ` types: { "application/rss+xml": ${rss} },`;
122
+ const typesLines = typesInline.length <= 80
123
+ ? typesInline
124
+ : ` types: {\n "application/rss+xml": ${rss},\n },`;
125
+ return `\n alternates: {\n canonical: ${canonical},\n${typesLines}\n },`;
115
126
  }
116
127
  export function generateMetadataBlock(opts) {
117
128
  const title = buildTitleExpression(opts);
118
129
  const desc = buildFieldExpression(opts.description, "description", DEFAULT_META_DESCRIPTION);
119
130
  const icon = buildFieldExpression(opts.icon, "icon", DEFAULT_FAVICON);
120
131
  const image = buildFieldExpression(opts.image, "image", DEFAULT_OG_IMAGE);
121
- const canonical = buildCanonicalLine(opts.canonicalPath);
132
+ const canonical = buildAlternatesBlock(opts.canonicalPath, opts.rssPath);
122
133
  return `export const metadata: Metadata = {
123
134
  title: \`${title}\`,
124
135
  description: \`${desc}\`,
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Canonical, JSON-serializable model for a single OpenAPI operation.
3
+ *
4
+ * This is the ONE contract shared by both halves of the API playground:
5
+ * - the build side (src/lib/openapi.ts) produces these objects from a parsed,
6
+ * dereferenced spec and embeds them into generated pages, and
7
+ * - the runtime side (the generated Next.js `<ApiPlayground>` component) is
8
+ * written strictly against this shape.
9
+ *
10
+ * Everything here must survive `JSON.stringify` (no class instances, no
11
+ * circular refs). Schemas/examples are passed through `toSerializable()` before
12
+ * they land in a descriptor, so a recursive `$ref` cannot break serialization.
13
+ */
14
+ /** A dereferenced JSON Schema fragment, already cycle-guarded and serializable. */
15
+ export type JsonSchema = unknown;
16
+ export type HttpMethod = "get" | "put" | "post" | "delete" | "options" | "head" | "patch" | "trace";
17
+ export type ParameterLocation = "query" | "header" | "path" | "cookie";
18
+ export interface ParameterDescriptor {
19
+ name: string;
20
+ in: ParameterLocation;
21
+ required: boolean;
22
+ deprecated?: boolean;
23
+ description?: string;
24
+ schema?: JsonSchema;
25
+ example?: unknown;
26
+ /** Stable anchor id for deep-linking this parameter, e.g. "param-query-page". */
27
+ anchorId: string;
28
+ }
29
+ export interface MediaTypeDescriptor {
30
+ /** e.g. "application/json". */
31
+ contentType: string;
32
+ schema?: JsonSchema;
33
+ /** `example` when present, otherwise the first value of `examples`. */
34
+ example?: unknown;
35
+ }
36
+ export interface RequestBodyDescriptor {
37
+ required: boolean;
38
+ description?: string;
39
+ content: MediaTypeDescriptor[];
40
+ }
41
+ export interface ResponseHeaderDescriptor {
42
+ name: string;
43
+ description?: string;
44
+ schema?: JsonSchema;
45
+ }
46
+ export interface ResponseDescriptor {
47
+ /** e.g. "200" | "default". */
48
+ status: string;
49
+ description?: string;
50
+ content: MediaTypeDescriptor[];
51
+ headers: ResponseHeaderDescriptor[];
52
+ }
53
+ export interface SecuritySchemeDescriptor {
54
+ type: "apiKey" | "http" | "oauth2" | "openIdConnect" | "mutualTLS";
55
+ description?: string;
56
+ /** apiKey */
57
+ name?: string;
58
+ in?: "query" | "header" | "cookie";
59
+ /** http: "bearer" | "basic" */
60
+ scheme?: string;
61
+ bearerFormat?: string;
62
+ openIdConnectUrl?: string;
63
+ /** oauth2 flows, kept as serializable JSON. */
64
+ flows?: unknown;
65
+ }
66
+ export interface SecurityRequirementDescriptor {
67
+ schemeName: string;
68
+ scopes: string[];
69
+ /** Resolved scheme from `components.securitySchemes`, when found. */
70
+ scheme?: SecuritySchemeDescriptor;
71
+ }
72
+ export interface ServerVariableDescriptor {
73
+ default: string;
74
+ enum?: string[];
75
+ description?: string;
76
+ }
77
+ export interface ServerDescriptor {
78
+ url: string;
79
+ description?: string;
80
+ variables?: Record<string, ServerVariableDescriptor>;
81
+ }
82
+ export interface OperationDescriptor {
83
+ /** Which named spec this operation came from. */
84
+ specName: string;
85
+ operationId?: string;
86
+ method: HttpMethod;
87
+ /** Templated path, e.g. "/users/{id}". */
88
+ path: string;
89
+ summary?: string;
90
+ description?: string;
91
+ deprecated?: boolean;
92
+ /** May be empty; a fallback tag is applied at routing time. */
93
+ tags: string[];
94
+ parameters: ParameterDescriptor[];
95
+ requestBody?: RequestBodyDescriptor;
96
+ responses: ResponseDescriptor[];
97
+ /** Operation -> path -> root precedence; empty if the spec has none. */
98
+ servers: ServerDescriptor[];
99
+ /** Resolved security requirements; empty means anonymous. */
100
+ security: SecurityRequirementDescriptor[];
101
+ /** Full route slug of this endpoint's generated page. */
102
+ slug: string;
103
+ /** Stable base anchor for the endpoint block on its page. */
104
+ endpointAnchor: string;
105
+ }
106
+ /**
107
+ * A single entry in the request-execution allowlist emitted at build time from
108
+ * the union of every spec's `servers[]`. The proxy route (server) and the
109
+ * playground component (client) both read this to decide whether a target URL
110
+ * may be called. `allowPrivate` is set ONLY when the spec's own declared server
111
+ * host is itself a loopback/private/metadata literal (the local-dev case).
112
+ */
113
+ export interface AllowlistEntry {
114
+ scheme: "http" | "https";
115
+ /** Lowercased hostname (never an IP unless the spec literally declared one). */
116
+ host: string;
117
+ port: number | null;
118
+ basePath?: string;
119
+ allowPrivate?: boolean;
120
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Canonical, JSON-serializable model for a single OpenAPI operation.
3
+ *
4
+ * This is the ONE contract shared by both halves of the API playground:
5
+ * - the build side (src/lib/openapi.ts) produces these objects from a parsed,
6
+ * dereferenced spec and embeds them into generated pages, and
7
+ * - the runtime side (the generated Next.js `<ApiPlayground>` component) is
8
+ * written strictly against this shape.
9
+ *
10
+ * Everything here must survive `JSON.stringify` (no class instances, no
11
+ * circular refs). Schemas/examples are passed through `toSerializable()` before
12
+ * they land in a descriptor, so a recursive `$ref` cannot break serialization.
13
+ */
14
+ export {};
@@ -0,0 +1,52 @@
1
+ import type { NormalizedOpenApiSpec, PageMeta } from "./types.js";
2
+ import type { AllowlistEntry, OperationDescriptor } from "./openapi-types.js";
3
+ /** Default base route segment for the generated API reference section. */
4
+ export declare const DEFAULT_API_BASE_SLUG = "api-reference";
5
+ /**
6
+ * Slugifies a single route/anchor segment: lowercase, collapse any run of
7
+ * non-alphanumerics to a single dash, trim edge dashes. Never returns "" and
8
+ * never contains a slash, so each segment is exactly one path/anchor part.
9
+ * (Distinct from `generateSlug`, which preserves "/" for nested MDX routes.)
10
+ */
11
+ export declare function slugifySegment(input: string): string;
12
+ /**
13
+ * Deterministic anchor id for a parameter, shared verbatim with the runtime
14
+ * component so deep links resolve. Top-level: `param-{in}-{name}`; nested schema
15
+ * properties append their parent path: `param-body-user-address-city`.
16
+ */
17
+ export declare function buildParamAnchor(name: string, location: string, parentPath?: string[]): string;
18
+ /**
19
+ * Parses one or more OpenAPI specs and exposes everything the generator needs:
20
+ * the operation descriptors, lookup indices for the MDX frontmatter path,
21
+ * synthetic sidebar/sitemap `PageMeta` objects, per-endpoint markdown bodies
22
+ * (for llms output), and the request-execution allowlist.
23
+ *
24
+ * `load()` never throws: a spec that fails to parse is logged and skipped so one
25
+ * malformed file cannot abort a build or crash a watcher.
26
+ */
27
+ export declare class OpenApiRegistry {
28
+ private operations;
29
+ private byOperationId;
30
+ private byMethodPath;
31
+ private pages;
32
+ private bodies;
33
+ private allowlistEntries;
34
+ get all(): OperationDescriptor[];
35
+ get isEmpty(): boolean;
36
+ load(specs: NormalizedOpenApiSpec[], rootDir: string, apiBaseSlug?: string): Promise<void>;
37
+ /** Fresh copies of the synthetic pages (caller may mutate/spread safely). */
38
+ syntheticPages(): PageMeta[];
39
+ bodyForSlug(slug: string): string | undefined;
40
+ allowlist(): AllowlistEntry[];
41
+ /** Looks up an operation by `operationId` or by `"METHOD /path"`. */
42
+ lookup(ref: string): OperationDescriptor | undefined;
43
+ private ingest;
44
+ private uniqueSlug;
45
+ private addAllowlist;
46
+ }
47
+ /**
48
+ * Builds the MDX body for a generated endpoint page: the operation description,
49
+ * followed by `<Field>` documentation for the parameters and request body, and
50
+ * a schema/example code block per response. Rendered above the playground.
51
+ */
52
+ export declare function buildEndpointDoc(op: OperationDescriptor): string;