doccupine 0.0.132 → 0.0.134
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +49 -10
- package/dist/index.d.ts +1 -1
- package/dist/index.js +274 -19
- package/dist/lib/config-manager.d.ts +8 -1
- package/dist/lib/config-manager.js +98 -4
- package/dist/lib/openapi-types.d.ts +120 -0
- package/dist/lib/openapi-types.js +14 -0
- package/dist/lib/openapi.d.ts +52 -0
- package/dist/lib/openapi.js +603 -0
- package/dist/lib/structures.js +28 -2
- package/dist/lib/types.d.ts +22 -0
- package/dist/lib/utils.d.ts +8 -0
- package/dist/lib/utils.js +14 -0
- package/dist/templates/app/api/playground/route.d.ts +1 -0
- package/dist/templates/app/api/playground/route.js +199 -0
- package/dist/templates/components/Chat.d.ts +1 -1
- package/dist/templates/components/Chat.js +8 -2
- package/dist/templates/components/Docs.d.ts +1 -1
- package/dist/templates/components/Docs.js +11 -2
- package/dist/templates/components/SideBar.d.ts +1 -1
- package/dist/templates/components/SideBar.js +10 -0
- package/dist/templates/components/layout/Accordion.d.ts +1 -1
- package/dist/templates/components/layout/Accordion.js +3 -2
- package/dist/templates/components/layout/ActionBar.d.ts +1 -1
- package/dist/templates/components/layout/ActionBar.js +21 -14
- package/dist/templates/components/layout/ApiPlayground.d.ts +1 -0
- package/dist/templates/components/layout/ApiPlayground.js +1083 -0
- package/dist/templates/components/layout/ApiPlaygroundDemo.d.ts +1 -0
- package/dist/templates/components/layout/ApiPlaygroundDemo.js +81 -0
- package/dist/templates/components/layout/Card.d.ts +1 -1
- package/dist/templates/components/layout/Card.js +1 -1
- package/dist/templates/components/layout/Code.d.ts +1 -1
- package/dist/templates/components/layout/Code.js +57 -47
- package/dist/templates/components/layout/CopyButton.d.ts +1 -0
- package/dist/templates/components/layout/CopyButton.js +68 -0
- package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
- package/dist/templates/components/layout/DocsComponents.js +39 -0
- package/dist/templates/components/layout/Mermaid.d.ts +1 -1
- package/dist/templates/components/layout/Mermaid.js +21 -3
- package/dist/templates/components/layout/SharedStyles.d.ts +1 -1
- package/dist/templates/components/layout/SharedStyles.js +0 -4
- package/dist/templates/components/layout/Steps.d.ts +1 -1
- package/dist/templates/components/layout/Steps.js +0 -1
- package/dist/templates/components/layout/Update.d.ts +1 -1
- package/dist/templates/components/layout/Update.js +2 -1
- package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
- package/dist/templates/mdx/accordion.mdx.js +19 -1
- package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/ai-assistant.mdx.js +3 -2
- package/dist/templates/mdx/analytics.mdx.d.ts +1 -1
- package/dist/templates/mdx/analytics.mdx.js +2 -2
- package/dist/templates/mdx/api-playground.mdx.d.ts +1 -0
- package/dist/templates/mdx/api-playground.mdx.js +158 -0
- package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
- package/dist/templates/mdx/authentication.mdx.js +3 -3
- package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
- package/dist/templates/mdx/buttons.mdx.js +1 -1
- package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
- package/dist/templates/mdx/callouts.mdx.js +1 -1
- package/dist/templates/mdx/cards.mdx.d.ts +1 -1
- package/dist/templates/mdx/cards.mdx.js +1 -1
- package/dist/templates/mdx/code.mdx.d.ts +1 -1
- package/dist/templates/mdx/code.mdx.js +1 -1
- package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
- package/dist/templates/mdx/color-swatches.mdx.js +1 -1
- package/dist/templates/mdx/commands.mdx.d.ts +1 -1
- package/dist/templates/mdx/commands.mdx.js +3 -2
- package/dist/templates/mdx/components.mdx.d.ts +1 -1
- package/dist/templates/mdx/components.mdx.js +12 -9
- package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
- package/dist/templates/mdx/deployment-and-hosting.mdx.js +4 -3
- package/dist/templates/mdx/fields.mdx.d.ts +1 -1
- package/dist/templates/mdx/fields.mdx.js +1 -1
- package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
- package/dist/templates/mdx/fonts.mdx.js +2 -2
- package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
- package/dist/templates/mdx/footer-links.mdx.js +1 -1
- package/dist/templates/mdx/frames.mdx.d.ts +1 -1
- package/dist/templates/mdx/frames.mdx.js +1 -1
- package/dist/templates/mdx/globals.mdx.d.ts +1 -1
- package/dist/templates/mdx/globals.mdx.js +1 -1
- package/dist/templates/mdx/icons.mdx.d.ts +1 -1
- package/dist/templates/mdx/icons.mdx.js +1 -1
- package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
- package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
- package/dist/templates/mdx/media-and-assets.mdx.js +2 -2
- package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
- package/dist/templates/mdx/mermaid.mdx.js +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
- package/dist/templates/mdx/model-context-protocol.mdx.js +2 -2
- package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
- package/dist/templates/mdx/navigation.mdx.js +22 -11
- package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/ai-assistant.mdx.js +4 -3
- package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/analytics.mdx.js +2 -2
- package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/api-playground.mdx.js +62 -0
- package/dist/templates/mdx/platform/billing.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/billing.mdx.js +1 -1
- package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
- package/dist/templates/mdx/platform/creating-a-project.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/creating-a-project.mdx.js +12 -2
- package/dist/templates/mdx/platform/custom-domains.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/custom-domains.mdx.js +1 -1
- package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/fonts-settings.mdx.js +1 -1
- package/dist/templates/mdx/platform/footer-links.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/footer-links.mdx.js +47 -0
- package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/import-from-github.mdx.js +91 -0
- package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/mcp.mdx.js +3 -3
- package/dist/templates/mdx/platform/project-settings.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/project-settings.mdx.js +1 -1
- package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -0
- package/dist/templates/mdx/platform/self-updating-docs.mdx.js +113 -0
- package/dist/templates/mdx/platform/team-members.mdx.d.ts +1 -1
- package/dist/templates/mdx/platform/team-members.mdx.js +1 -1
- package/dist/templates/mdx/sections.mdx.d.ts +1 -1
- package/dist/templates/mdx/sections.mdx.js +1 -1
- package/dist/templates/mdx/steps.mdx.d.ts +1 -1
- package/dist/templates/mdx/steps.mdx.js +1 -1
- package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
- package/dist/templates/mdx/tabs.mdx.js +1 -1
- package/dist/templates/mdx/theme.mdx.d.ts +1 -1
- package/dist/templates/mdx/theme.mdx.js +1 -1
- package/dist/templates/mdx/update.mdx.d.ts +1 -1
- package/dist/templates/mdx/update.mdx.js +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
- package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
- package/dist/templates/package.js +8 -8
- package/dist/templates/services/openapi/playgroundAllowlistStub.d.ts +1 -0
- package/dist/templates/services/openapi/playgroundAllowlistStub.js +4 -0
- package/dist/templates/types/openapi.d.ts +1 -0
- package/dist/templates/types/openapi.js +93 -0
- package/dist/templates/utils/apiAnchors.d.ts +1 -0
- package/dist/templates/utils/apiAnchors.js +39 -0
- package/dist/templates/utils/apiSnippets.d.ts +1 -0
- package/dist/templates/utils/apiSnippets.js +94 -0
- package/dist/templates/utils/orderNavItems.d.ts +1 -1
- package/dist/templates/utils/orderNavItems.js +3 -0
- package/dist/templates/utils/playgroundAllowlist.d.ts +1 -0
- package/dist/templates/utils/playgroundAllowlist.js +70 -0
- package/dist/templates/utils/ssrfGuard.d.ts +1 -0
- package/dist/templates/utils/ssrfGuard.js +217 -0
- package/package.json +4 -3
|
@@ -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
|
-
|
|
43
|
-
|
|
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
|
-
|
|
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;
|
|
@@ -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;
|