@easydocs/dashboard 0.4.2 → 0.5.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/package.json +2 -2
- package/src/components/SpecEditor.tsx +1 -1
- package/src/lib/db.ts +2 -42
- package/src/lib/operation-schema.ts +0 -44
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@easydocs/dashboard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "EasyDocs docs dashboard — view and export AI-generated OpenAPI specs",
|
|
5
5
|
"files": [
|
|
6
6
|
"src",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"react": "^19.0.0",
|
|
20
20
|
"react-dom": "^19.0.0",
|
|
21
21
|
"zod": "^3.25.76",
|
|
22
|
-
"@easydocs/core": "0.
|
|
22
|
+
"@easydocs/core": "0.5.0"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/js-yaml": "^4.0.9",
|
|
@@ -6,7 +6,7 @@ import { json } from '@codemirror/lang-json'
|
|
|
6
6
|
import { oneDark } from '@codemirror/theme-one-dark'
|
|
7
7
|
import type { Endpoint } from '@easydocs/core/schema'
|
|
8
8
|
import type { Operation } from '@easydocs/core'
|
|
9
|
-
import { OperationSchema } from '
|
|
9
|
+
import { OperationSchema } from '@easydocs/core'
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
endpoint: Endpoint
|
package/src/lib/db.ts
CHANGED
|
@@ -4,7 +4,9 @@ import {
|
|
|
4
4
|
getEndpointsByProject,
|
|
5
5
|
getAllProjects,
|
|
6
6
|
findOrCreateProject,
|
|
7
|
+
buildFullSpec,
|
|
7
8
|
} from '@easydocs/core'
|
|
9
|
+
export { buildFullSpec }
|
|
8
10
|
import type { Endpoint, Project } from '@easydocs/core/schema'
|
|
9
11
|
|
|
10
12
|
let db: ReturnType<typeof createDB> | null = null
|
|
@@ -24,45 +26,3 @@ export async function fetchEndpoints(projectSlug?: string): Promise<Endpoint[]>
|
|
|
24
26
|
const projectId = await findOrCreateProject(db, projectSlug)
|
|
25
27
|
return getEndpointsByProject(db, projectId)
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
const SECURITY_SCHEME_DEFS: Record<string, unknown> = {
|
|
29
|
-
bearerAuth: { type: 'http', scheme: 'bearer', bearerFormat: 'JWT' },
|
|
30
|
-
basicAuth: { type: 'http', scheme: 'basic' },
|
|
31
|
-
apiKeyHeader: { type: 'apiKey', in: 'header', name: 'X-API-Key' },
|
|
32
|
-
apiKeyQuery: { type: 'apiKey', in: 'query', name: 'api_key' },
|
|
33
|
-
cookieAuth: { type: 'apiKey', in: 'cookie', name: 'session' },
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function buildFullSpec(endpointList: Endpoint[], projectName?: string) {
|
|
37
|
-
const usedSchemes = new Set<string>()
|
|
38
|
-
const paths: Record<string, Record<string, unknown>> = {}
|
|
39
|
-
|
|
40
|
-
for (const e of endpointList) {
|
|
41
|
-
if (!e.path || !e.method) continue
|
|
42
|
-
const activeSpec = e.isManuallyEdited && e.manualSpec ? e.manualSpec : e.spec
|
|
43
|
-
if (!activeSpec) continue
|
|
44
|
-
|
|
45
|
-
if (!paths[e.path]) paths[e.path] = {}
|
|
46
|
-
paths[e.path][e.method.toLowerCase()] = activeSpec
|
|
47
|
-
|
|
48
|
-
if (activeSpec.security) {
|
|
49
|
-
for (const entry of activeSpec.security) {
|
|
50
|
-
for (const name of Object.keys(entry)) {
|
|
51
|
-
if (SECURITY_SCHEME_DEFS[name]) usedSchemes.add(name)
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const securitySchemes =
|
|
58
|
-
usedSchemes.size > 0
|
|
59
|
-
? Object.fromEntries([...usedSchemes].map((n) => [n, SECURITY_SCHEME_DEFS[n]]))
|
|
60
|
-
: undefined
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
openapi: '3.0.3',
|
|
64
|
-
info: { title: projectName ?? 'API Documentation', version: '1.0.0' },
|
|
65
|
-
paths,
|
|
66
|
-
...(securitySchemes ? { components: { securitySchemes } } : {}),
|
|
67
|
-
}
|
|
68
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod'
|
|
2
|
-
|
|
3
|
-
const SchemaObject = z.record(z.any()).optional()
|
|
4
|
-
|
|
5
|
-
const MediaTypeSchema = z.object({
|
|
6
|
-
schema: SchemaObject,
|
|
7
|
-
example: z.any().optional(),
|
|
8
|
-
examples: z.record(z.any()).optional(),
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
const ParameterSchema = z.object({
|
|
12
|
-
name: z.string(),
|
|
13
|
-
in: z.enum(['query', 'header', 'path', 'cookie']),
|
|
14
|
-
description: z.string().optional(),
|
|
15
|
-
required: z.boolean().default(false),
|
|
16
|
-
deprecated: z.boolean().optional(),
|
|
17
|
-
schema: SchemaObject,
|
|
18
|
-
example: z.any().optional(),
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
const ResponseSchema = z.object({
|
|
22
|
-
description: z.string(),
|
|
23
|
-
headers: z.record(z.any()).optional(),
|
|
24
|
-
content: z.record(MediaTypeSchema).optional(),
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
export const OperationSchema = z.object({
|
|
28
|
-
tags: z.array(z.string()).optional(),
|
|
29
|
-
summary: z.string().optional(),
|
|
30
|
-
description: z.string().optional(),
|
|
31
|
-
operationId: z.string().optional(),
|
|
32
|
-
parameters: z.array(ParameterSchema).optional(),
|
|
33
|
-
requestBody: z
|
|
34
|
-
.object({
|
|
35
|
-
description: z.string().optional(),
|
|
36
|
-
required: z.boolean().optional(),
|
|
37
|
-
content: z.record(MediaTypeSchema),
|
|
38
|
-
})
|
|
39
|
-
.nullable()
|
|
40
|
-
.optional(),
|
|
41
|
-
responses: z.record(ResponseSchema).default({}),
|
|
42
|
-
deprecated: z.boolean().optional(),
|
|
43
|
-
security: z.array(z.record(z.array(z.string()))).optional(),
|
|
44
|
-
})
|