@alauda/doom 0.1.0 → 0.2.1
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/lib/cli/config.d.ts +1 -3
- package/lib/cli/constants.d.ts +2 -0
- package/lib/cli/constants.js +5 -0
- package/lib/cli/load-config.js +2 -1
- package/lib/plugins/api/index.d.ts +2 -0
- package/lib/plugins/api/index.js +50 -0
- package/lib/plugins/api/types.d.ts +28 -0
- package/lib/plugins/api/types.js +1 -0
- package/lib/plugins/global/index.js +3 -1
- package/lib/plugins/index.d.ts +1 -0
- package/lib/plugins/index.js +1 -0
- package/lib/plugins/swagger/index.d.ts +2 -0
- package/lib/plugins/swagger/index.js +38 -0
- package/lib/plugins/swagger/types.d.ts +28 -0
- package/lib/plugins/swagger/types.js +1 -0
- package/lib/runtime/components/Directive.d.ts +11 -0
- package/lib/runtime/components/Directive.js +17 -0
- package/lib/runtime/components/K8sCrd.d.ts +19 -0
- package/lib/runtime/components/K8sCrd.js +65 -0
- package/lib/runtime/components/OpenAPIPath.d.ts +14 -0
- package/lib/runtime/components/OpenAPIPath.js +110 -0
- package/lib/runtime/components/OpenAPIRef.d.ts +12 -0
- package/lib/runtime/components/OpenAPIRef.js +100 -0
- package/lib/runtime/components/Overview.js +1 -1
- package/lib/runtime/components/SwaggerModel.d.ts +5 -0
- package/lib/runtime/components/SwaggerModel.js +5 -0
- package/lib/runtime/components/SwaggerPath.d.ts +5 -0
- package/lib/runtime/components/SwaggerPath.js +32 -0
- package/lib/runtime/components/_HeadingTitle.d.ts +9 -0
- package/lib/runtime/components/_HeadingTitle.js +15 -0
- package/lib/runtime/components/_Markdown.d.ts +3 -0
- package/lib/runtime/components/_Markdown.js +6 -0
- package/lib/runtime/components/_RefLink.d.ts +4 -0
- package/lib/runtime/components/_RefLink.js +19 -0
- package/lib/runtime/components/index.d.ts +3 -0
- package/lib/runtime/components/index.js +3 -0
- package/lib/runtime/hooks/index.d.ts +1 -0
- package/lib/runtime/hooks/index.js +1 -0
- package/lib/runtime/hooks/useTranslation.d.ts +1 -0
- package/lib/runtime/hooks/useTranslation.js +8 -0
- package/lib/runtime/index.d.ts +3 -0
- package/lib/runtime/index.js +3 -0
- package/lib/runtime/translation.d.ts +13 -0
- package/lib/runtime/translation.js +11 -0
- package/lib/runtime/types.d.ts +11 -0
- package/lib/runtime/types.js +1 -0
- package/lib/runtime/utils.d.ts +9 -0
- package/lib/runtime/utils.js +19 -0
- package/lib/utils/helpers.d.ts +1 -0
- package/lib/utils/helpers.js +17 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +1 -0
- package/lib/utils/types.d.ts +8 -0
- package/lib/utils/types.js +1 -0
- package/package.json +22 -15
- package/styles/global.scss +33 -0
package/lib/cli/config.d.ts
CHANGED
package/lib/cli/constants.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export declare const DEFAULT_CONFIG_NAME = "doom.config";
|
|
2
|
+
export declare const JSON_EXTENSION = ".json";
|
|
2
3
|
export declare const YAML_EXTENSIONS: readonly [".yaml", ".yml"];
|
|
4
|
+
export declare const STATIC_CONFIG_EXTENSIONS: readonly [".json", ".yaml", ".yml"];
|
|
3
5
|
export declare const JS_EXTENSIONS: readonly [".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
|
|
4
6
|
export declare const DEFAULT_EXTENSIONS: readonly [".yaml", ".yml", ".js", ".ts", ".mjs", ".mts", ".cjs", ".cts"];
|
|
5
7
|
export declare const DEFAULT_CONFIGS: ("doom.config.yaml" | "doom.config.yml" | "doom.config.js" | "doom.config.ts" | "doom.config.mjs" | "doom.config.mts" | "doom.config.cjs" | "doom.config.cts")[];
|
package/lib/cli/constants.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
export const DEFAULT_CONFIG_NAME = 'doom.config';
|
|
2
|
+
export const JSON_EXTENSION = '.json';
|
|
2
3
|
export const YAML_EXTENSIONS = ['.yaml', '.yml'];
|
|
4
|
+
export const STATIC_CONFIG_EXTENSIONS = [
|
|
5
|
+
JSON_EXTENSION,
|
|
6
|
+
...YAML_EXTENSIONS,
|
|
7
|
+
];
|
|
3
8
|
export const JS_EXTENSIONS = [
|
|
4
9
|
'.js',
|
|
5
10
|
'.ts',
|
package/lib/cli/load-config.js
CHANGED
|
@@ -6,7 +6,7 @@ import fs from 'node:fs';
|
|
|
6
6
|
import path from 'node:path';
|
|
7
7
|
import rehypeRaw from 'rehype-raw';
|
|
8
8
|
import { parse } from 'yaml';
|
|
9
|
-
import { autoSidebarPlugin, globalPlugin } from '../plugins/index.js';
|
|
9
|
+
import { autoSidebarPlugin, globalPlugin, apiPlugin } from '../plugins/index.js';
|
|
10
10
|
import { pkgResolve } from '../utils/helpers.js';
|
|
11
11
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
12
12
|
const DEFAULT_LOGO = '/logo.svg';
|
|
@@ -55,6 +55,7 @@ const getCommonConfig = (config) => {
|
|
|
55
55
|
}),
|
|
56
56
|
autoSidebarPlugin(),
|
|
57
57
|
globalPlugin(),
|
|
58
|
+
apiPlugin(),
|
|
58
59
|
],
|
|
59
60
|
builderConfig: {
|
|
60
61
|
server: {
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { openapiSchemaToJsonSchema } from '@openapi-contrib/openapi-schema-to-json-schema';
|
|
3
|
+
import { convertObj } from 'swagger2openapi';
|
|
4
|
+
import { glob } from 'tinyglobby';
|
|
5
|
+
import { resolveStaticConfig } from '../../utils/index.js';
|
|
6
|
+
const crdsMap = {};
|
|
7
|
+
const openapisMap = {};
|
|
8
|
+
let allReferences;
|
|
9
|
+
export const apiPlugin = () => {
|
|
10
|
+
return {
|
|
11
|
+
name: 'doom-api',
|
|
12
|
+
async beforeBuild(config_) {
|
|
13
|
+
const config = config_;
|
|
14
|
+
if (!config.api) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const { crds, openapis, references } = config.api;
|
|
18
|
+
if (crds) {
|
|
19
|
+
for (const file of await glob(crds, {
|
|
20
|
+
cwd: config.root,
|
|
21
|
+
})) {
|
|
22
|
+
crdsMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (openapis) {
|
|
26
|
+
for (const file of await glob(openapis, {
|
|
27
|
+
cwd: config.root,
|
|
28
|
+
})) {
|
|
29
|
+
let doc = await resolveStaticConfig(path.resolve(config.root, file));
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
31
|
+
doc.info ??= { title: 'Unknown', version: '0.0.0' };
|
|
32
|
+
if ('swagger' in doc && doc.swagger === '2.0') {
|
|
33
|
+
doc = (await convertObj(doc, {})).openapi;
|
|
34
|
+
}
|
|
35
|
+
if ('openapi' in doc && doc.openapi.startsWith('3.0.')) {
|
|
36
|
+
doc = openapiSchemaToJsonSchema(doc);
|
|
37
|
+
doc.openapi = '3.1.0';
|
|
38
|
+
}
|
|
39
|
+
openapisMap[file] = doc;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
allReferences = references;
|
|
43
|
+
},
|
|
44
|
+
extendPageData(pageData) {
|
|
45
|
+
pageData.crdsMap = crdsMap;
|
|
46
|
+
pageData.openapisMap = openapisMap;
|
|
47
|
+
pageData.references = allReferences;
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
export interface CustomResourceDefinitionVersion {
|
|
3
|
+
name: string;
|
|
4
|
+
schema: {
|
|
5
|
+
openAPIV3Schema: OpenAPIV3.SchemaObject;
|
|
6
|
+
};
|
|
7
|
+
served: boolean;
|
|
8
|
+
storage: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CustomResourceDefinition {
|
|
11
|
+
apiVersion: string;
|
|
12
|
+
kind: 'CustomResourceDefinition';
|
|
13
|
+
metadata: {
|
|
14
|
+
annotations: Record<string, string>;
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
spec: {
|
|
18
|
+
group: string;
|
|
19
|
+
names: {
|
|
20
|
+
kind: string;
|
|
21
|
+
listKind: string;
|
|
22
|
+
plural: string;
|
|
23
|
+
singular: string;
|
|
24
|
+
};
|
|
25
|
+
scope: 'Namespaced' | 'Cluster';
|
|
26
|
+
versions: CustomResourceDefinitionVersion[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -11,7 +11,9 @@ export const globalPlugin = () => {
|
|
|
11
11
|
.readdirSync(componentsDir)
|
|
12
12
|
.filter((file) => {
|
|
13
13
|
const basename = path.basename(file, path.extname(file));
|
|
14
|
-
return !basename.
|
|
14
|
+
return (!basename.startsWith('_') &&
|
|
15
|
+
!basename.endsWith('.d') &&
|
|
16
|
+
basename !== 'index');
|
|
15
17
|
})
|
|
16
18
|
.map((file) => path.resolve(componentsDir, file)),
|
|
17
19
|
},
|
package/lib/plugins/index.d.ts
CHANGED
package/lib/plugins/index.js
CHANGED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import path from 'node:path';
|
|
2
|
+
import { glob } from 'tinyglobby';
|
|
3
|
+
import { resolveStaticConfig } from '../../utils/index.js';
|
|
4
|
+
const crdMap = {};
|
|
5
|
+
const openapiMap = {};
|
|
6
|
+
let allModelReferences;
|
|
7
|
+
export const swaggerPlugin = () => {
|
|
8
|
+
return {
|
|
9
|
+
name: 'doom-swagger',
|
|
10
|
+
async beforeBuild(config_) {
|
|
11
|
+
const config = config_;
|
|
12
|
+
if (!config.swagger) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
const { crds, openapis, modelReferences } = config.swagger;
|
|
16
|
+
if (crds) {
|
|
17
|
+
for (const file of await glob(crds, {
|
|
18
|
+
cwd: config.root,
|
|
19
|
+
})) {
|
|
20
|
+
crdMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
if (openapis) {
|
|
24
|
+
for (const file of await glob(openapis, {
|
|
25
|
+
cwd: config.root,
|
|
26
|
+
})) {
|
|
27
|
+
openapiMap[file] = await resolveStaticConfig(path.resolve(config.root, file));
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
allModelReferences = modelReferences;
|
|
31
|
+
},
|
|
32
|
+
extendPageData(pageData) {
|
|
33
|
+
pageData.crdMap = crdMap;
|
|
34
|
+
pageData.openapiMap = openapiMap;
|
|
35
|
+
pageData.modelReferences = allModelReferences;
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
export interface CustomResourceDefinitionVersion {
|
|
3
|
+
name: string;
|
|
4
|
+
schema: {
|
|
5
|
+
openAPIV3Schema: OpenAPIV3.SchemaObject;
|
|
6
|
+
};
|
|
7
|
+
served: boolean;
|
|
8
|
+
storage: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface CustomResourceDefinition {
|
|
11
|
+
apiVersion: string;
|
|
12
|
+
kind: 'CustomResourceDefinition';
|
|
13
|
+
metadata: {
|
|
14
|
+
annotations: Record<string, string>;
|
|
15
|
+
name: string;
|
|
16
|
+
};
|
|
17
|
+
spec: {
|
|
18
|
+
group: string;
|
|
19
|
+
names: {
|
|
20
|
+
kind: string;
|
|
21
|
+
listKind: string;
|
|
22
|
+
plural: string;
|
|
23
|
+
singular: string;
|
|
24
|
+
};
|
|
25
|
+
scope: 'Namespaced' | 'Cluster';
|
|
26
|
+
versions: CustomResourceDefinitionVersion[];
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
export interface DirectiveProps {
|
|
3
|
+
type?: 'danger' | 'details' | 'info' | 'note' | 'tip' | 'warning';
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
title?: ReactNode;
|
|
7
|
+
open?: boolean;
|
|
8
|
+
onToggle?: (open: boolean) => void;
|
|
9
|
+
}
|
|
10
|
+
export declare const Directive: ({ className, type, title, children, open, onToggle, }: DirectiveProps) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export default Directive;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { upperCase } from 'es-toolkit';
|
|
4
|
+
import { useCallback } from 'react';
|
|
5
|
+
export const Directive = ({ className, type = 'info', title, children, open, onToggle, }) => {
|
|
6
|
+
const rootClassName = clsx('rspress-directive', type, className);
|
|
7
|
+
const titleNode = title || upperCase(type);
|
|
8
|
+
const contentNode = (_jsx("div", { className: "rspress-directive-content", children: children }));
|
|
9
|
+
const handleToggle = useCallback((ev) => {
|
|
10
|
+
onToggle?.(ev.currentTarget.open);
|
|
11
|
+
}, [onToggle]);
|
|
12
|
+
if (type === 'details') {
|
|
13
|
+
return (_jsxs("details", { className: rootClassName, open: open, onToggle: handleToggle, children: [_jsx("summary", { className: "rspress-directive-title", children: titleNode }), contentNode] }));
|
|
14
|
+
}
|
|
15
|
+
return (_jsxs("div", { className: rootClassName, children: [_jsx("div", { className: "rspress-directive-title", children: titleNode }), contentNode] }));
|
|
16
|
+
};
|
|
17
|
+
export default Directive;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modified based on @see https://github.com/crdsdev/doc/blob/main/template/doc.html
|
|
3
|
+
*/
|
|
4
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
5
|
+
export interface K8sCrdProps {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
export declare const K8sCrdSchemaPart: ({ name, parent, schema: property, openAll, }: {
|
|
9
|
+
name: string;
|
|
10
|
+
parent: OpenAPIV3_1.SchemaObject;
|
|
11
|
+
schema: OpenAPIV3_1.SchemaObject;
|
|
12
|
+
openAll: boolean;
|
|
13
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export declare const K8sCrdSchema: ({ schema, version, }: {
|
|
15
|
+
schema: OpenAPIV3_1.SchemaObject;
|
|
16
|
+
version: string;
|
|
17
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export declare const K8sCrd: ({ name }: K8sCrdProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
19
|
+
export default K8sCrd;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* modified based on @see https://github.com/crdsdev/doc/blob/main/template/doc.html
|
|
4
|
+
*/
|
|
5
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
6
|
+
import { Badge, Button, getCustomMDXComponent } from '@rspress/core/theme';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
8
|
+
import { useTranslation } from '../hooks/index.js';
|
|
9
|
+
import { Markdown } from './_Markdown.js';
|
|
10
|
+
import Directive from './Directive.js';
|
|
11
|
+
const X = getCustomMDXComponent();
|
|
12
|
+
export const K8sCrdSchemaPart = ({ name, parent, schema: property, openAll, }) => {
|
|
13
|
+
const [open, setOpen] = useState(openAll);
|
|
14
|
+
const onToggle = useCallback((open) => {
|
|
15
|
+
setOpen(open);
|
|
16
|
+
}, []);
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
setOpen(openAll);
|
|
19
|
+
}, [openAll]);
|
|
20
|
+
const [props, required, type, schema] = useMemo(() => {
|
|
21
|
+
let schema = property;
|
|
22
|
+
let props = property.properties;
|
|
23
|
+
let type = property.type;
|
|
24
|
+
if (property.type === 'array') {
|
|
25
|
+
const itemsSchema = property.items;
|
|
26
|
+
if (itemsSchema.type === 'object') {
|
|
27
|
+
schema = itemsSchema;
|
|
28
|
+
props = itemsSchema.properties;
|
|
29
|
+
type = `[]object`;
|
|
30
|
+
}
|
|
31
|
+
else if (itemsSchema.type) {
|
|
32
|
+
type = `[]${itemsSchema.type}`;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
let required = false;
|
|
36
|
+
if (parent.required?.includes(name)) {
|
|
37
|
+
required = true;
|
|
38
|
+
}
|
|
39
|
+
return [props, required, type, schema];
|
|
40
|
+
}, [name, parent, property]);
|
|
41
|
+
return (_jsx(_Fragment, { children: _jsxs(Directive, { type: "details", title: _jsxs(_Fragment, { children: [name, type && _jsx(X.code, { children: type }), required && _jsx(Badge, { children: "required" })] }), open: open, onToggle: onToggle, children: [_jsx(Markdown, { children: schema.description }), props &&
|
|
42
|
+
Object.entries(props).map(([name, subSchema]) => (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, openAll: openAll }, name)))] }) }));
|
|
43
|
+
};
|
|
44
|
+
export const K8sCrdSchema = ({ schema, version, }) => {
|
|
45
|
+
const { description, properties } = schema;
|
|
46
|
+
const t = useTranslation();
|
|
47
|
+
const [openAll, setOpenAll] = useState(false);
|
|
48
|
+
const expandAll = useCallback(() => {
|
|
49
|
+
setOpenAll(true);
|
|
50
|
+
}, []);
|
|
51
|
+
const collapseAll = useCallback(() => {
|
|
52
|
+
setOpenAll(false);
|
|
53
|
+
}, []);
|
|
54
|
+
return (_jsxs(_Fragment, { children: [_jsx(Markdown, { children: description }), _jsxs("div", { className: "flex items-center", children: [_jsxs("span", { children: [_jsx(X.code, { children: version }), _jsx(Badge, { children: "version" })] }), properties != null && (_jsxs("div", { className: "ml-auto", children: [_jsx(Button, { className: "doom-btn", type: "button", text: _jsxs("span", { onClick: collapseAll, children: ["- ", t('collapse_all')] }), size: "medium", theme: "alt" }), _jsx(Button, { className: "doom-btn ml-2", type: "button", text: _jsxs("span", { onClick: expandAll, children: ["+ ", t('expand_all')] }), size: "medium", theme: "alt" })] }))] }), properties == null ? (_jsx(Directive, { type: "warning", children: t('crd_no_schema') })) : (_jsx("div", { className: "doom-collapse-group", children: Object.entries(properties).map(([name, subSchema]) => (_jsx(K8sCrdSchemaPart, { name: name, parent: schema, schema: subSchema, openAll: openAll }, name))) }))] }));
|
|
55
|
+
};
|
|
56
|
+
export const K8sCrd = ({ name }) => {
|
|
57
|
+
const { page } = usePageData();
|
|
58
|
+
const crd = useMemo(() => Object.values(page.crdsMap || {}).find((crd) => crd.metadata.name === name), [page]);
|
|
59
|
+
if (!crd) {
|
|
60
|
+
console.error(`No CustomResourceDefinition found for ${name}`);
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return (_jsxs(_Fragment, { children: [_jsxs(X.p, { children: [_jsx(X.code, { children: crd.spec.group }), _jsx(Badge, { children: "group" })] }), crd.spec.versions.map((version) => (_jsx(K8sCrdSchema, { schema: version.schema.openAPIV3Schema, version: version.name })))] }));
|
|
64
|
+
};
|
|
65
|
+
export default K8sCrd;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
export interface OpenAPIPathProps {
|
|
3
|
+
path: string;
|
|
4
|
+
}
|
|
5
|
+
export declare const OpenAPIParameters: ({ parameters, openapi, }: {
|
|
6
|
+
parameters: Array<OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.ParameterObject>;
|
|
7
|
+
openapi: OpenAPIV3_1.Document;
|
|
8
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export declare const OpenAPIResponses: ({ responses, openapi, }: {
|
|
10
|
+
responses: OpenAPIV3_1.ResponsesObject;
|
|
11
|
+
openapi: OpenAPIV3_1.Document;
|
|
12
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare const OpenAPIPath: ({ path }: OpenAPIPathProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export default OpenAPIPath;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
3
|
+
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
4
|
+
import BananaSlug from 'github-slugger';
|
|
5
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
6
|
+
import { useMemo } from 'react';
|
|
7
|
+
import { DEFAULT_COMMON_REFS, omitRoutePathRefs, resolveRef } from '../utils.js';
|
|
8
|
+
import { HeadingTitle } from './_HeadingTitle.js';
|
|
9
|
+
import { RefLink } from './_RefLink.js';
|
|
10
|
+
import OpenAPIRef from './OpenAPIRef.js';
|
|
11
|
+
import { Markdown } from './_Markdown.js';
|
|
12
|
+
const X = getCustomMDXComponent();
|
|
13
|
+
export const OpenAPIParameters = ({ parameters, openapi, }) => {
|
|
14
|
+
return (_jsx(X.ul, { children: parameters.map((param, index) => {
|
|
15
|
+
const paramObj = '$ref' in param
|
|
16
|
+
? resolveRef(openapi, param.$ref)
|
|
17
|
+
: param;
|
|
18
|
+
const type = paramObj.schema &&
|
|
19
|
+
('$ref' in paramObj.schema ? paramObj.schema : paramObj.schema.type);
|
|
20
|
+
let typeNode;
|
|
21
|
+
if (typeof type === 'string') {
|
|
22
|
+
typeNode = _jsx(X.code, { children: type });
|
|
23
|
+
}
|
|
24
|
+
else if (type) {
|
|
25
|
+
typeNode = _jsx(RefLink, { "$ref": type.$ref });
|
|
26
|
+
}
|
|
27
|
+
return (_jsxs(X.li, { children: [_jsx(X.code, { children: paramObj.name }), "(", _jsxs("em", { children: ["in ", paramObj.in] }), "):", ' ', typeNode, ", ", paramObj.required ? 'required' : 'optional', _jsx(Markdown, { children: paramObj.description })] }, index));
|
|
28
|
+
}) }));
|
|
29
|
+
};
|
|
30
|
+
export const OpenAPIResponses = ({ responses, openapi, }) => {
|
|
31
|
+
return (_jsx(X.ul, { children: Object.entries(responses).map(([code, response], index) => {
|
|
32
|
+
const responseObj = '$ref' in response
|
|
33
|
+
? resolveRef(openapi, response.$ref)
|
|
34
|
+
: response;
|
|
35
|
+
const schema = responseObj.content?.['application/json'].schema;
|
|
36
|
+
let refNode;
|
|
37
|
+
if (schema && '$ref' in schema) {
|
|
38
|
+
refNode = (_jsxs(_Fragment, { children: ["(", _jsx(RefLink, { "$ref": schema.$ref }), ")"] }));
|
|
39
|
+
}
|
|
40
|
+
return (_jsxs(X.li, { children: [_jsx(X.code, { children: code }), refNode, ": ", responseObj.description] }, index));
|
|
41
|
+
}) }));
|
|
42
|
+
};
|
|
43
|
+
const getRefsForPath = (openapi, path, knownRefs) => {
|
|
44
|
+
const pathSchema = openapi.paths?.[path];
|
|
45
|
+
if (!pathSchema) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
const refs = new Set();
|
|
49
|
+
const collectRefs = (schema) => {
|
|
50
|
+
if ('$ref' in schema && typeof schema.$ref === 'string') {
|
|
51
|
+
const ref = schema.$ref.replace('#/components/schemas/', '');
|
|
52
|
+
if (!knownRefs[ref]) {
|
|
53
|
+
refs.add(ref);
|
|
54
|
+
schema = resolveRef(openapi, schema.$ref);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
for (const value of Object.values(schema)) {
|
|
58
|
+
if (typeof value === 'object') {
|
|
59
|
+
collectRefs(value);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
for (const method of Object.values(OpenAPIV3.HttpMethods)) {
|
|
64
|
+
if (pathSchema[method]?.requestBody) {
|
|
65
|
+
collectRefs(pathSchema[method].requestBody);
|
|
66
|
+
}
|
|
67
|
+
if (pathSchema[method]?.responses) {
|
|
68
|
+
for (const response in pathSchema[method].responses) {
|
|
69
|
+
collectRefs(pathSchema[method].responses[response]);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return Array.from(refs);
|
|
74
|
+
};
|
|
75
|
+
export const OpenAPIPath = ({ path }) => {
|
|
76
|
+
const { page } = usePageData();
|
|
77
|
+
const slugger = useMemo(() => new BananaSlug(), []);
|
|
78
|
+
const [pathItem, openapi, refs] = useMemo(() => {
|
|
79
|
+
for (const openapi of Object.values(page.openapisMap || {})) {
|
|
80
|
+
const pathItem = openapi.paths?.[path];
|
|
81
|
+
if (pathItem) {
|
|
82
|
+
return [
|
|
83
|
+
pathItem,
|
|
84
|
+
openapi,
|
|
85
|
+
getRefsForPath(openapi, path, omitRoutePathRefs({
|
|
86
|
+
...page.references,
|
|
87
|
+
...DEFAULT_COMMON_REFS,
|
|
88
|
+
}, page.routePath)),
|
|
89
|
+
];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return [];
|
|
93
|
+
}, [page.openapiMap]);
|
|
94
|
+
if (!pathItem || !openapi) {
|
|
95
|
+
console.error(`No OpenAPI path definition found for ${path}`);
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 2, children: path }), pathItem.parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 3, children: "Common Parameters" }), _jsx(OpenAPIParameters, { parameters: pathItem.parameters, openapi: openapi })] })), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
99
|
+
if (!pathItem[method]) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const { description, parameters, requestBody, responses, summary } = pathItem[method];
|
|
103
|
+
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { slugger: slugger, level: 3, children: [_jsx(X.code, { children: method }), summary] }), _jsx(Markdown, { children: description }), parameters && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Parameters" }), _jsx(OpenAPIParameters, { parameters: parameters, openapi: openapi })] })), requestBody && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Request Body" }), _jsx(RefLink, { "$ref": '$ref' in requestBody
|
|
104
|
+
? requestBody.$ref
|
|
105
|
+
: requestBody.content['application/json'].schema?.$ref })] })), responses && (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slugger: slugger, level: 4, children: "Response" }), _jsx(OpenAPIResponses, { responses: responses, openapi: openapi })] }))] }));
|
|
106
|
+
}), refs?.map((ref, index) => {
|
|
107
|
+
return (_jsx(OpenAPIRef, { schema: ref, openapi: openapi, collectRefs: false }, index));
|
|
108
|
+
})] }));
|
|
109
|
+
};
|
|
110
|
+
export default OpenAPIPath;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
export interface OpenAPIRefProps {
|
|
3
|
+
schema: string;
|
|
4
|
+
openapi?: OpenAPIV3_1.Document;
|
|
5
|
+
collectRefs?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare const OpenAPIProperties: ({ properties, openapi, }: {
|
|
8
|
+
properties: Record<string, OpenAPIV3_1.ReferenceObject | OpenAPIV3_1.SchemaObject>;
|
|
9
|
+
openapi: OpenAPIV3_1.Document;
|
|
10
|
+
}) => import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare const OpenAPIRef: ({ schema, openapi: openapi_, collectRefs, }: OpenAPIRefProps) => import("react/jsx-runtime").JSX.Element | null;
|
|
12
|
+
export default OpenAPIRef;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
3
|
+
import { getCustomMDXComponent } from '@rspress/theme-default';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import { DEFAULT_COMMON_REFS, modelName, omitRoutePathRefs, resolveRef, } from '../utils.js';
|
|
6
|
+
import { HeadingTitle } from './_HeadingTitle.js';
|
|
7
|
+
import { RefLink } from './_RefLink.js';
|
|
8
|
+
import { Markdown } from './_Markdown.js';
|
|
9
|
+
const X = getCustomMDXComponent();
|
|
10
|
+
export const OpenAPIProperties = ({ properties, openapi, }) => {
|
|
11
|
+
return (_jsx(X.ul, { children: Object.entries(properties).map(([name, prop], index) => {
|
|
12
|
+
const propObj = '$ref' in prop ? resolveRef(openapi, prop.$ref) : prop;
|
|
13
|
+
const type = propObj.type;
|
|
14
|
+
let typeNode;
|
|
15
|
+
if (type === 'array') {
|
|
16
|
+
const { items } = propObj;
|
|
17
|
+
const itemsObj = '$ref' in items ? resolveRef(openapi, items.$ref) : items;
|
|
18
|
+
const itemsType = itemsObj.type;
|
|
19
|
+
typeNode = (_jsxs("code", { children: ["[]", typeof itemsType === 'string'
|
|
20
|
+
? itemsType
|
|
21
|
+
: '$ref' in items && _jsx(RefLink, { "$ref": items.$ref })] }));
|
|
22
|
+
}
|
|
23
|
+
else if (type === 'object') {
|
|
24
|
+
if (typeof propObj.additionalProperties === 'object') {
|
|
25
|
+
const props = propObj.additionalProperties;
|
|
26
|
+
const propsObj = '$ref' in props ? resolveRef(openapi, props.$ref) : props;
|
|
27
|
+
const propsType = propsObj.type;
|
|
28
|
+
typeNode = (_jsxs("code", { children: ["map[string]", typeof propsType === 'string'
|
|
29
|
+
? propsType
|
|
30
|
+
: '$ref' in props && _jsx(RefLink, { "$ref": props.$ref })] }));
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
typeNode = _jsx(X.code, { children: type });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (typeof type === 'string') {
|
|
37
|
+
typeNode = _jsx(X.code, { children: type });
|
|
38
|
+
}
|
|
39
|
+
else if ('$ref' in prop) {
|
|
40
|
+
typeNode = _jsx(RefLink, { "$ref": prop.$ref });
|
|
41
|
+
}
|
|
42
|
+
return (_jsxs(X.li, { children: [_jsx(X.code, { children: name }), ": ", typeNode, _jsx(Markdown, { children: propObj.description })] }, index));
|
|
43
|
+
}) }));
|
|
44
|
+
};
|
|
45
|
+
const getRefsForSchema = (openapi, schema, knownRefs) => {
|
|
46
|
+
const refSchema = openapi.components?.schemas[schema];
|
|
47
|
+
if (!refSchema) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const refs = new Set();
|
|
51
|
+
const collectRefs = (schema) => {
|
|
52
|
+
if ('$ref' in schema && typeof schema.$ref === 'string') {
|
|
53
|
+
const ref = schema.$ref.replace('#/components/schemas/', '');
|
|
54
|
+
if (!knownRefs[ref]) {
|
|
55
|
+
refs.add(ref);
|
|
56
|
+
schema = resolveRef(openapi, schema.$ref);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
for (const value of Object.values(schema)) {
|
|
60
|
+
if (typeof value === 'object') {
|
|
61
|
+
collectRefs(value);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
collectRefs(refSchema);
|
|
66
|
+
return Array.from(refs);
|
|
67
|
+
};
|
|
68
|
+
export const OpenAPIRef = ({ schema, openapi: openapi_, collectRefs = true, }) => {
|
|
69
|
+
const { page } = usePageData();
|
|
70
|
+
const [schemaItem, openapi] = useMemo(() => {
|
|
71
|
+
if (openapi_) {
|
|
72
|
+
return [
|
|
73
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments -- no sure to understand
|
|
74
|
+
resolveRef(openapi_, schema),
|
|
75
|
+
openapi_,
|
|
76
|
+
];
|
|
77
|
+
}
|
|
78
|
+
for (const openapi of Object.values(page.openapisMap || {})) {
|
|
79
|
+
const schemaItem = openapi.components?.schemas?.[schema];
|
|
80
|
+
if (schemaItem) {
|
|
81
|
+
return [schemaItem, openapi];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return [];
|
|
85
|
+
}, []);
|
|
86
|
+
if (!schemaItem || !openapi) {
|
|
87
|
+
console.error(`No OpenAPI schema definition found for ${schema}`);
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
const refs = useMemo(() => {
|
|
91
|
+
if (collectRefs) {
|
|
92
|
+
return getRefsForSchema(openapi, schema, omitRoutePathRefs({
|
|
93
|
+
...page.references,
|
|
94
|
+
...DEFAULT_COMMON_REFS,
|
|
95
|
+
}, page.routePath));
|
|
96
|
+
}
|
|
97
|
+
}, [collectRefs, openapi, page.routePath, schema]);
|
|
98
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { slug: schema, level: 2, children: modelName(schema) }), _jsx(Markdown, { children: schemaItem.description }), schemaItem.properties && (_jsx(OpenAPIProperties, { properties: schemaItem.properties, openapi: openapi })), refs?.map((schema, index) => (_jsx(OpenAPIRef, { schema: schema, openapi: openapi, collectRefs: false }, index)))] }));
|
|
99
|
+
};
|
|
100
|
+
export default OpenAPIRef;
|
|
@@ -123,6 +123,6 @@ export function Overview(props) {
|
|
|
123
123
|
return [];
|
|
124
124
|
}, [overviewSidebarGroups, routePath, frontmatter]);
|
|
125
125
|
return (_jsxs("div", { className: "overview-index mx-auto", children: [content, groups.map((group) => (_jsxs(Fragment, { children: [(group.name === title || group.name === defaultGroupTitle) &&
|
|
126
|
-
groups.length === 1 ? (_jsx("h2", { style: { paddingTop: 0 } })) : (_jsx("h2", { children: renderInlineMarkdown(group.name) })), _jsx("div", { className: classes.overviewGroups, children: group.items.map((item) => (_jsxs("div", { className: classes.overviewGroup, children: [_jsx("div", { className: "flex", children: _jsx("h3", { style: { marginBottom: 8 }, children: _jsx(Link, { href: normalizeHref(item.link), children: renderInlineMarkdown(item.text) }) }) }), _jsx("div", { className: classes.overviewDescription, children: item.description }), _jsx("ul", { className: "list-none", children: item.headers?.map((header) => (_jsx("li", { className: `${classes.overviewGroupLi} ${classes[`level${header.depth}`]} first:mt-2`, children: _jsx(Link, { href: `${normalizeHref(item.link)}#${header.id}`, children: renderInlineMarkdown(header.text) }) }, header.id))) })] }, item.link))) })] }, group.name)))] }));
|
|
126
|
+
groups.length === 1 ? (_jsx("h2", { style: { paddingTop: 0 } })) : (_jsx("h2", { children: renderInlineMarkdown(group.name) })), _jsx("div", { className: classes.overviewGroups, children: group.items.map((item) => (_jsxs("div", { className: classes.overviewGroup, children: [_jsx("div", { className: "flex break-all", children: _jsx("h3", { style: { marginBottom: 8 }, children: _jsx(Link, { href: normalizeHref(item.link), children: renderInlineMarkdown(item.text) }) }) }), _jsx("div", { className: classes.overviewDescription, children: item.description }), _jsx("ul", { className: "list-none", children: item.headers?.map((header) => (_jsx("li", { className: `${classes.overviewGroupLi} ${classes[`level${header.depth}`]} first:mt-2`, children: _jsx(Link, { href: `${normalizeHref(item.link)}#${header.id}`, children: renderInlineMarkdown(header.text) }) }, header.id))) })] }, item.link))) })] }, group.name)))] }));
|
|
127
127
|
}
|
|
128
128
|
export default Overview;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
3
|
+
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
4
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { HeadingTitle } from './_HeadingTitle.js';
|
|
7
|
+
export const SwaggerPath = ({ path }) => {
|
|
8
|
+
const X = useMemo(getCustomMDXComponent, []);
|
|
9
|
+
const { page } = usePageData();
|
|
10
|
+
const pathItem = useMemo(() => {
|
|
11
|
+
for (const [, openapi] of Object.entries(page.openapiMap || {})) {
|
|
12
|
+
const pathItem = openapi.paths?.[path];
|
|
13
|
+
if (pathItem) {
|
|
14
|
+
return pathItem;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}, [page.openapiMap]);
|
|
18
|
+
if (!pathItem) {
|
|
19
|
+
console.error(`No OpenAPI path definition found for ${path}`);
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
return (_jsxs(_Fragment, { children: [_jsx(HeadingTitle, { level: 2, children: path }), Object.values(OpenAPIV3.HttpMethods).map((method) => {
|
|
23
|
+
if (!pathItem[method]) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
const { parameters, summary } = pathItem[method];
|
|
27
|
+
return (_jsxs(_Fragment, { children: [_jsxs(HeadingTitle, { level: 3, children: [_jsx(X.code, { children: method }), summary] }), _jsx(HeadingTitle, { level: 4, children: "Parameters" }), _jsx(X.ul, { children: parameters?.map((parameter, index) => {
|
|
28
|
+
return (_jsxs(X.li, { children: [_jsx(X.code, { children: parameter.name }), parameter.description] }, index));
|
|
29
|
+
}) })] }));
|
|
30
|
+
})] }));
|
|
31
|
+
};
|
|
32
|
+
export default SwaggerPath;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import BananaSlug from 'github-slugger';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
export interface HeadingTitleProps {
|
|
4
|
+
slug?: string;
|
|
5
|
+
slugger?: BananaSlug;
|
|
6
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export declare const HeadingTitle: ({ slug, slugger, level, children, }: HeadingTitleProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
3
|
+
import { Children, useMemo } from 'react';
|
|
4
|
+
export const HeadingTitle = ({ slug, slugger, level, children, }) => {
|
|
5
|
+
const X = useMemo(getCustomMDXComponent, []);
|
|
6
|
+
const HeadingComponents = useMemo(() => {
|
|
7
|
+
return [null, X.h1, X.h2, X.h3, X.h4, X.h5, X.h6];
|
|
8
|
+
}, [X]);
|
|
9
|
+
const HeadingComponent = HeadingComponents[level];
|
|
10
|
+
const id = useMemo(() => slug ||
|
|
11
|
+
slugger?.slug(Children.toArray(children)
|
|
12
|
+
.filter((it) => typeof it === 'string')
|
|
13
|
+
.join('')), [slug, children]);
|
|
14
|
+
return (_jsxs(HeadingComponent, { id: id, children: [children, _jsx(X.a, { className: "header-anchor", href: `#${id}`, "aria-hidden": true, children: "#" })] }));
|
|
15
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
3
|
+
import ReactMarkdown from 'react-markdown';
|
|
4
|
+
import remarkGfm from 'remark-gfm';
|
|
5
|
+
const components = getCustomMDXComponent();
|
|
6
|
+
export const Markdown = ({ children }) => children && (_jsx(ReactMarkdown, { remarkPlugins: [[remarkGfm]], components: components, skipHtml: true, children: children }));
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
3
|
+
import { DEFAULT_COMMON_REFS, modelName } from '../utils.js';
|
|
4
|
+
import { usePageData } from '@rspress/core/runtime';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
const X = getCustomMDXComponent();
|
|
7
|
+
export const RefLink = ({ $ref }) => {
|
|
8
|
+
const { page } = usePageData();
|
|
9
|
+
const references = useMemo(() => ({
|
|
10
|
+
...DEFAULT_COMMON_REFS,
|
|
11
|
+
...page.references,
|
|
12
|
+
}), []);
|
|
13
|
+
if (!$ref) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
const ref = $ref.replace('/components/schemas/', '');
|
|
17
|
+
const refName = modelName(ref);
|
|
18
|
+
return _jsx(X.a, { href: references[ref.slice(1)] || ref, children: refName });
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTranslation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useTranslation.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const useTranslation: () => (key: "collapse_all" | "expand_all" | "crd_no_schema") => string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useLang } from '@rspress/core/runtime';
|
|
2
|
+
import { TRANSLATIONS } from '../translation.js';
|
|
3
|
+
import { useCallback } from 'react';
|
|
4
|
+
export const useTranslation = () => {
|
|
5
|
+
const lang = (useLang() || 'zh');
|
|
6
|
+
const translations = TRANSLATIONS[lang];
|
|
7
|
+
return useCallback((key) => translations[key], []);
|
|
8
|
+
};
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export declare const TRANSLATIONS: {
|
|
2
|
+
en: {
|
|
3
|
+
collapse_all: string;
|
|
4
|
+
expand_all: string;
|
|
5
|
+
crd_no_schema: string;
|
|
6
|
+
};
|
|
7
|
+
zh: {
|
|
8
|
+
collapse_all: string;
|
|
9
|
+
expand_all: string;
|
|
10
|
+
crd_no_schema: string;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export type Locale = keyof typeof TRANSLATIONS;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const en = {
|
|
2
|
+
collapse_all: 'Collapse All',
|
|
3
|
+
expand_all: 'Expand All',
|
|
4
|
+
crd_no_schema: 'This CRD has an empty or unspecified schema.',
|
|
5
|
+
};
|
|
6
|
+
const zh = {
|
|
7
|
+
collapse_all: '全部收起',
|
|
8
|
+
expand_all: '全部展开',
|
|
9
|
+
crd_no_schema: '此 CRD 未定义或定义为空。',
|
|
10
|
+
};
|
|
11
|
+
export const TRANSLATIONS = { en, zh };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { PageData } from '@rspress/core';
|
|
2
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
|
+
import type { CustomResourceDefinition } from '../plugins/api/types.js';
|
|
4
|
+
export interface ExtendedPage {
|
|
5
|
+
crdsMap?: Record<string, CustomResourceDefinition>;
|
|
6
|
+
openapisMap?: Record<string, OpenAPIV3_1.Document>;
|
|
7
|
+
references?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export interface ExtendedPageData extends PageData {
|
|
10
|
+
page: PageData['page'] & ExtendedPage;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
2
|
+
export declare const modelName: (ref: string) => string;
|
|
3
|
+
export declare const resolveRef: <T extends object = OpenAPIV3_1.SchemaObject>(openapi: OpenAPIV3_1.Document, ref: string) => T;
|
|
4
|
+
export declare const DEFAULT_COMMON_REFS: {
|
|
5
|
+
[k: string]: string;
|
|
6
|
+
};
|
|
7
|
+
export declare const omitRoutePathRefs: (refs: Record<string, string>, routePath: string) => {
|
|
8
|
+
[k: string]: string;
|
|
9
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { last, upperFirst } from 'es-toolkit';
|
|
2
|
+
import { get } from 'es-toolkit/compat';
|
|
3
|
+
export const modelName = (ref) => upperFirst(last(ref.split('.')));
|
|
4
|
+
export const resolveRef = (openapi, ref) => {
|
|
5
|
+
if (!ref.startsWith('#/')) {
|
|
6
|
+
ref = `#/components/schemas/${ref}`;
|
|
7
|
+
}
|
|
8
|
+
return get(openapi, ref.slice(2).split('/'));
|
|
9
|
+
};
|
|
10
|
+
const DEFAULT_COMMON_REFS_ = {
|
|
11
|
+
'v1alpha1.ListMeta': 'common-definitions/list-meta/#ListMeta',
|
|
12
|
+
'v1.ObjectMeta': 'common-definitions/object-meta/#ObjectMeta',
|
|
13
|
+
};
|
|
14
|
+
const K8S_DOC_PREFIX = 'https://kubernetes.io/docs/reference/kubernetes-api/';
|
|
15
|
+
export const DEFAULT_COMMON_REFS = Object.fromEntries(Object.entries(DEFAULT_COMMON_REFS_).map(([key, value]) => [
|
|
16
|
+
key,
|
|
17
|
+
`${K8S_DOC_PREFIX}${value}`,
|
|
18
|
+
]));
|
|
19
|
+
export const omitRoutePathRefs = (refs, routePath) => Object.fromEntries(Object.entries(refs).filter(([, value]) => routePath !== value.split('#')[0]));
|
package/lib/utils/helpers.d.ts
CHANGED
package/lib/utils/helpers.js
CHANGED
|
@@ -1,4 +1,21 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
1
2
|
import path from 'node:path';
|
|
3
|
+
import { parse } from 'yaml';
|
|
2
4
|
import { BASE_DIR, PKG_DIR } from './constants.js';
|
|
5
|
+
import { JSON_EXTENSION, YAML_EXTENSIONS } from '../cli/constants.js';
|
|
3
6
|
export const baseResolve = (...paths) => path.resolve(BASE_DIR, ...paths);
|
|
4
7
|
export const pkgResolve = (...paths) => path.resolve(PKG_DIR, ...paths);
|
|
8
|
+
export const resolveStaticConfig = async (filepath) => {
|
|
9
|
+
const extname = path.extname(filepath);
|
|
10
|
+
const content = await fs.readFile(filepath, 'utf-8');
|
|
11
|
+
if (extname === JSON_EXTENSION) {
|
|
12
|
+
if (!content.trim()) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
return JSON.parse(content);
|
|
16
|
+
}
|
|
17
|
+
if (YAML_EXTENSIONS.includes(extname)) {
|
|
18
|
+
return parse(content);
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`Unsupported file extension: ${extname}`);
|
|
21
|
+
};
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
6
|
"repository": {
|
|
@@ -9,11 +9,9 @@
|
|
|
9
9
|
},
|
|
10
10
|
"packageManager": "yarn@4.5.0",
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=18.
|
|
13
|
-
},
|
|
14
|
-
"bin": {
|
|
15
|
-
"doom": "lib/cli/index.js"
|
|
12
|
+
"node": ">=18.17.0 <20 || >=20.1.0"
|
|
16
13
|
},
|
|
14
|
+
"bin": "lib/cli/index.js",
|
|
17
15
|
"exports": {
|
|
18
16
|
"./package.json": "./package.json",
|
|
19
17
|
"./runtime": "./lib/runtime/index.js"
|
|
@@ -38,29 +36,38 @@
|
|
|
38
36
|
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register"
|
|
39
37
|
},
|
|
40
38
|
"dependencies": {
|
|
41
|
-
"@
|
|
42
|
-
"@rspress/
|
|
39
|
+
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
40
|
+
"@rspress/core": "^1.37.4",
|
|
41
|
+
"@rspress/plugin-preview": "^1.37.4",
|
|
43
42
|
"chokidar": "^4.0.1",
|
|
43
|
+
"clsx": "^2.1.1",
|
|
44
44
|
"commander": "^12.1.0",
|
|
45
|
+
"es-toolkit": "^1.29.0",
|
|
46
|
+
"react-markdown": "^8.0.7",
|
|
45
47
|
"rehype-raw": "^6.1.1",
|
|
46
|
-
"
|
|
48
|
+
"remark-gfm": "^3.0.1",
|
|
49
|
+
"swagger2openapi": "^7.0.8",
|
|
50
|
+
"tinyglobby": "^0.2.10",
|
|
51
|
+
"yaml": "^2.6.1",
|
|
47
52
|
"yoctocolors": "^2.1.1"
|
|
48
53
|
},
|
|
49
54
|
"devDependencies": {
|
|
50
|
-
"@eslint/js": "^9.
|
|
55
|
+
"@eslint/js": "^9.16.0",
|
|
51
56
|
"@swc-node/register": "^1.10.9",
|
|
52
|
-
"@swc/core": "1.
|
|
57
|
+
"@swc/core": "1.10.1",
|
|
53
58
|
"@types/eslint__js": "^8.42.3",
|
|
54
59
|
"@types/fs-extra": "^11.0.4",
|
|
55
|
-
"@types/node": "~18.
|
|
56
|
-
"
|
|
60
|
+
"@types/node": "~18.17.19",
|
|
61
|
+
"@types/swagger2openapi": "^7.0.4",
|
|
62
|
+
"eslint": "^9.16.0",
|
|
57
63
|
"lint-staged": "^15.2.10",
|
|
58
64
|
"npm-run-all2": "^7.0.1",
|
|
59
|
-
"
|
|
65
|
+
"openapi-types": "^12.1.3",
|
|
66
|
+
"prettier": "^3.4.2",
|
|
60
67
|
"prettier-plugin-pkg": "^0.18.1",
|
|
61
68
|
"simple-git-hooks": "^2.11.1",
|
|
62
|
-
"typescript": "^5.
|
|
63
|
-
"typescript-eslint": "^8.
|
|
69
|
+
"typescript": "^5.7.2",
|
|
70
|
+
"typescript-eslint": "^8.18.0"
|
|
64
71
|
},
|
|
65
72
|
"publishConfig": {
|
|
66
73
|
"access": "public"
|
package/styles/global.scss
CHANGED
|
@@ -4,3 +4,36 @@ td {
|
|
|
4
4
|
display: inline-block;
|
|
5
5
|
}
|
|
6
6
|
}
|
|
7
|
+
|
|
8
|
+
.doom-btn {
|
|
9
|
+
position: relative;
|
|
10
|
+
padding: 0 !important;
|
|
11
|
+
|
|
12
|
+
> span {
|
|
13
|
+
display: block;
|
|
14
|
+
padding: 0 20px;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.doom-collapse-group {
|
|
19
|
+
.rspress-directive {
|
|
20
|
+
margin-bottom: 0;
|
|
21
|
+
padding-top: 10px;
|
|
22
|
+
padding-bottom: 10px;
|
|
23
|
+
border-radius: 0;
|
|
24
|
+
|
|
25
|
+
&:first-child {
|
|
26
|
+
border-top-left-radius: var(--rp-radius-small);
|
|
27
|
+
border-top-right-radius: var(--rp-radius-small);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
&:last-child {
|
|
31
|
+
border-bottom-left-radius: var(--rp-radius-small);
|
|
32
|
+
border-bottom-right-radius: var(--rp-radius-small);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
+ .rspress-directive {
|
|
36
|
+
margin-top: -1px;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|