@alauda/doom 0.0.0-alpha.9 → 0.2.0
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 +2 -0
- 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 +100 -54
- 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/auto-sidebar/walk.js +3 -1
- 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/K8sCrd.d.ts +5 -0
- package/lib/runtime/components/K8sCrd.js +5 -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/index.d.ts +2 -0
- package/lib/runtime/index.js +2 -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 +25 -13
package/README.md
CHANGED
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
|
@@ -1,48 +1,77 @@
|
|
|
1
1
|
import { nodeTypes } from '@mdx-js/mdx';
|
|
2
|
-
import { addLeadingSlash, addTrailingSlash, } from '@rspress/core';
|
|
2
|
+
import { addLeadingSlash, addTrailingSlash, removeLeadingSlash, } from '@rspress/core';
|
|
3
|
+
import { pluginPreview } from '@rspress/plugin-preview';
|
|
3
4
|
import { logger } from '@rspress/shared/logger';
|
|
4
5
|
import fs from 'node:fs';
|
|
5
6
|
import path from 'node:path';
|
|
6
7
|
import rehypeRaw from 'rehype-raw';
|
|
7
8
|
import { parse } from 'yaml';
|
|
8
|
-
import { autoSidebarPlugin, globalPlugin } from '../plugins/index.js';
|
|
9
|
+
import { autoSidebarPlugin, globalPlugin, apiPlugin } from '../plugins/index.js';
|
|
9
10
|
import { pkgResolve } from '../utils/helpers.js';
|
|
10
11
|
import { CWD, DEFAULT_CONFIG_NAME, DEFAULT_EXTENSIONS, I18N_FILE, YAML_EXTENSIONS, } from './constants.js';
|
|
11
|
-
const DEFAULT_LOGO =
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
12
|
+
const DEFAULT_LOGO = '/logo.svg';
|
|
13
|
+
const getCommonConfig = (config) => {
|
|
14
|
+
return {
|
|
15
|
+
lang: 'en',
|
|
16
|
+
route: {
|
|
17
|
+
exclude: ['shared/**/*', 'doom.config.*'],
|
|
18
|
+
},
|
|
19
|
+
markdown: {
|
|
20
|
+
checkDeadLinks: true,
|
|
21
|
+
highlightLanguages: [['jsonc', 'json']],
|
|
22
|
+
mdxRs: false,
|
|
23
|
+
rehypePlugins: [[rehypeRaw, { passThrough: nodeTypes }]],
|
|
24
|
+
},
|
|
25
|
+
ssg: {
|
|
26
|
+
strict: true,
|
|
27
|
+
},
|
|
28
|
+
themeConfig: {
|
|
29
|
+
enableScrollToTop: true,
|
|
30
|
+
locales: 'lang' in config && config.lang == null
|
|
31
|
+
? undefined
|
|
32
|
+
: [
|
|
33
|
+
{
|
|
34
|
+
lang: 'zh',
|
|
35
|
+
label: '简体中文',
|
|
36
|
+
searchPlaceholderText: '搜索文档',
|
|
37
|
+
searchNoResultsText: '未搜索到相关结果',
|
|
38
|
+
searchSuggestedQueryText: '可更换不同的关键字后重试',
|
|
39
|
+
outlineTitle: '本页概览',
|
|
40
|
+
prevPageText: '上一页',
|
|
41
|
+
nextPageText: '下一页',
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
lang: 'en',
|
|
45
|
+
label: 'English',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
},
|
|
49
|
+
plugins: [
|
|
50
|
+
pluginPreview({
|
|
51
|
+
iframeOptions: {
|
|
52
|
+
devPort: 7891,
|
|
53
|
+
},
|
|
54
|
+
defaultRenderMode: 'pure',
|
|
55
|
+
}),
|
|
56
|
+
autoSidebarPlugin(),
|
|
57
|
+
globalPlugin(),
|
|
58
|
+
apiPlugin(),
|
|
59
|
+
],
|
|
60
|
+
builderConfig: {
|
|
61
|
+
server: {
|
|
62
|
+
open: true,
|
|
33
63
|
},
|
|
34
|
-
{
|
|
35
|
-
|
|
36
|
-
|
|
64
|
+
tools: {
|
|
65
|
+
rspack: {
|
|
66
|
+
resolve: {
|
|
67
|
+
extensionAlias: {
|
|
68
|
+
'.js': ['.ts', '.tsx', '.js'],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
37
72
|
},
|
|
38
|
-
],
|
|
39
|
-
},
|
|
40
|
-
plugins: [autoSidebarPlugin(), globalPlugin()],
|
|
41
|
-
builderConfig: {
|
|
42
|
-
server: {
|
|
43
|
-
open: true,
|
|
44
73
|
},
|
|
45
|
-
}
|
|
74
|
+
};
|
|
46
75
|
};
|
|
47
76
|
const findConfig = (basePath) => {
|
|
48
77
|
return DEFAULT_EXTENSIONS.map((ext) => basePath + ext).find(fs.existsSync);
|
|
@@ -64,36 +93,53 @@ export async function loadConfig(root, configFile) {
|
|
|
64
93
|
configFilePath = findConfig(path.resolve('docs', DEFAULT_CONFIG_NAME));
|
|
65
94
|
}
|
|
66
95
|
}
|
|
96
|
+
let config;
|
|
97
|
+
const { loadConfig, mergeRsbuildConfig } = await import('@rsbuild/core');
|
|
67
98
|
if (!configFilePath) {
|
|
68
99
|
logger.info(`No doom config file found in ${process.cwd()}`);
|
|
69
|
-
return {
|
|
70
|
-
config: {},
|
|
71
|
-
};
|
|
72
100
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
101
|
+
else {
|
|
102
|
+
try {
|
|
103
|
+
if (YAML_EXTENSIONS.includes(path.extname(configFilePath))) {
|
|
104
|
+
config = parse(fs.readFileSync(configFilePath, 'utf-8'));
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
const { content } = await loadConfig({
|
|
108
|
+
cwd: path.dirname(configFilePath),
|
|
109
|
+
path: configFilePath,
|
|
110
|
+
});
|
|
111
|
+
config = content;
|
|
112
|
+
}
|
|
78
113
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
cwd: path.dirname(configFilePath),
|
|
82
|
-
path: configFilePath,
|
|
83
|
-
});
|
|
84
|
-
config = content;
|
|
114
|
+
catch {
|
|
115
|
+
logger.error(`Failed to load config from ${configFilePath}`);
|
|
85
116
|
}
|
|
86
117
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}
|
|
90
|
-
const mergedConfig = mergeRsbuildConfig(COMMON_CONFIG, config ?? {});
|
|
118
|
+
config ??= {};
|
|
119
|
+
const mergedConfig = mergeRsbuildConfig(getCommonConfig(config), config);
|
|
91
120
|
const base = addLeadingSlash(mergedConfig.base || '/');
|
|
92
121
|
mergedConfig.base = base;
|
|
93
122
|
mergedConfig.root = resolveDocRoot(CWD, root, mergedConfig.root);
|
|
123
|
+
let ensureDefaultLogo = false;
|
|
124
|
+
if (!mergedConfig.logo) {
|
|
125
|
+
mergedConfig.logo = DEFAULT_LOGO;
|
|
126
|
+
ensureDefaultLogo = true;
|
|
127
|
+
}
|
|
128
|
+
if (!mergedConfig.icon) {
|
|
129
|
+
mergedConfig.icon = DEFAULT_LOGO;
|
|
130
|
+
ensureDefaultLogo = true;
|
|
131
|
+
}
|
|
132
|
+
if (ensureDefaultLogo) {
|
|
133
|
+
const publicPath = path.resolve(mergedConfig.root, `public`);
|
|
134
|
+
fs.mkdirSync(publicPath, { recursive: true });
|
|
135
|
+
const logoPath = path.resolve(publicPath, removeLeadingSlash(DEFAULT_LOGO));
|
|
136
|
+
if (!fs.existsSync(logoPath)) {
|
|
137
|
+
fs.copyFileSync(pkgResolve(`assets${DEFAULT_LOGO}`), logoPath);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
94
140
|
if (mergedConfig.i18nSourcePath) {
|
|
95
141
|
if (!path.isAbsolute(mergedConfig.i18nSourcePath)) {
|
|
96
|
-
mergedConfig.i18nSourcePath = path.resolve(configFilePath, mergedConfig.i18nSourcePath);
|
|
142
|
+
mergedConfig.i18nSourcePath = path.resolve(configFilePath ?? mergedConfig.root, mergedConfig.i18nSourcePath);
|
|
97
143
|
}
|
|
98
144
|
}
|
|
99
145
|
else {
|
|
@@ -102,7 +148,7 @@ export async function loadConfig(root, configFile) {
|
|
|
102
148
|
if (!mergedConfig.outDir) {
|
|
103
149
|
mergedConfig.outDir = `dist${base}`;
|
|
104
150
|
}
|
|
105
|
-
if (mergedConfig.builderConfig?.server?.open) {
|
|
151
|
+
if (mergedConfig.builderConfig?.server?.open === true) {
|
|
106
152
|
mergedConfig.builderConfig.server.open = addTrailingSlash(base);
|
|
107
153
|
}
|
|
108
154
|
return {
|
|
@@ -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 {};
|
|
@@ -181,7 +181,9 @@ export async function walk(workDir, routePrefix = '/', docsDir, extensions) {
|
|
|
181
181
|
}
|
|
182
182
|
});
|
|
183
183
|
// find the `_meta.json` file in the subdirectory
|
|
184
|
-
const subDirs = (await fs.readdir(workDir)).filter((v) => fs.statSync(path.join(workDir, v)).isDirectory() &&
|
|
184
|
+
const subDirs = (await fs.readdir(workDir)).filter((v) => fs.statSync(path.join(workDir, v)).isDirectory() &&
|
|
185
|
+
v !== 'node_modules' &&
|
|
186
|
+
(workDir !== docsDir || !['public', 'shared'].includes(v)));
|
|
185
187
|
const sidebars = [];
|
|
186
188
|
// Every sub dir will represent a group of sidebar
|
|
187
189
|
const sidebarConfig = {
|
|
@@ -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,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, className: "rspress-plugin-api-docgen", 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
|
+
};
|
package/lib/runtime/index.d.ts
CHANGED
package/lib/runtime/index.js
CHANGED
|
@@ -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,14 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alauda/doom",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Doctor Doom making docs.",
|
|
6
|
-
"repository":
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://gitlab-ce.alauda.cn/idp/Doom.git"
|
|
9
|
+
},
|
|
7
10
|
"packageManager": "yarn@4.5.0",
|
|
8
11
|
"engines": {
|
|
9
|
-
"node": ">=18.
|
|
12
|
+
"node": ">=18.17.0 <20 || >=20.1.0"
|
|
10
13
|
},
|
|
11
|
-
"bin": "
|
|
14
|
+
"bin": "lib/cli/index.js",
|
|
12
15
|
"exports": {
|
|
13
16
|
"./package.json": "./package.json",
|
|
14
17
|
"./runtime": "./lib/runtime/index.js"
|
|
@@ -33,28 +36,37 @@
|
|
|
33
36
|
"swc-node": "node --enable-source-maps --import @swc-node/register/esm-register"
|
|
34
37
|
},
|
|
35
38
|
"dependencies": {
|
|
36
|
-
"@
|
|
39
|
+
"@openapi-contrib/openapi-schema-to-json-schema": "^5.1.0",
|
|
40
|
+
"@rspress/core": "^1.37.4",
|
|
41
|
+
"@rspress/plugin-preview": "^1.37.4",
|
|
37
42
|
"chokidar": "^4.0.1",
|
|
38
43
|
"commander": "^12.1.0",
|
|
44
|
+
"es-toolkit": "^1.29.0",
|
|
45
|
+
"react-markdown": "^8.0.7",
|
|
39
46
|
"rehype-raw": "^6.1.1",
|
|
40
|
-
"
|
|
47
|
+
"remark-gfm": "^3.0.1",
|
|
48
|
+
"swagger2openapi": "^7.0.8",
|
|
49
|
+
"tinyglobby": "^0.2.10",
|
|
50
|
+
"yaml": "^2.6.1",
|
|
41
51
|
"yoctocolors": "^2.1.1"
|
|
42
52
|
},
|
|
43
53
|
"devDependencies": {
|
|
44
|
-
"@eslint/js": "^9.
|
|
54
|
+
"@eslint/js": "^9.16.0",
|
|
45
55
|
"@swc-node/register": "^1.10.9",
|
|
46
|
-
"@swc/core": "1.
|
|
56
|
+
"@swc/core": "1.10.1",
|
|
47
57
|
"@types/eslint__js": "^8.42.3",
|
|
48
58
|
"@types/fs-extra": "^11.0.4",
|
|
49
|
-
"@types/node": "~18.
|
|
50
|
-
"
|
|
59
|
+
"@types/node": "~18.17.19",
|
|
60
|
+
"@types/swagger2openapi": "^7.0.4",
|
|
61
|
+
"eslint": "^9.16.0",
|
|
51
62
|
"lint-staged": "^15.2.10",
|
|
52
63
|
"npm-run-all2": "^7.0.1",
|
|
53
|
-
"
|
|
64
|
+
"openapi-types": "^12.1.3",
|
|
65
|
+
"prettier": "^3.4.2",
|
|
54
66
|
"prettier-plugin-pkg": "^0.18.1",
|
|
55
67
|
"simple-git-hooks": "^2.11.1",
|
|
56
|
-
"typescript": "^5.
|
|
57
|
-
"typescript-eslint": "^8.
|
|
68
|
+
"typescript": "^5.7.2",
|
|
69
|
+
"typescript-eslint": "^8.18.0"
|
|
58
70
|
},
|
|
59
71
|
"publishConfig": {
|
|
60
72
|
"access": "public"
|