silgi 0.0.14 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -2
- package/dist/chunks/generate.mjs +1118 -844
- package/dist/cli/config.d.mts +1630 -16
- package/dist/cli/config.d.ts +1630 -16
- package/dist/cli/index.mjs +50 -40
- package/dist/ecosystem/nitro/module.d.mts +10 -0
- package/dist/ecosystem/nitro/module.d.ts +10 -0
- package/dist/ecosystem/nitro/module.mjs +65 -0
- package/dist/ecosystem/nitro/runtime/plugin.d.ts +3 -0
- package/dist/ecosystem/nitro/runtime/plugin.mjs +2 -0
- package/dist/index.d.mts +147 -29
- package/dist/index.d.ts +147 -29
- package/dist/index.mjs +464 -6
- package/dist/shared/silgi.BaeZYxPa.d.mts +871 -0
- package/dist/shared/silgi.BaeZYxPa.d.ts +871 -0
- package/dist/shared/silgi.CbXGs1ur.mjs +317 -0
- package/dist/shared/silgi.KTm2r-Fb.mjs +25 -0
- package/dist/shared/silgi.wK7ZsagJ.mjs +484 -0
- package/package.json +48 -39
- package/dist/plugins/openapi.d.mts +0 -138
- package/dist/plugins/openapi.d.ts +0 -138
- package/dist/plugins/openapi.mjs +0 -204
- package/dist/plugins/scalar.d.mts +0 -14
- package/dist/plugins/scalar.d.ts +0 -14
- package/dist/plugins/scalar.mjs +0 -66
- package/dist/shared/silgi.BMCYk2cR.mjs +0 -841
- package/dist/shared/silgi.D5qK9QOm.d.mts +0 -301
- package/dist/shared/silgi.D5qK9QOm.d.ts +0 -301
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
|
-
import { SchemaObject, ServerObject, OpenAPIObject } from 'openapi3-ts/oas31';
|
|
3
|
-
import { P as PergelPlugin, D as DefaultContext, a as DefaultInterface, I as InitSilgi } from '../shared/silgi.D5qK9QOm.mjs';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import 'consola';
|
|
6
|
-
import 'h3';
|
|
7
|
-
import 'hookable';
|
|
8
|
-
|
|
9
|
-
interface DefaultSilgiPlugin {
|
|
10
|
-
openapi?: {
|
|
11
|
-
schema?: {
|
|
12
|
-
input?: SchemaObject;
|
|
13
|
-
output?: SchemaObject;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
declare module 'silgi' {
|
|
18
|
-
interface DefaultInterface {
|
|
19
|
-
plugins: DefaultSilgiPlugin;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
interface OpenAPIPluginConfig {
|
|
23
|
-
title?: string;
|
|
24
|
-
version?: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
servers?: ServerObject[];
|
|
27
|
-
writeToFile?: boolean;
|
|
28
|
-
outputPath?: string;
|
|
29
|
-
}
|
|
30
|
-
declare const createOpenAPIPlugin: (options?: OpenAPIPluginConfig | undefined) => PergelPlugin<DefaultContext, DefaultInterface, OpenAPIPluginConfig>;
|
|
31
|
-
declare function createSchema(schema: {
|
|
32
|
-
input?: Partial<SchemaObject>;
|
|
33
|
-
output?: Partial<SchemaObject>;
|
|
34
|
-
}): {
|
|
35
|
-
input: {
|
|
36
|
-
discriminator?: openapi3_ts_oas31.DiscriminatorObject;
|
|
37
|
-
readOnly?: boolean;
|
|
38
|
-
writeOnly?: boolean;
|
|
39
|
-
xml?: openapi3_ts_oas31.XmlObject;
|
|
40
|
-
externalDocs?: openapi3_ts_oas31.ExternalDocumentationObject;
|
|
41
|
-
example?: any;
|
|
42
|
-
examples?: any[];
|
|
43
|
-
deprecated?: boolean;
|
|
44
|
-
type: string | openapi3_ts_oas31.SchemaObjectType[];
|
|
45
|
-
format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
|
|
46
|
-
allOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
47
|
-
oneOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
48
|
-
anyOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
49
|
-
not?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
50
|
-
items?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
51
|
-
properties?: {
|
|
52
|
-
[propertyName: string]: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
53
|
-
};
|
|
54
|
-
additionalProperties?: SchemaObject | openapi3_ts_oas31.ReferenceObject | boolean;
|
|
55
|
-
propertyNames?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
56
|
-
description?: string;
|
|
57
|
-
default?: any;
|
|
58
|
-
title?: string;
|
|
59
|
-
multipleOf?: number;
|
|
60
|
-
maximum?: number;
|
|
61
|
-
const?: any;
|
|
62
|
-
exclusiveMaximum?: number;
|
|
63
|
-
minimum?: number;
|
|
64
|
-
exclusiveMinimum?: number;
|
|
65
|
-
maxLength?: number;
|
|
66
|
-
minLength?: number;
|
|
67
|
-
pattern?: string;
|
|
68
|
-
maxItems?: number;
|
|
69
|
-
minItems?: number;
|
|
70
|
-
uniqueItems?: boolean;
|
|
71
|
-
maxProperties?: number;
|
|
72
|
-
minProperties?: number;
|
|
73
|
-
required?: string[];
|
|
74
|
-
enum?: any[];
|
|
75
|
-
prefixItems?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
76
|
-
contentMediaType?: string;
|
|
77
|
-
contentEncoding?: string;
|
|
78
|
-
};
|
|
79
|
-
output: {
|
|
80
|
-
discriminator?: openapi3_ts_oas31.DiscriminatorObject;
|
|
81
|
-
readOnly?: boolean;
|
|
82
|
-
writeOnly?: boolean;
|
|
83
|
-
xml?: openapi3_ts_oas31.XmlObject;
|
|
84
|
-
externalDocs?: openapi3_ts_oas31.ExternalDocumentationObject;
|
|
85
|
-
example?: any;
|
|
86
|
-
examples?: any[];
|
|
87
|
-
deprecated?: boolean;
|
|
88
|
-
type: string | openapi3_ts_oas31.SchemaObjectType[];
|
|
89
|
-
format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
|
|
90
|
-
allOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
91
|
-
oneOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
92
|
-
anyOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
93
|
-
not?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
94
|
-
items?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
95
|
-
properties?: {
|
|
96
|
-
[propertyName: string]: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
97
|
-
};
|
|
98
|
-
additionalProperties?: SchemaObject | openapi3_ts_oas31.ReferenceObject | boolean;
|
|
99
|
-
propertyNames?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
100
|
-
description?: string;
|
|
101
|
-
default?: any;
|
|
102
|
-
title?: string;
|
|
103
|
-
multipleOf?: number;
|
|
104
|
-
maximum?: number;
|
|
105
|
-
const?: any;
|
|
106
|
-
exclusiveMaximum?: number;
|
|
107
|
-
minimum?: number;
|
|
108
|
-
exclusiveMinimum?: number;
|
|
109
|
-
maxLength?: number;
|
|
110
|
-
minLength?: number;
|
|
111
|
-
pattern?: string;
|
|
112
|
-
maxItems?: number;
|
|
113
|
-
minItems?: number;
|
|
114
|
-
uniqueItems?: boolean;
|
|
115
|
-
maxProperties?: number;
|
|
116
|
-
minProperties?: number;
|
|
117
|
-
required?: string[];
|
|
118
|
-
enum?: any[];
|
|
119
|
-
prefixItems?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
120
|
-
contentMediaType?: string;
|
|
121
|
-
contentEncoding?: string;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
declare function createSchemaFromZod(schema: {
|
|
125
|
-
input?: z.ZodType<any>;
|
|
126
|
-
output?: z.ZodType<any>;
|
|
127
|
-
}): {
|
|
128
|
-
input: SchemaObject | {
|
|
129
|
-
type: string;
|
|
130
|
-
};
|
|
131
|
-
output: SchemaObject | {
|
|
132
|
-
type: string;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
declare function getOpenAPIDocument(initSilgi: InitSilgi<any, any>): OpenAPIObject;
|
|
136
|
-
declare function getOpenAPIPath(initSilgi: InitSilgi<any, any>): string | undefined;
|
|
137
|
-
|
|
138
|
-
export { type DefaultSilgiPlugin, type OpenAPIPluginConfig, createOpenAPIPlugin, createSchema, createSchemaFromZod, getOpenAPIDocument, getOpenAPIPath };
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import * as openapi3_ts_oas31 from 'openapi3-ts/oas31';
|
|
2
|
-
import { SchemaObject, ServerObject, OpenAPIObject } from 'openapi3-ts/oas31';
|
|
3
|
-
import { P as PergelPlugin, D as DefaultContext, a as DefaultInterface, I as InitSilgi } from '../shared/silgi.D5qK9QOm.js';
|
|
4
|
-
import { z } from 'zod';
|
|
5
|
-
import 'consola';
|
|
6
|
-
import 'h3';
|
|
7
|
-
import 'hookable';
|
|
8
|
-
|
|
9
|
-
interface DefaultSilgiPlugin {
|
|
10
|
-
openapi?: {
|
|
11
|
-
schema?: {
|
|
12
|
-
input?: SchemaObject;
|
|
13
|
-
output?: SchemaObject;
|
|
14
|
-
};
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
declare module 'silgi' {
|
|
18
|
-
interface DefaultInterface {
|
|
19
|
-
plugins: DefaultSilgiPlugin;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
interface OpenAPIPluginConfig {
|
|
23
|
-
title?: string;
|
|
24
|
-
version?: string;
|
|
25
|
-
description?: string;
|
|
26
|
-
servers?: ServerObject[];
|
|
27
|
-
writeToFile?: boolean;
|
|
28
|
-
outputPath?: string;
|
|
29
|
-
}
|
|
30
|
-
declare const createOpenAPIPlugin: (options?: OpenAPIPluginConfig | undefined) => PergelPlugin<DefaultContext, DefaultInterface, OpenAPIPluginConfig>;
|
|
31
|
-
declare function createSchema(schema: {
|
|
32
|
-
input?: Partial<SchemaObject>;
|
|
33
|
-
output?: Partial<SchemaObject>;
|
|
34
|
-
}): {
|
|
35
|
-
input: {
|
|
36
|
-
discriminator?: openapi3_ts_oas31.DiscriminatorObject;
|
|
37
|
-
readOnly?: boolean;
|
|
38
|
-
writeOnly?: boolean;
|
|
39
|
-
xml?: openapi3_ts_oas31.XmlObject;
|
|
40
|
-
externalDocs?: openapi3_ts_oas31.ExternalDocumentationObject;
|
|
41
|
-
example?: any;
|
|
42
|
-
examples?: any[];
|
|
43
|
-
deprecated?: boolean;
|
|
44
|
-
type: string | openapi3_ts_oas31.SchemaObjectType[];
|
|
45
|
-
format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
|
|
46
|
-
allOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
47
|
-
oneOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
48
|
-
anyOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
49
|
-
not?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
50
|
-
items?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
51
|
-
properties?: {
|
|
52
|
-
[propertyName: string]: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
53
|
-
};
|
|
54
|
-
additionalProperties?: SchemaObject | openapi3_ts_oas31.ReferenceObject | boolean;
|
|
55
|
-
propertyNames?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
56
|
-
description?: string;
|
|
57
|
-
default?: any;
|
|
58
|
-
title?: string;
|
|
59
|
-
multipleOf?: number;
|
|
60
|
-
maximum?: number;
|
|
61
|
-
const?: any;
|
|
62
|
-
exclusiveMaximum?: number;
|
|
63
|
-
minimum?: number;
|
|
64
|
-
exclusiveMinimum?: number;
|
|
65
|
-
maxLength?: number;
|
|
66
|
-
minLength?: number;
|
|
67
|
-
pattern?: string;
|
|
68
|
-
maxItems?: number;
|
|
69
|
-
minItems?: number;
|
|
70
|
-
uniqueItems?: boolean;
|
|
71
|
-
maxProperties?: number;
|
|
72
|
-
minProperties?: number;
|
|
73
|
-
required?: string[];
|
|
74
|
-
enum?: any[];
|
|
75
|
-
prefixItems?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
76
|
-
contentMediaType?: string;
|
|
77
|
-
contentEncoding?: string;
|
|
78
|
-
};
|
|
79
|
-
output: {
|
|
80
|
-
discriminator?: openapi3_ts_oas31.DiscriminatorObject;
|
|
81
|
-
readOnly?: boolean;
|
|
82
|
-
writeOnly?: boolean;
|
|
83
|
-
xml?: openapi3_ts_oas31.XmlObject;
|
|
84
|
-
externalDocs?: openapi3_ts_oas31.ExternalDocumentationObject;
|
|
85
|
-
example?: any;
|
|
86
|
-
examples?: any[];
|
|
87
|
-
deprecated?: boolean;
|
|
88
|
-
type: string | openapi3_ts_oas31.SchemaObjectType[];
|
|
89
|
-
format?: "int32" | "int64" | "float" | "double" | "byte" | "binary" | "date" | "date-time" | "password" | string;
|
|
90
|
-
allOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
91
|
-
oneOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
92
|
-
anyOf?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
93
|
-
not?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
94
|
-
items?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
95
|
-
properties?: {
|
|
96
|
-
[propertyName: string]: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
97
|
-
};
|
|
98
|
-
additionalProperties?: SchemaObject | openapi3_ts_oas31.ReferenceObject | boolean;
|
|
99
|
-
propertyNames?: SchemaObject | openapi3_ts_oas31.ReferenceObject;
|
|
100
|
-
description?: string;
|
|
101
|
-
default?: any;
|
|
102
|
-
title?: string;
|
|
103
|
-
multipleOf?: number;
|
|
104
|
-
maximum?: number;
|
|
105
|
-
const?: any;
|
|
106
|
-
exclusiveMaximum?: number;
|
|
107
|
-
minimum?: number;
|
|
108
|
-
exclusiveMinimum?: number;
|
|
109
|
-
maxLength?: number;
|
|
110
|
-
minLength?: number;
|
|
111
|
-
pattern?: string;
|
|
112
|
-
maxItems?: number;
|
|
113
|
-
minItems?: number;
|
|
114
|
-
uniqueItems?: boolean;
|
|
115
|
-
maxProperties?: number;
|
|
116
|
-
minProperties?: number;
|
|
117
|
-
required?: string[];
|
|
118
|
-
enum?: any[];
|
|
119
|
-
prefixItems?: (SchemaObject | openapi3_ts_oas31.ReferenceObject)[];
|
|
120
|
-
contentMediaType?: string;
|
|
121
|
-
contentEncoding?: string;
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
declare function createSchemaFromZod(schema: {
|
|
125
|
-
input?: z.ZodType<any>;
|
|
126
|
-
output?: z.ZodType<any>;
|
|
127
|
-
}): {
|
|
128
|
-
input: SchemaObject | {
|
|
129
|
-
type: string;
|
|
130
|
-
};
|
|
131
|
-
output: SchemaObject | {
|
|
132
|
-
type: string;
|
|
133
|
-
};
|
|
134
|
-
};
|
|
135
|
-
declare function getOpenAPIDocument(initSilgi: InitSilgi<any, any>): OpenAPIObject;
|
|
136
|
-
declare function getOpenAPIPath(initSilgi: InitSilgi<any, any>): string | undefined;
|
|
137
|
-
|
|
138
|
-
export { type DefaultSilgiPlugin, type OpenAPIPluginConfig, createOpenAPIPlugin, createSchema, createSchemaFromZod, getOpenAPIDocument, getOpenAPIPath };
|
package/dist/plugins/openapi.mjs
DELETED
|
@@ -1,204 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { generateSchema } from '@anatine/zod-openapi';
|
|
4
|
-
import consola from 'consola';
|
|
5
|
-
import { a as defineSilgiPlugin } from '../shared/silgi.BMCYk2cR.mjs';
|
|
6
|
-
import 'hookable';
|
|
7
|
-
import 'node:buffer';
|
|
8
|
-
import 'node:fs';
|
|
9
|
-
import 'unctx';
|
|
10
|
-
|
|
11
|
-
function parseMethodName(methodName) {
|
|
12
|
-
const [method, ...pathParts] = methodName.split(":");
|
|
13
|
-
const path = pathParts.join(":");
|
|
14
|
-
return !path || !isHttpMethod(method) ? { method: "post", path: methodName } : { method, path };
|
|
15
|
-
}
|
|
16
|
-
function isHttpMethod(method) {
|
|
17
|
-
return ["get", "post", "put", "delete", "patch"].includes(method.toLowerCase());
|
|
18
|
-
}
|
|
19
|
-
const createOpenAPIPlugin = defineSilgiPlugin({
|
|
20
|
-
name: "openapi",
|
|
21
|
-
async setup(config, initSilgi) {
|
|
22
|
-
const document = {
|
|
23
|
-
openapi: "3.1",
|
|
24
|
-
info: {
|
|
25
|
-
title: config.title || "API Documentation",
|
|
26
|
-
version: config.version || "1.0.0",
|
|
27
|
-
description: config.description || ""
|
|
28
|
-
},
|
|
29
|
-
servers: config.servers || [{
|
|
30
|
-
url: "/",
|
|
31
|
-
description: "Default Server",
|
|
32
|
-
// Required by ServerObject
|
|
33
|
-
variables: {}
|
|
34
|
-
// Required by ServerObject
|
|
35
|
-
}],
|
|
36
|
-
paths: {},
|
|
37
|
-
components: {
|
|
38
|
-
schemas: {
|
|
39
|
-
Success: {
|
|
40
|
-
description: "Success response",
|
|
41
|
-
type: "object",
|
|
42
|
-
required: ["success"],
|
|
43
|
-
properties: {
|
|
44
|
-
success: { type: "boolean", enum: [true] },
|
|
45
|
-
data: { type: "object" }
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
Error: {
|
|
49
|
-
description: "Error response",
|
|
50
|
-
type: "object",
|
|
51
|
-
required: ["success", "error"],
|
|
52
|
-
properties: {
|
|
53
|
-
success: { type: "boolean", enum: [false] },
|
|
54
|
-
error: {
|
|
55
|
-
type: "object",
|
|
56
|
-
properties: {
|
|
57
|
-
code: { type: "string" },
|
|
58
|
-
message: { type: "string" }
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
const paths = {};
|
|
67
|
-
const services = initSilgi.getAllServices();
|
|
68
|
-
for (const [scopeName, scope] of Object.entries(services)) {
|
|
69
|
-
for (const serviceName of scope.services) {
|
|
70
|
-
const service = initSilgi.getService(scopeName, serviceName);
|
|
71
|
-
for (const [methodName, handler] of service.handlers.entries()) {
|
|
72
|
-
let schema = handler.options?.plugins?.openapi?.schema;
|
|
73
|
-
const sharedZod = initSilgi.silgi.options.shared[scopeName]?.zod;
|
|
74
|
-
if (!schema && sharedZod) {
|
|
75
|
-
try {
|
|
76
|
-
schema = createSchemaFromZod(sharedZod[serviceName][methodName]);
|
|
77
|
-
} catch {
|
|
78
|
-
if (!schema?.input || !schema?.output) {
|
|
79
|
-
consola.withTag("silgi:openapi").info("Please add schema for", scopeName, serviceName, methodName);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const { method, path } = parseMethodName(String(methodName));
|
|
84
|
-
const route = `/${scopeName}/${serviceName}/${path}`;
|
|
85
|
-
const operation = {
|
|
86
|
-
tags: [scopeName, serviceName],
|
|
87
|
-
summary: String(methodName).split(":")[1] || String(methodName),
|
|
88
|
-
description: String(`Handle copy: defineService().scope('${scopeName}').service('${serviceName}').methods({ '${String(methodName)}': { ... } })`),
|
|
89
|
-
parameters: (() => {
|
|
90
|
-
switch (method) {
|
|
91
|
-
case "get":
|
|
92
|
-
if (!schema?.input)
|
|
93
|
-
return [];
|
|
94
|
-
return Object.entries(schema.input.properties || {}).map(([paramName, paramSchema]) => ({
|
|
95
|
-
in: "query",
|
|
96
|
-
name: paramName,
|
|
97
|
-
required: schema.input?.required?.includes(paramName) || false,
|
|
98
|
-
schema: paramSchema,
|
|
99
|
-
description: paramSchema.description || undefined,
|
|
100
|
-
$ref: paramSchema.$ref || undefined
|
|
101
|
-
}));
|
|
102
|
-
case "delete":
|
|
103
|
-
return [{
|
|
104
|
-
in: "path",
|
|
105
|
-
name: "id",
|
|
106
|
-
required: true,
|
|
107
|
-
schema: { type: "string" }
|
|
108
|
-
}];
|
|
109
|
-
case "put":
|
|
110
|
-
case "patch":
|
|
111
|
-
return [{
|
|
112
|
-
in: "path",
|
|
113
|
-
name: "id",
|
|
114
|
-
required: true,
|
|
115
|
-
schema: { type: "string" }
|
|
116
|
-
}];
|
|
117
|
-
default:
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
})(),
|
|
121
|
-
...method !== "get" && method !== "delete" ? {
|
|
122
|
-
requestBody: {
|
|
123
|
-
required: true,
|
|
124
|
-
content: {
|
|
125
|
-
"application/json": {
|
|
126
|
-
schema: schema?.input || { type: "object" }
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
} : {},
|
|
131
|
-
responses: {
|
|
132
|
-
200: {
|
|
133
|
-
description: "Successful operation",
|
|
134
|
-
content: {
|
|
135
|
-
"application/json": {
|
|
136
|
-
schema: {
|
|
137
|
-
type: "object",
|
|
138
|
-
required: ["success"],
|
|
139
|
-
properties: {
|
|
140
|
-
success: { type: "boolean", enum: [true] },
|
|
141
|
-
data: schema?.output || { type: "object" }
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
400: {
|
|
148
|
-
description: "Operation failed",
|
|
149
|
-
content: {
|
|
150
|
-
"application/json": {
|
|
151
|
-
schema: { $ref: "#/components/schemas/Error" }
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
};
|
|
157
|
-
paths[route] = {
|
|
158
|
-
...paths[route],
|
|
159
|
-
[method]: operation
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
document.paths = paths;
|
|
165
|
-
initSilgi.setEvent("openapi", document);
|
|
166
|
-
if (config.writeToFile) {
|
|
167
|
-
try {
|
|
168
|
-
const silgiDir = join(process.cwd(), ".silgi");
|
|
169
|
-
await mkdir(silgiDir, { recursive: true });
|
|
170
|
-
const outputJSON = join(silgiDir, "openapi.json");
|
|
171
|
-
await writeFile(outputJSON, JSON.stringify(document, null, 2), "utf-8");
|
|
172
|
-
} catch (error) {
|
|
173
|
-
initSilgi.silgi.logger.error("Failed to generate OpenAPI documentation:", error);
|
|
174
|
-
throw error;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
});
|
|
179
|
-
function createSchema(schema) {
|
|
180
|
-
return {
|
|
181
|
-
input: {
|
|
182
|
-
type: "object",
|
|
183
|
-
...schema.input
|
|
184
|
-
},
|
|
185
|
-
output: {
|
|
186
|
-
type: "object",
|
|
187
|
-
...schema.output
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
function createSchemaFromZod(schema) {
|
|
192
|
-
return {
|
|
193
|
-
input: schema.input ? generateSchema(schema.input) : { type: "object" },
|
|
194
|
-
output: schema.output ? generateSchema(schema.output) : { type: "object" }
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
function getOpenAPIDocument(initSilgi) {
|
|
198
|
-
return initSilgi.getEvent("openapi:document");
|
|
199
|
-
}
|
|
200
|
-
function getOpenAPIPath(initSilgi) {
|
|
201
|
-
return initSilgi.getEvent("openapi:path");
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export { createOpenAPIPlugin, createSchema, createSchemaFromZod, getOpenAPIDocument, getOpenAPIPath };
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { P as PergelPlugin, D as DefaultContext, a as DefaultInterface } from '../shared/silgi.D5qK9QOm.mjs';
|
|
2
|
-
import 'consola';
|
|
3
|
-
import 'h3';
|
|
4
|
-
import 'zod';
|
|
5
|
-
import 'hookable';
|
|
6
|
-
|
|
7
|
-
interface SilgiPluginConfig {
|
|
8
|
-
writeToFile?: boolean;
|
|
9
|
-
theme?: 'alternate' | 'default' | 'moon' | 'purple' | 'solarized' | 'bluePlanet' | 'saturn' | 'kepler' | 'mars' | 'deepSpace' | 'none';
|
|
10
|
-
outputPath?: string;
|
|
11
|
-
}
|
|
12
|
-
declare const createScalarPlugin: (options?: SilgiPluginConfig | undefined) => PergelPlugin<DefaultContext, DefaultInterface, SilgiPluginConfig>;
|
|
13
|
-
|
|
14
|
-
export { type SilgiPluginConfig, createScalarPlugin };
|
package/dist/plugins/scalar.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { P as PergelPlugin, D as DefaultContext, a as DefaultInterface } from '../shared/silgi.D5qK9QOm.js';
|
|
2
|
-
import 'consola';
|
|
3
|
-
import 'h3';
|
|
4
|
-
import 'zod';
|
|
5
|
-
import 'hookable';
|
|
6
|
-
|
|
7
|
-
interface SilgiPluginConfig {
|
|
8
|
-
writeToFile?: boolean;
|
|
9
|
-
theme?: 'alternate' | 'default' | 'moon' | 'purple' | 'solarized' | 'bluePlanet' | 'saturn' | 'kepler' | 'mars' | 'deepSpace' | 'none';
|
|
10
|
-
outputPath?: string;
|
|
11
|
-
}
|
|
12
|
-
declare const createScalarPlugin: (options?: SilgiPluginConfig | undefined) => PergelPlugin<DefaultContext, DefaultInterface, SilgiPluginConfig>;
|
|
13
|
-
|
|
14
|
-
export { type SilgiPluginConfig, createScalarPlugin };
|
package/dist/plugins/scalar.mjs
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
|
-
import { join } from 'node:path';
|
|
3
|
-
import { defineEventHandler } from 'h3';
|
|
4
|
-
import { a as defineSilgiPlugin } from '../shared/silgi.BMCYk2cR.mjs';
|
|
5
|
-
import 'consola';
|
|
6
|
-
import 'hookable';
|
|
7
|
-
import 'node:buffer';
|
|
8
|
-
import 'node:fs';
|
|
9
|
-
import 'unctx';
|
|
10
|
-
|
|
11
|
-
function generateHTML(openapi, config) {
|
|
12
|
-
return `<!doctype html>
|
|
13
|
-
<html>
|
|
14
|
-
<head>
|
|
15
|
-
<title>${openapi.info.title || "API Documentation"}</title>
|
|
16
|
-
<meta charset="utf-8" />
|
|
17
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
18
|
-
</head>
|
|
19
|
-
<body>
|
|
20
|
-
<script id="api-reference" type="application/json">
|
|
21
|
-
${JSON.stringify(openapi, null, 2)}
|
|
22
|
-
<\/script>
|
|
23
|
-
|
|
24
|
-
<script>
|
|
25
|
-
var configuration = {
|
|
26
|
-
theme: '${config.theme || "deepSpace"}'
|
|
27
|
-
}
|
|
28
|
-
document.getElementById('api-reference').dataset.configuration = JSON.stringify(configuration)
|
|
29
|
-
<\/script>
|
|
30
|
-
|
|
31
|
-
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"><\/script>
|
|
32
|
-
</body>
|
|
33
|
-
</html>`;
|
|
34
|
-
}
|
|
35
|
-
const createScalarPlugin = defineSilgiPlugin({
|
|
36
|
-
name: "scalar",
|
|
37
|
-
dependencies: ["openapi"],
|
|
38
|
-
async setup(config, initSilgi) {
|
|
39
|
-
const openapi = initSilgi.getEvent("openapi");
|
|
40
|
-
if (!openapi)
|
|
41
|
-
throw new Error("OpenAPI document not found. Make sure openapi plugin is initialized before scalar");
|
|
42
|
-
const scalarHandler = defineEventHandler(async (_event) => {
|
|
43
|
-
return generateHTML(openapi, config);
|
|
44
|
-
});
|
|
45
|
-
const routePath = "/api/_silgi/scalar";
|
|
46
|
-
initSilgi.silgi.hook("h3:app:setup", (router) => {
|
|
47
|
-
router.use(routePath, scalarHandler);
|
|
48
|
-
});
|
|
49
|
-
if (!config.writeToFile)
|
|
50
|
-
return;
|
|
51
|
-
try {
|
|
52
|
-
const silgiDir = join(process.cwd(), ".silgi");
|
|
53
|
-
await mkdir(silgiDir, { recursive: true });
|
|
54
|
-
const outputPath = config.outputPath || "docs";
|
|
55
|
-
const docsDir = join(silgiDir, outputPath);
|
|
56
|
-
await mkdir(docsDir, { recursive: true });
|
|
57
|
-
const htmlPath = join(docsDir, "index.html");
|
|
58
|
-
await writeFile(htmlPath, generateHTML(openapi, config), "utf-8");
|
|
59
|
-
} catch (error) {
|
|
60
|
-
initSilgi.silgi.logger.error("Failed to generate Scalar documentation:", error);
|
|
61
|
-
throw error;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
export { createScalarPlugin };
|