@raystack/chronicle 0.1.2
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/bin/chronicle.js +2 -0
- package/dist/cli/index.js +9763 -0
- package/next.config.mjs +10 -0
- package/package.json +60 -0
- package/source.config.ts +43 -0
- package/src/app/[[...slug]]/layout.tsx +15 -0
- package/src/app/[[...slug]]/page.tsx +57 -0
- package/src/app/api/apis-proxy/route.ts +59 -0
- package/src/app/api/health/route.ts +3 -0
- package/src/app/api/search/route.ts +90 -0
- package/src/app/apis/[[...slug]]/layout.module.css +22 -0
- package/src/app/apis/[[...slug]]/layout.tsx +26 -0
- package/src/app/apis/[[...slug]]/page.tsx +57 -0
- package/src/app/layout.tsx +26 -0
- package/src/app/providers.tsx +8 -0
- package/src/cli/commands/build.ts +31 -0
- package/src/cli/commands/dev.ts +32 -0
- package/src/cli/commands/init.ts +58 -0
- package/src/cli/commands/serve.ts +52 -0
- package/src/cli/commands/start.ts +32 -0
- package/src/cli/index.ts +21 -0
- package/src/cli/utils/config.ts +35 -0
- package/src/cli/utils/index.ts +2 -0
- package/src/cli/utils/process.ts +7 -0
- package/src/components/api/code-snippets.module.css +7 -0
- package/src/components/api/code-snippets.tsx +76 -0
- package/src/components/api/endpoint-page.module.css +58 -0
- package/src/components/api/endpoint-page.tsx +283 -0
- package/src/components/api/field-row.module.css +126 -0
- package/src/components/api/field-row.tsx +204 -0
- package/src/components/api/field-section.module.css +24 -0
- package/src/components/api/field-section.tsx +100 -0
- package/src/components/api/index.ts +8 -0
- package/src/components/api/json-editor.module.css +9 -0
- package/src/components/api/json-editor.tsx +61 -0
- package/src/components/api/key-value-editor.module.css +13 -0
- package/src/components/api/key-value-editor.tsx +62 -0
- package/src/components/api/method-badge.module.css +4 -0
- package/src/components/api/method-badge.tsx +29 -0
- package/src/components/api/response-panel.module.css +8 -0
- package/src/components/api/response-panel.tsx +44 -0
- package/src/components/common/breadcrumb.tsx +3 -0
- package/src/components/common/button.tsx +3 -0
- package/src/components/common/callout.module.css +7 -0
- package/src/components/common/callout.tsx +27 -0
- package/src/components/common/code-block.tsx +3 -0
- package/src/components/common/dialog.tsx +3 -0
- package/src/components/common/index.ts +10 -0
- package/src/components/common/input-field.tsx +3 -0
- package/src/components/common/sidebar.tsx +3 -0
- package/src/components/common/switch.tsx +3 -0
- package/src/components/common/table.tsx +3 -0
- package/src/components/common/tabs.tsx +3 -0
- package/src/components/mdx/code.module.css +42 -0
- package/src/components/mdx/code.tsx +27 -0
- package/src/components/mdx/details.module.css +37 -0
- package/src/components/mdx/details.tsx +18 -0
- package/src/components/mdx/image.tsx +38 -0
- package/src/components/mdx/index.tsx +35 -0
- package/src/components/mdx/link.tsx +38 -0
- package/src/components/mdx/mermaid.module.css +9 -0
- package/src/components/mdx/mermaid.tsx +37 -0
- package/src/components/mdx/paragraph.module.css +8 -0
- package/src/components/mdx/paragraph.tsx +19 -0
- package/src/components/mdx/table.tsx +40 -0
- package/src/components/ui/breadcrumbs.tsx +72 -0
- package/src/components/ui/client-theme-switcher.tsx +18 -0
- package/src/components/ui/footer.module.css +27 -0
- package/src/components/ui/footer.tsx +30 -0
- package/src/components/ui/search.module.css +104 -0
- package/src/components/ui/search.tsx +202 -0
- package/src/lib/api-routes.ts +120 -0
- package/src/lib/config.ts +36 -0
- package/src/lib/index.ts +2 -0
- package/src/lib/openapi.ts +188 -0
- package/src/lib/remark-unused-directives.ts +31 -0
- package/src/lib/schema.ts +99 -0
- package/src/lib/snippet-generators.ts +87 -0
- package/src/lib/source.ts +66 -0
- package/src/themes/default/Layout.module.css +81 -0
- package/src/themes/default/Layout.tsx +133 -0
- package/src/themes/default/Page.module.css +46 -0
- package/src/themes/default/Page.tsx +21 -0
- package/src/themes/default/Toc.module.css +48 -0
- package/src/themes/default/Toc.tsx +66 -0
- package/src/themes/default/font.ts +6 -0
- package/src/themes/default/index.ts +13 -0
- package/src/themes/paper/ChapterNav.module.css +71 -0
- package/src/themes/paper/ChapterNav.tsx +96 -0
- package/src/themes/paper/Layout.module.css +33 -0
- package/src/themes/paper/Layout.tsx +25 -0
- package/src/themes/paper/Page.module.css +174 -0
- package/src/themes/paper/Page.tsx +107 -0
- package/src/themes/paper/ReadingProgress.module.css +132 -0
- package/src/themes/paper/ReadingProgress.tsx +294 -0
- package/src/themes/paper/index.ts +8 -0
- package/src/themes/registry.ts +14 -0
- package/src/types/config.ts +64 -0
- package/src/types/content.ts +35 -0
- package/src/types/index.ts +3 -0
- package/src/types/theme.ts +22 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { spawn } from 'child_process'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import { resolveContentDir, loadCLIConfig, attachLifecycleHandlers } from '@/cli/utils'
|
|
6
|
+
|
|
7
|
+
declare const PACKAGE_ROOT: string
|
|
8
|
+
|
|
9
|
+
const nextBin = path.join(PACKAGE_ROOT, 'node_modules', '.bin', process.platform === 'win32' ? 'next.cmd' : 'next')
|
|
10
|
+
|
|
11
|
+
export const startCommand = new Command('start')
|
|
12
|
+
.description('Start production server')
|
|
13
|
+
.option('-p, --port <port>', 'Port number', '3000')
|
|
14
|
+
.option('-c, --content <path>', 'Content directory')
|
|
15
|
+
.action((options) => {
|
|
16
|
+
const contentDir = resolveContentDir(options.content)
|
|
17
|
+
loadCLIConfig(contentDir)
|
|
18
|
+
|
|
19
|
+
console.log(chalk.cyan('Starting production server...'))
|
|
20
|
+
console.log(chalk.gray(`Content: ${contentDir}`))
|
|
21
|
+
|
|
22
|
+
const child = spawn(nextBin, ['start', '-p', options.port], {
|
|
23
|
+
stdio: 'inherit',
|
|
24
|
+
cwd: PACKAGE_ROOT,
|
|
25
|
+
env: {
|
|
26
|
+
...process.env,
|
|
27
|
+
CHRONICLE_CONTENT_DIR: contentDir,
|
|
28
|
+
},
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
attachLifecycleHandlers(child)
|
|
32
|
+
})
|
package/src/cli/index.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Command } from 'commander'
|
|
2
|
+
import { initCommand } from './commands/init'
|
|
3
|
+
import { devCommand } from './commands/dev'
|
|
4
|
+
import { buildCommand } from './commands/build'
|
|
5
|
+
import { startCommand } from './commands/start'
|
|
6
|
+
import { serveCommand } from './commands/serve'
|
|
7
|
+
|
|
8
|
+
const program = new Command()
|
|
9
|
+
|
|
10
|
+
program
|
|
11
|
+
.name('chronicle')
|
|
12
|
+
.description('Config-driven documentation framework')
|
|
13
|
+
.version('0.1.0')
|
|
14
|
+
|
|
15
|
+
program.addCommand(initCommand)
|
|
16
|
+
program.addCommand(devCommand)
|
|
17
|
+
program.addCommand(buildCommand)
|
|
18
|
+
program.addCommand(startCommand)
|
|
19
|
+
program.addCommand(serveCommand)
|
|
20
|
+
|
|
21
|
+
program.parse()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import path from 'path'
|
|
3
|
+
import { parse } from 'yaml'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
import type { ChronicleConfig } from '@/types'
|
|
6
|
+
|
|
7
|
+
export interface CLIConfig {
|
|
8
|
+
config: ChronicleConfig
|
|
9
|
+
configPath: string
|
|
10
|
+
contentDir: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function resolveContentDir(contentFlag?: string): string {
|
|
14
|
+
if (contentFlag) return path.resolve(contentFlag)
|
|
15
|
+
if (process.env.CHRONICLE_CONTENT_DIR) return path.resolve(process.env.CHRONICLE_CONTENT_DIR)
|
|
16
|
+
return process.cwd()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function loadCLIConfig(contentDir: string): CLIConfig {
|
|
20
|
+
const configPath = path.join(contentDir, 'chronicle.yaml')
|
|
21
|
+
|
|
22
|
+
if (!fs.existsSync(configPath)) {
|
|
23
|
+
console.log(chalk.red('Error: chronicle.yaml not found in'), contentDir)
|
|
24
|
+
console.log(chalk.gray(`Run 'chronicle init' to create one`))
|
|
25
|
+
process.exit(1)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const config = parse(fs.readFileSync(configPath, 'utf-8')) as ChronicleConfig
|
|
29
|
+
|
|
30
|
+
return {
|
|
31
|
+
config,
|
|
32
|
+
configPath,
|
|
33
|
+
contentDir,
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ChildProcess } from 'child_process'
|
|
2
|
+
|
|
3
|
+
export function attachLifecycleHandlers(child: ChildProcess) {
|
|
4
|
+
child.on('close', (code) => process.exit(code ?? 0))
|
|
5
|
+
process.on('SIGINT', () => child.kill('SIGINT'))
|
|
6
|
+
process.on('SIGTERM', () => child.kill('SIGTERM'))
|
|
7
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { CodeBlock } from "@raystack/apsara";
|
|
5
|
+
import {
|
|
6
|
+
generateCurl,
|
|
7
|
+
generatePython,
|
|
8
|
+
generateGo,
|
|
9
|
+
generateTypeScript,
|
|
10
|
+
} from "@/lib/snippet-generators";
|
|
11
|
+
import styles from "./code-snippets.module.css";
|
|
12
|
+
|
|
13
|
+
interface CodeSnippetsProps {
|
|
14
|
+
method: string;
|
|
15
|
+
url: string;
|
|
16
|
+
headers: Record<string, string>;
|
|
17
|
+
body?: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const languages = [
|
|
21
|
+
{ value: "curl", label: "cURL", lang: "curl", generate: generateCurl },
|
|
22
|
+
{
|
|
23
|
+
value: "python",
|
|
24
|
+
label: "Python",
|
|
25
|
+
lang: "python",
|
|
26
|
+
generate: generatePython,
|
|
27
|
+
},
|
|
28
|
+
{ value: "go", label: "Go", lang: "go", generate: generateGo },
|
|
29
|
+
{
|
|
30
|
+
value: "typescript",
|
|
31
|
+
label: "TypeScript",
|
|
32
|
+
lang: "typescript",
|
|
33
|
+
generate: generateTypeScript,
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
export function CodeSnippets({
|
|
38
|
+
method,
|
|
39
|
+
url,
|
|
40
|
+
headers,
|
|
41
|
+
body,
|
|
42
|
+
}: CodeSnippetsProps) {
|
|
43
|
+
const opts = { method, url, headers, body };
|
|
44
|
+
const [selected, setSelected] = useState("curl");
|
|
45
|
+
const current = languages.find((l) => l.value === selected) ?? languages[0];
|
|
46
|
+
|
|
47
|
+
const code = useMemo(
|
|
48
|
+
() => current.generate(opts),
|
|
49
|
+
[selected, method, url, headers, body],
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<CodeBlock
|
|
54
|
+
value={selected}
|
|
55
|
+
onValueChange={setSelected}
|
|
56
|
+
className={styles.snippets}
|
|
57
|
+
>
|
|
58
|
+
<CodeBlock.Header>
|
|
59
|
+
<CodeBlock.LanguageSelect>
|
|
60
|
+
<CodeBlock.LanguageSelectTrigger />
|
|
61
|
+
<CodeBlock.LanguageSelectContent>
|
|
62
|
+
{languages.map((l) => (
|
|
63
|
+
<CodeBlock.LanguageSelectItem key={l.value} value={l.value}>
|
|
64
|
+
{l.label}
|
|
65
|
+
</CodeBlock.LanguageSelectItem>
|
|
66
|
+
))}
|
|
67
|
+
</CodeBlock.LanguageSelectContent>
|
|
68
|
+
</CodeBlock.LanguageSelect>
|
|
69
|
+
<CodeBlock.CopyButton />
|
|
70
|
+
</CodeBlock.Header>
|
|
71
|
+
<CodeBlock.Content>
|
|
72
|
+
<CodeBlock.Code language={current.lang}>{code}</CodeBlock.Code>
|
|
73
|
+
</CodeBlock.Content>
|
|
74
|
+
</CodeBlock>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
.layout {
|
|
2
|
+
display: grid;
|
|
3
|
+
grid-template-columns: 1fr 1fr;
|
|
4
|
+
gap: var(--rs-space-9);
|
|
5
|
+
padding: var(--rs-space-7);
|
|
6
|
+
max-width: 1400px;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.left {
|
|
10
|
+
gap: var(--rs-space-7);
|
|
11
|
+
min-width: 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.right {
|
|
15
|
+
gap: var(--rs-space-5);
|
|
16
|
+
min-width: 0;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.title {
|
|
20
|
+
margin: 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.description {
|
|
24
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.methodPath {
|
|
28
|
+
gap: var(--rs-space-3);
|
|
29
|
+
padding: var(--rs-space-4) var(--rs-space-5);
|
|
30
|
+
border: 1px solid var(--rs-color-border-base-primary);
|
|
31
|
+
border-radius: 8px;
|
|
32
|
+
background: var(--rs-color-background-base-secondary);
|
|
33
|
+
overflow: hidden;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.path {
|
|
37
|
+
font-family: monospace;
|
|
38
|
+
flex: 1;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
overflow: hidden;
|
|
41
|
+
text-overflow: ellipsis;
|
|
42
|
+
white-space: nowrap;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.tryButton {
|
|
46
|
+
margin-left: auto;
|
|
47
|
+
flex-shrink: 0;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@media (max-width: 900px) {
|
|
51
|
+
.layout {
|
|
52
|
+
grid-template-columns: 1fr;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.right {
|
|
56
|
+
position: static;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
import { useState, useCallback } from 'react'
|
|
4
|
+
import type { OpenAPIV3 } from 'openapi-types'
|
|
5
|
+
import { Flex, Text, Headline, Button, CodeBlock } from '@raystack/apsara'
|
|
6
|
+
import { MethodBadge } from './method-badge'
|
|
7
|
+
import { FieldSection } from './field-section'
|
|
8
|
+
import { KeyValueEditor, type KeyValueEntry } from './key-value-editor'
|
|
9
|
+
import { CodeSnippets } from './code-snippets'
|
|
10
|
+
import { ResponsePanel } from './response-panel'
|
|
11
|
+
import { flattenSchema, generateExampleJson, type SchemaField } from '@/lib/schema'
|
|
12
|
+
import styles from './endpoint-page.module.css'
|
|
13
|
+
|
|
14
|
+
interface EndpointPageProps {
|
|
15
|
+
method: string
|
|
16
|
+
path: string
|
|
17
|
+
operation: OpenAPIV3.OperationObject
|
|
18
|
+
serverUrl: string
|
|
19
|
+
specName: string
|
|
20
|
+
auth?: { type: string; header: string; placeholder?: string }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function EndpointPage({ method, path, operation, serverUrl, specName, auth }: EndpointPageProps) {
|
|
24
|
+
const params = (operation.parameters ?? []) as OpenAPIV3.ParameterObject[]
|
|
25
|
+
const body = getRequestBody(operation.requestBody as OpenAPIV3.RequestBodyObject | undefined)
|
|
26
|
+
|
|
27
|
+
const headerFields = paramsToFields(params.filter((p) => p.in === 'header'))
|
|
28
|
+
const headerLocations = Object.fromEntries(headerFields.map((f) => [f.name, 'header']))
|
|
29
|
+
const pathFields = paramsToFields(params.filter((p) => p.in === 'path'))
|
|
30
|
+
const pathLocations = Object.fromEntries(pathFields.map((f) => [f.name, 'path']))
|
|
31
|
+
const queryFields = paramsToFields(params.filter((p) => p.in === 'query'))
|
|
32
|
+
const queryLocations = Object.fromEntries(queryFields.map((f) => [f.name, 'query']))
|
|
33
|
+
const responses = getResponseSections(operation.responses as Record<string, OpenAPIV3.ResponseObject>)
|
|
34
|
+
|
|
35
|
+
// State for editable fields
|
|
36
|
+
const [customHeaders, setCustomHeaders] = useState<KeyValueEntry[]>(() => {
|
|
37
|
+
const initial: KeyValueEntry[] = []
|
|
38
|
+
if (auth) initial.push({ key: auth.header, value: '' })
|
|
39
|
+
return initial
|
|
40
|
+
})
|
|
41
|
+
const [headerValues, setHeaderValues] = useState<Record<string, unknown>>({})
|
|
42
|
+
const [pathValues, setPathValues] = useState<Record<string, unknown>>({})
|
|
43
|
+
const [queryValues, setQueryValues] = useState<Record<string, unknown>>({})
|
|
44
|
+
const [bodyValues, setBodyValues] = useState<Record<string, unknown>>(() => {
|
|
45
|
+
try { return body?.jsonExample ? JSON.parse(body.jsonExample) : {} }
|
|
46
|
+
catch { return {} }
|
|
47
|
+
})
|
|
48
|
+
const [bodyJsonStr, setBodyJsonStr] = useState(body?.jsonExample ?? '{}')
|
|
49
|
+
const [responseBody, setResponseBody] = useState<{ status: number; statusText: string; body: unknown } | null>(null)
|
|
50
|
+
const [loading, setLoading] = useState(false)
|
|
51
|
+
|
|
52
|
+
// Two-way sync: fields → JSON
|
|
53
|
+
const handleBodyValuesChange = useCallback((values: Record<string, unknown>) => {
|
|
54
|
+
setBodyValues(values)
|
|
55
|
+
setBodyJsonStr(JSON.stringify(values, null, 2))
|
|
56
|
+
}, [])
|
|
57
|
+
|
|
58
|
+
// Two-way sync: JSON → fields
|
|
59
|
+
const handleBodyJsonChange = useCallback((jsonStr: string) => {
|
|
60
|
+
setBodyJsonStr(jsonStr)
|
|
61
|
+
try {
|
|
62
|
+
setBodyValues(JSON.parse(jsonStr))
|
|
63
|
+
} catch { /* ignore invalid JSON while typing */ }
|
|
64
|
+
}, [])
|
|
65
|
+
|
|
66
|
+
// Try it handler
|
|
67
|
+
const handleTryIt = useCallback(async () => {
|
|
68
|
+
setLoading(true)
|
|
69
|
+
setResponseBody(null)
|
|
70
|
+
|
|
71
|
+
let resolvedPath = path
|
|
72
|
+
for (const [key, value] of Object.entries(pathValues)) {
|
|
73
|
+
resolvedPath = resolvedPath.replace(`{${key}}`, encodeURIComponent(String(value)))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const queryEntries = Object.entries(queryValues).filter(([, v]) => v !== undefined && v !== '')
|
|
77
|
+
const queryString = queryEntries
|
|
78
|
+
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`)
|
|
79
|
+
.join('&')
|
|
80
|
+
const fullPath = queryString ? `${resolvedPath}?${queryString}` : resolvedPath
|
|
81
|
+
|
|
82
|
+
const reqHeaders: Record<string, string> = {}
|
|
83
|
+
for (const [key, value] of Object.entries(headerValues)) {
|
|
84
|
+
if (value !== undefined && value !== null && value !== '') reqHeaders[key] = String(value)
|
|
85
|
+
}
|
|
86
|
+
for (const entry of customHeaders) {
|
|
87
|
+
if (entry.key && entry.value) reqHeaders[entry.key] = entry.value
|
|
88
|
+
}
|
|
89
|
+
if (body && bodyJsonStr) {
|
|
90
|
+
reqHeaders['Content-Type'] = body.contentType ?? 'application/json'
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try {
|
|
94
|
+
const res = await fetch('/api/apis-proxy', {
|
|
95
|
+
method: 'POST',
|
|
96
|
+
headers: { 'Content-Type': 'application/json' },
|
|
97
|
+
body: JSON.stringify({
|
|
98
|
+
specName,
|
|
99
|
+
method,
|
|
100
|
+
path: fullPath,
|
|
101
|
+
headers: reqHeaders,
|
|
102
|
+
body: body ? bodyValues : undefined,
|
|
103
|
+
}),
|
|
104
|
+
})
|
|
105
|
+
const data = await res.json()
|
|
106
|
+
if (data.status !== undefined) {
|
|
107
|
+
setResponseBody(data)
|
|
108
|
+
} else {
|
|
109
|
+
setResponseBody({ status: res.status, statusText: res.statusText, body: data.error ?? data })
|
|
110
|
+
}
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.error('API request failed:', err)
|
|
113
|
+
setResponseBody({ status: 0, statusText: 'Error', body: 'Failed to send request' })
|
|
114
|
+
} finally {
|
|
115
|
+
setLoading(false)
|
|
116
|
+
}
|
|
117
|
+
}, [specName, method, path, pathValues, queryValues, headerValues, customHeaders, bodyValues, bodyJsonStr, body])
|
|
118
|
+
|
|
119
|
+
// Snippet display values
|
|
120
|
+
const fullUrl = '{domain}' + path
|
|
121
|
+
const snippetHeaders: Record<string, string> = {}
|
|
122
|
+
if (auth) {
|
|
123
|
+
snippetHeaders[auth.header] = auth.placeholder ?? 'YOUR_API_KEY'
|
|
124
|
+
}
|
|
125
|
+
if (body) {
|
|
126
|
+
snippetHeaders['Content-Type'] = body.contentType ?? 'application/json'
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return (
|
|
130
|
+
<div className={styles.layout}>
|
|
131
|
+
<Flex direction="column" className={styles.left}>
|
|
132
|
+
{operation.summary && (
|
|
133
|
+
<Headline size="small" as="h1" className={styles.title}>{operation.summary}</Headline>
|
|
134
|
+
)}
|
|
135
|
+
{operation.description && (
|
|
136
|
+
<Text size={3} className={styles.description}>{operation.description}</Text>
|
|
137
|
+
)}
|
|
138
|
+
|
|
139
|
+
<Flex align="center" className={styles.methodPath}>
|
|
140
|
+
<MethodBadge method={method} />
|
|
141
|
+
<Text size={3} className={styles.path}>{path}</Text>
|
|
142
|
+
<Button variant="solid" size="small" className={styles.tryButton} onClick={handleTryIt} disabled={loading}>
|
|
143
|
+
{loading ? 'Sending...' : 'Send'}
|
|
144
|
+
</Button>
|
|
145
|
+
</Flex>
|
|
146
|
+
|
|
147
|
+
<FieldSection
|
|
148
|
+
title="Headers"
|
|
149
|
+
fields={headerFields}
|
|
150
|
+
locations={headerLocations}
|
|
151
|
+
editable
|
|
152
|
+
values={headerValues}
|
|
153
|
+
onValuesChange={setHeaderValues}
|
|
154
|
+
>
|
|
155
|
+
<KeyValueEditor entries={customHeaders} onChange={setCustomHeaders} />
|
|
156
|
+
</FieldSection>
|
|
157
|
+
<FieldSection
|
|
158
|
+
title="Path"
|
|
159
|
+
fields={pathFields}
|
|
160
|
+
locations={pathLocations}
|
|
161
|
+
editable
|
|
162
|
+
values={pathValues}
|
|
163
|
+
onValuesChange={setPathValues}
|
|
164
|
+
/>
|
|
165
|
+
<FieldSection
|
|
166
|
+
title="Query Parameters"
|
|
167
|
+
fields={queryFields}
|
|
168
|
+
locations={queryLocations}
|
|
169
|
+
editable
|
|
170
|
+
values={queryValues}
|
|
171
|
+
onValuesChange={setQueryValues}
|
|
172
|
+
/>
|
|
173
|
+
{body && (
|
|
174
|
+
<FieldSection
|
|
175
|
+
title="Body"
|
|
176
|
+
label={body?.contentType}
|
|
177
|
+
fields={body?.fields ?? []}
|
|
178
|
+
jsonExample={bodyJsonStr}
|
|
179
|
+
editableJson
|
|
180
|
+
onJsonChange={handleBodyJsonChange}
|
|
181
|
+
alwaysShow
|
|
182
|
+
editable
|
|
183
|
+
values={bodyValues}
|
|
184
|
+
onValuesChange={handleBodyValuesChange}
|
|
185
|
+
/>
|
|
186
|
+
)}
|
|
187
|
+
|
|
188
|
+
{responses.map((resp) => (
|
|
189
|
+
<FieldSection
|
|
190
|
+
key={resp.status}
|
|
191
|
+
title={`${resp.status}${resp.description ? ` — ${resp.description}` : ''}`}
|
|
192
|
+
fields={resp.fields}
|
|
193
|
+
jsonExample={resp.jsonExample}
|
|
194
|
+
/>
|
|
195
|
+
))}
|
|
196
|
+
</Flex>
|
|
197
|
+
<Flex direction="column" className={styles.right}>
|
|
198
|
+
<CodeSnippets
|
|
199
|
+
method={method}
|
|
200
|
+
url={fullUrl}
|
|
201
|
+
headers={snippetHeaders}
|
|
202
|
+
body={body ? bodyJsonStr : undefined}
|
|
203
|
+
/>
|
|
204
|
+
<ResponsePanel responses={responses} />
|
|
205
|
+
{responseBody && (
|
|
206
|
+
<Flex direction="column" gap="small">
|
|
207
|
+
<Text size={3} weight="medium">
|
|
208
|
+
Response — {responseBody.status} {responseBody.statusText}
|
|
209
|
+
</Text>
|
|
210
|
+
<CodeBlock>
|
|
211
|
+
<CodeBlock.Header>
|
|
212
|
+
<CodeBlock.CopyButton />
|
|
213
|
+
</CodeBlock.Header>
|
|
214
|
+
<CodeBlock.Content>
|
|
215
|
+
<CodeBlock.Code language="json">
|
|
216
|
+
{typeof responseBody.body === 'string'
|
|
217
|
+
? (responseBody.body || 'No response body')
|
|
218
|
+
: (JSON.stringify(responseBody.body, null, 2) ?? 'No response body')}
|
|
219
|
+
</CodeBlock.Code>
|
|
220
|
+
</CodeBlock.Content>
|
|
221
|
+
</CodeBlock>
|
|
222
|
+
</Flex>
|
|
223
|
+
)}
|
|
224
|
+
</Flex>
|
|
225
|
+
</div>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function paramsToFields(params: OpenAPIV3.ParameterObject[]): SchemaField[] {
|
|
230
|
+
return params.map((p) => {
|
|
231
|
+
const schema = (p.schema ?? {}) as OpenAPIV3.SchemaObject
|
|
232
|
+
return {
|
|
233
|
+
name: p.name,
|
|
234
|
+
type: schema.type ? String(schema.type) : 'string',
|
|
235
|
+
required: p.required ?? false,
|
|
236
|
+
description: p.description,
|
|
237
|
+
default: schema.default,
|
|
238
|
+
}
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
interface RequestBody {
|
|
243
|
+
contentType: string
|
|
244
|
+
fields: SchemaField[]
|
|
245
|
+
jsonExample: string
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function getRequestBody(body: OpenAPIV3.RequestBodyObject | undefined): RequestBody | null {
|
|
249
|
+
if (!body?.content) return null
|
|
250
|
+
const contentType = Object.keys(body.content)[0]
|
|
251
|
+
if (!contentType) return null
|
|
252
|
+
const schema = body.content[contentType]?.schema as OpenAPIV3.SchemaObject | undefined
|
|
253
|
+
if (!schema) return null
|
|
254
|
+
return {
|
|
255
|
+
contentType,
|
|
256
|
+
fields: flattenSchema(schema),
|
|
257
|
+
jsonExample: JSON.stringify(generateExampleJson(schema), null, 2),
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
interface ResponseSection {
|
|
262
|
+
status: string
|
|
263
|
+
description?: string
|
|
264
|
+
fields: SchemaField[]
|
|
265
|
+
jsonExample?: string
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
function getResponseSections(responses: Record<string, OpenAPIV3.ResponseObject>): ResponseSection[] {
|
|
269
|
+
return Object.entries(responses).map(([status, resp]) => {
|
|
270
|
+
const content = resp.content ?? {}
|
|
271
|
+
const contentType = Object.keys(content)[0]
|
|
272
|
+
const schema = contentType
|
|
273
|
+
? (content[contentType]?.schema as OpenAPIV3.SchemaObject | undefined)
|
|
274
|
+
: undefined
|
|
275
|
+
|
|
276
|
+
return {
|
|
277
|
+
status,
|
|
278
|
+
description: resp.description,
|
|
279
|
+
fields: schema ? flattenSchema(schema) : [],
|
|
280
|
+
jsonExample: schema ? JSON.stringify(generateExampleJson(schema), null, 2) : undefined,
|
|
281
|
+
}
|
|
282
|
+
})
|
|
283
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
.row {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: var(--rs-space-2);
|
|
5
|
+
padding: var(--rs-space-4) 0;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
.row + .row {
|
|
9
|
+
border-top: 1px solid var(--rs-color-border-base-primary);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.main {
|
|
13
|
+
gap: var(--rs-space-2);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.badges {
|
|
17
|
+
gap: var(--rs-space-3);
|
|
18
|
+
flex-wrap: wrap;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.name {
|
|
22
|
+
font-family: monospace;
|
|
23
|
+
font-size: 13px;
|
|
24
|
+
color: var(--rs-color-foreground-base-primary);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.type {
|
|
28
|
+
font-family: monospace;
|
|
29
|
+
font-size: 12px;
|
|
30
|
+
padding: 1px var(--rs-space-2);
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
background: var(--rs-color-background-neutral-secondary);
|
|
33
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.location {
|
|
37
|
+
font-size: 12px;
|
|
38
|
+
padding: 1px var(--rs-space-2);
|
|
39
|
+
border-radius: 4px;
|
|
40
|
+
background: var(--rs-color-background-neutral-secondary);
|
|
41
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.required {
|
|
45
|
+
font-size: 11px;
|
|
46
|
+
padding: 1px var(--rs-space-2);
|
|
47
|
+
border-radius: 4px;
|
|
48
|
+
background: var(--rs-color-background-danger-primary);
|
|
49
|
+
color: var(--rs-color-foreground-danger-primary);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.description {
|
|
53
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
54
|
+
font-size: 13px;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.example {
|
|
58
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
59
|
+
font-size: 12px;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.example code {
|
|
63
|
+
font-family: monospace;
|
|
64
|
+
background: var(--rs-color-background-neutral-secondary);
|
|
65
|
+
padding: 1px var(--rs-space-2);
|
|
66
|
+
border-radius: 3px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.accordion {
|
|
70
|
+
border: none;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.accordion :global([class*="accordion-header"]) {
|
|
74
|
+
margin: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.accordion button {
|
|
78
|
+
min-height: unset;
|
|
79
|
+
padding: 0;
|
|
80
|
+
border: none;
|
|
81
|
+
background: transparent;
|
|
82
|
+
box-shadow: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.accordion button:hover,
|
|
86
|
+
.accordion button:focus-visible {
|
|
87
|
+
background: transparent;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
.accordion :global([class*="accordion-content-inner"]) {
|
|
91
|
+
padding: var(--rs-space-3) 0 0 0;
|
|
92
|
+
border: none;
|
|
93
|
+
box-shadow: none;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.children {
|
|
97
|
+
display: flex;
|
|
98
|
+
flex-direction: column;
|
|
99
|
+
padding-left: var(--rs-space-5);
|
|
100
|
+
width: 100%;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.trigger {
|
|
104
|
+
color: var(--rs-color-foreground-base-secondary);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
.fieldInfo {
|
|
108
|
+
flex: 1;
|
|
109
|
+
min-width: 0;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.fieldInput {
|
|
113
|
+
flex: 1;
|
|
114
|
+
min-width: 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.arrayItems {
|
|
118
|
+
gap: var(--rs-space-3);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.arrayItem {
|
|
122
|
+
align-items: center;
|
|
123
|
+
border: 1px solid var(--rs-color-border-base-primary);
|
|
124
|
+
border-radius: 8px;
|
|
125
|
+
padding: var(--rs-space-3) var(--rs-space-4);
|
|
126
|
+
}
|