@hono-di/swagger 0.0.6 → 0.0.9
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/dist/index.cjs +43 -10
- package/dist/index.js +43 -10
- package/package.json +3 -2
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
var core = require('@hono-di/core');
|
|
4
4
|
require('reflect-metadata');
|
|
5
5
|
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
|
|
6
9
|
// src/document-builder.ts
|
|
7
10
|
var DocumentBuilder = class {
|
|
11
|
+
static {
|
|
12
|
+
__name(this, "DocumentBuilder");
|
|
13
|
+
}
|
|
8
14
|
document = {
|
|
9
15
|
openapi: "3.0.0",
|
|
10
16
|
info: {
|
|
@@ -33,15 +39,25 @@ var DocumentBuilder = class {
|
|
|
33
39
|
return this;
|
|
34
40
|
}
|
|
35
41
|
setContact(name, url, email) {
|
|
36
|
-
this.document.info.contact = {
|
|
42
|
+
this.document.info.contact = {
|
|
43
|
+
name,
|
|
44
|
+
url,
|
|
45
|
+
email
|
|
46
|
+
};
|
|
37
47
|
return this;
|
|
38
48
|
}
|
|
39
49
|
addServer(url, description) {
|
|
40
|
-
this.document.servers.push({
|
|
50
|
+
this.document.servers.push({
|
|
51
|
+
url,
|
|
52
|
+
description
|
|
53
|
+
});
|
|
41
54
|
return this;
|
|
42
55
|
}
|
|
43
56
|
addTag(name, description) {
|
|
44
|
-
this.document.tags.push({
|
|
57
|
+
this.document.tags.push({
|
|
58
|
+
name,
|
|
59
|
+
description
|
|
60
|
+
});
|
|
45
61
|
return this;
|
|
46
62
|
}
|
|
47
63
|
addBearerAuth(options = {}, name = "bearer") {
|
|
@@ -71,12 +87,14 @@ function ApiTags(...tags) {
|
|
|
71
87
|
Reflect.defineMetadata(DECORATORS.API_TAGS, tags, target);
|
|
72
88
|
};
|
|
73
89
|
}
|
|
90
|
+
__name(ApiTags, "ApiTags");
|
|
74
91
|
function ApiOperation(options) {
|
|
75
92
|
return (target, propertyKey, descriptor) => {
|
|
76
93
|
Reflect.defineMetadata(DECORATORS.API_OPERATION, options, descriptor.value);
|
|
77
94
|
return descriptor;
|
|
78
95
|
};
|
|
79
96
|
}
|
|
97
|
+
__name(ApiOperation, "ApiOperation");
|
|
80
98
|
function ApiResponse(options) {
|
|
81
99
|
return (target, propertyKey, descriptor) => {
|
|
82
100
|
const responses = Reflect.getMetadata(DECORATORS.API_RESPONSE, descriptor.value) || {};
|
|
@@ -85,16 +103,25 @@ function ApiResponse(options) {
|
|
|
85
103
|
return descriptor;
|
|
86
104
|
};
|
|
87
105
|
}
|
|
106
|
+
__name(ApiResponse, "ApiResponse");
|
|
88
107
|
function ApiProperty(options = {}) {
|
|
89
108
|
return (target, propertyKey) => {
|
|
90
109
|
const properties = Reflect.getMetadata(DECORATORS.API_PROPERTY, target.constructor) || [];
|
|
91
|
-
properties.push({
|
|
110
|
+
properties.push({
|
|
111
|
+
key: propertyKey,
|
|
112
|
+
...options
|
|
113
|
+
});
|
|
92
114
|
Reflect.defineMetadata(DECORATORS.API_PROPERTY, properties, target.constructor);
|
|
93
115
|
};
|
|
94
116
|
}
|
|
117
|
+
__name(ApiProperty, "ApiProperty");
|
|
95
118
|
|
|
96
119
|
// src/explorers/api-scanner.ts
|
|
97
120
|
var SwaggerScanner = class {
|
|
121
|
+
static {
|
|
122
|
+
__name(this, "SwaggerScanner");
|
|
123
|
+
}
|
|
124
|
+
container;
|
|
98
125
|
constructor(container) {
|
|
99
126
|
this.container = container;
|
|
100
127
|
}
|
|
@@ -109,12 +136,16 @@ var SwaggerScanner = class {
|
|
|
109
136
|
}
|
|
110
137
|
scanController(controller, document) {
|
|
111
138
|
if (!controller) return;
|
|
112
|
-
const { prefix } = Reflect.getMetadata(core.METADATA_KEYS.CONTROLLER, controller) || {
|
|
139
|
+
const { prefix } = Reflect.getMetadata(core.METADATA_KEYS.CONTROLLER, controller) || {
|
|
140
|
+
prefix: ""
|
|
141
|
+
};
|
|
113
142
|
const routes = Reflect.getMetadata(core.METADATA_KEYS.ROUTES, controller) || [];
|
|
114
143
|
const apiTags = Reflect.getMetadata(DECORATORS.API_TAGS, controller) || [];
|
|
115
144
|
apiTags.forEach((tag) => {
|
|
116
145
|
if (!document.tags.find((t) => t.name === tag)) {
|
|
117
|
-
document.tags.push({
|
|
146
|
+
document.tags.push({
|
|
147
|
+
name: tag
|
|
148
|
+
});
|
|
118
149
|
}
|
|
119
150
|
});
|
|
120
151
|
routes.forEach((route) => {
|
|
@@ -140,14 +171,15 @@ var SwaggerScanner = class {
|
|
|
140
171
|
};
|
|
141
172
|
});
|
|
142
173
|
if (Object.keys(responses).length === 0) {
|
|
143
|
-
responses["200"] = {
|
|
174
|
+
responses["200"] = {
|
|
175
|
+
description: "Successful operation"
|
|
176
|
+
};
|
|
144
177
|
}
|
|
145
178
|
return {
|
|
146
179
|
summary: apiOperation.summary || "",
|
|
147
180
|
description: apiOperation.description || "",
|
|
148
181
|
tags: controllerTags,
|
|
149
182
|
responses
|
|
150
|
-
// TODO: Add parameters and request body scanning
|
|
151
183
|
};
|
|
152
184
|
}
|
|
153
185
|
normalizePath(prefix, path) {
|
|
@@ -162,6 +194,9 @@ var SwaggerScanner = class {
|
|
|
162
194
|
|
|
163
195
|
// src/swagger-module.ts
|
|
164
196
|
var SwaggerModule = class {
|
|
197
|
+
static {
|
|
198
|
+
__name(this, "SwaggerModule");
|
|
199
|
+
}
|
|
165
200
|
static createDocument(app, config) {
|
|
166
201
|
const container = app.getContainer();
|
|
167
202
|
const scanner = new SwaggerScanner(container);
|
|
@@ -222,5 +257,3 @@ exports.DECORATORS = DECORATORS;
|
|
|
222
257
|
exports.DECORATORS_PREFIX = DECORATORS_PREFIX;
|
|
223
258
|
exports.DocumentBuilder = DocumentBuilder;
|
|
224
259
|
exports.SwaggerModule = SwaggerModule;
|
|
225
|
-
//# sourceMappingURL=index.cjs.map
|
|
226
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { METADATA_KEYS } from '@hono-di/core';
|
|
2
2
|
import 'reflect-metadata';
|
|
3
3
|
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
|
|
4
7
|
// src/document-builder.ts
|
|
5
8
|
var DocumentBuilder = class {
|
|
9
|
+
static {
|
|
10
|
+
__name(this, "DocumentBuilder");
|
|
11
|
+
}
|
|
6
12
|
document = {
|
|
7
13
|
openapi: "3.0.0",
|
|
8
14
|
info: {
|
|
@@ -31,15 +37,25 @@ var DocumentBuilder = class {
|
|
|
31
37
|
return this;
|
|
32
38
|
}
|
|
33
39
|
setContact(name, url, email) {
|
|
34
|
-
this.document.info.contact = {
|
|
40
|
+
this.document.info.contact = {
|
|
41
|
+
name,
|
|
42
|
+
url,
|
|
43
|
+
email
|
|
44
|
+
};
|
|
35
45
|
return this;
|
|
36
46
|
}
|
|
37
47
|
addServer(url, description) {
|
|
38
|
-
this.document.servers.push({
|
|
48
|
+
this.document.servers.push({
|
|
49
|
+
url,
|
|
50
|
+
description
|
|
51
|
+
});
|
|
39
52
|
return this;
|
|
40
53
|
}
|
|
41
54
|
addTag(name, description) {
|
|
42
|
-
this.document.tags.push({
|
|
55
|
+
this.document.tags.push({
|
|
56
|
+
name,
|
|
57
|
+
description
|
|
58
|
+
});
|
|
43
59
|
return this;
|
|
44
60
|
}
|
|
45
61
|
addBearerAuth(options = {}, name = "bearer") {
|
|
@@ -69,12 +85,14 @@ function ApiTags(...tags) {
|
|
|
69
85
|
Reflect.defineMetadata(DECORATORS.API_TAGS, tags, target);
|
|
70
86
|
};
|
|
71
87
|
}
|
|
88
|
+
__name(ApiTags, "ApiTags");
|
|
72
89
|
function ApiOperation(options) {
|
|
73
90
|
return (target, propertyKey, descriptor) => {
|
|
74
91
|
Reflect.defineMetadata(DECORATORS.API_OPERATION, options, descriptor.value);
|
|
75
92
|
return descriptor;
|
|
76
93
|
};
|
|
77
94
|
}
|
|
95
|
+
__name(ApiOperation, "ApiOperation");
|
|
78
96
|
function ApiResponse(options) {
|
|
79
97
|
return (target, propertyKey, descriptor) => {
|
|
80
98
|
const responses = Reflect.getMetadata(DECORATORS.API_RESPONSE, descriptor.value) || {};
|
|
@@ -83,16 +101,25 @@ function ApiResponse(options) {
|
|
|
83
101
|
return descriptor;
|
|
84
102
|
};
|
|
85
103
|
}
|
|
104
|
+
__name(ApiResponse, "ApiResponse");
|
|
86
105
|
function ApiProperty(options = {}) {
|
|
87
106
|
return (target, propertyKey) => {
|
|
88
107
|
const properties = Reflect.getMetadata(DECORATORS.API_PROPERTY, target.constructor) || [];
|
|
89
|
-
properties.push({
|
|
108
|
+
properties.push({
|
|
109
|
+
key: propertyKey,
|
|
110
|
+
...options
|
|
111
|
+
});
|
|
90
112
|
Reflect.defineMetadata(DECORATORS.API_PROPERTY, properties, target.constructor);
|
|
91
113
|
};
|
|
92
114
|
}
|
|
115
|
+
__name(ApiProperty, "ApiProperty");
|
|
93
116
|
|
|
94
117
|
// src/explorers/api-scanner.ts
|
|
95
118
|
var SwaggerScanner = class {
|
|
119
|
+
static {
|
|
120
|
+
__name(this, "SwaggerScanner");
|
|
121
|
+
}
|
|
122
|
+
container;
|
|
96
123
|
constructor(container) {
|
|
97
124
|
this.container = container;
|
|
98
125
|
}
|
|
@@ -107,12 +134,16 @@ var SwaggerScanner = class {
|
|
|
107
134
|
}
|
|
108
135
|
scanController(controller, document) {
|
|
109
136
|
if (!controller) return;
|
|
110
|
-
const { prefix } = Reflect.getMetadata(METADATA_KEYS.CONTROLLER, controller) || {
|
|
137
|
+
const { prefix } = Reflect.getMetadata(METADATA_KEYS.CONTROLLER, controller) || {
|
|
138
|
+
prefix: ""
|
|
139
|
+
};
|
|
111
140
|
const routes = Reflect.getMetadata(METADATA_KEYS.ROUTES, controller) || [];
|
|
112
141
|
const apiTags = Reflect.getMetadata(DECORATORS.API_TAGS, controller) || [];
|
|
113
142
|
apiTags.forEach((tag) => {
|
|
114
143
|
if (!document.tags.find((t) => t.name === tag)) {
|
|
115
|
-
document.tags.push({
|
|
144
|
+
document.tags.push({
|
|
145
|
+
name: tag
|
|
146
|
+
});
|
|
116
147
|
}
|
|
117
148
|
});
|
|
118
149
|
routes.forEach((route) => {
|
|
@@ -138,14 +169,15 @@ var SwaggerScanner = class {
|
|
|
138
169
|
};
|
|
139
170
|
});
|
|
140
171
|
if (Object.keys(responses).length === 0) {
|
|
141
|
-
responses["200"] = {
|
|
172
|
+
responses["200"] = {
|
|
173
|
+
description: "Successful operation"
|
|
174
|
+
};
|
|
142
175
|
}
|
|
143
176
|
return {
|
|
144
177
|
summary: apiOperation.summary || "",
|
|
145
178
|
description: apiOperation.description || "",
|
|
146
179
|
tags: controllerTags,
|
|
147
180
|
responses
|
|
148
|
-
// TODO: Add parameters and request body scanning
|
|
149
181
|
};
|
|
150
182
|
}
|
|
151
183
|
normalizePath(prefix, path) {
|
|
@@ -160,6 +192,9 @@ var SwaggerScanner = class {
|
|
|
160
192
|
|
|
161
193
|
// src/swagger-module.ts
|
|
162
194
|
var SwaggerModule = class {
|
|
195
|
+
static {
|
|
196
|
+
__name(this, "SwaggerModule");
|
|
197
|
+
}
|
|
163
198
|
static createDocument(app, config) {
|
|
164
199
|
const container = app.getContainer();
|
|
165
200
|
const scanner = new SwaggerScanner(container);
|
|
@@ -213,5 +248,3 @@ var SwaggerModule = class {
|
|
|
213
248
|
};
|
|
214
249
|
|
|
215
250
|
export { ApiOperation, ApiProperty, ApiResponse, ApiTags, DECORATORS, DECORATORS_PREFIX, DocumentBuilder, SwaggerModule };
|
|
216
|
-
//# sourceMappingURL=index.js.map
|
|
217
|
-
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hono-di/swagger",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
4
4
|
"description": "OpenAPI (Swagger) module for Hono-DI",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "bun test"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@hono-di/core": "0.0.
|
|
24
|
+
"@hono-di/core": "0.0.9",
|
|
25
25
|
"reflect-metadata": "^0.2.2"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"tsup": "^8.5.1",
|
|
32
32
|
"typescript": "^5.4.0",
|
|
33
|
+
"@swc/core": "^1.15.8",
|
|
33
34
|
"@types/node": "^22.10.6"
|
|
34
35
|
}
|
|
35
36
|
}
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/document-builder.ts","../src/decorators.ts","../src/explorers/api-scanner.ts","../src/swagger-module.ts"],"names":["METADATA_KEYS"],"mappings":";;;;;;AAAO,IAAM,kBAAN,MAAsB;AAAA,EACR,QAAA,GAAgB;AAAA,IAC7B,OAAA,EAAS,OAAA;AAAA,IACT,IAAA,EAAM;AAAA,MACF,KAAA,EAAO,EAAA;AAAA,MACP,WAAA,EAAa,EAAA;AAAA,MACb,OAAA,EAAS,OAAA;AAAA,MACT,SAAS;AAAC,KACd;AAAA,IACA,MAAM,EAAC;AAAA,IACP,SAAS,EAAC;AAAA,IACV,OAAO,EAAC;AAAA,IACR,UAAA,EAAY;AAAA,MACR,iBAAiB;AAAC;AACtB,GACJ;AAAA,EAEA,SAAS,KAAA,EAAqB;AAC1B,IAAA,IAAA,CAAK,QAAA,CAAS,KAAK,KAAA,GAAQ,KAAA;AAC3B,IAAA,OAA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,MAAA,EAA0C;AACpF,IAAA,MAAM,SAAA,GAAY,IAAI,YAAA,EAAa;AACnC,IAAA,MAAM,OAAA,GAAU,IAAI,cAAA,CAAe,SAAS,CAAA;AAC5C,IAAA,MAAM,QAAA,GAAW,MAAA;AACjB,IAAA,OAAO,OAAA,CAAQ,KAAK,QAAQ,CAAA;AAAA,EAChC;AAAA,EAEA,OAAO,KAAA,CAAM,IAAA,EAAc,GAAA,EAAwB,UAA2B,OAAA,EAAgC;AAC1G,IAAA,MAAM,WAAA,GAAc,IAAI,cAAA,EAAe;AAGvC,IAAA,WAAA,CAAY,GAAA,CAAI,GAAG,IAAI,CAAA,KAAA,CAAA,EAAS,CAAC,CAAA,KAAW,CAAA,CAAE,IAAA,CAAK,QAAQ,CAAC,CAAA;AAG5D,IAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,CAAC,CAAA,KAAW;AAC9B,MAAA,MAAM,IAAA,GAAO;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAA,EAKA,QAAA,CAAS,KAAK,KAAK,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAA,EAeZ,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAA,CAAA;AAiB5C,MAAA,OAAO,CAAA,CAAE,KAAK,IAAI,CAAA;AAAA,IACtB,CAAC,CAAA;AAAA,EACL;AACJ","file":"index.cjs","sourcesContent":["export class DocumentBuilder {\n private readonly document: any = {\n openapi: '3.0.0',\n info: {\n title: '',\n description: '',\n version: '1.0.0',\n contact: {},\n },\n tags: [],\n servers: [],\n paths: {},\n components: {\n securitySchemes: {},\n },\n };\n\n setTitle(title: string): this {\n this.document.info.title = title;\n return this;\n }\n\n setDescription(description: string): this {\n this.document.info.description = description;\n return this;\n }\n\n setVersion(version: string): this {\n this.document.info.version = version;\n return this;\n }\n\n setContact(name: string, url: string, email: string): this {\n this.document.info.contact = { name, url, email };\n return this;\n }\n\n addServer(url: string, description?: string): this {\n this.document.servers.push({ url, description });\n return this;\n }\n\n addTag(name: string, description?: string): this {\n this.document.tags.push({ name, description });\n return this;\n }\n\n addBearerAuth(options: any = {}, name = 'bearer'): this {\n this.document.components.securitySchemes[name] = {\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n ...options,\n };\n return this;\n }\n\n build(): any {\n return this.document;\n }\n}\n","import 'reflect-metadata';\n\nexport const DECORATORS_PREFIX = 'swagger';\nexport const DECORATORS = {\n API_TAGS: `${DECORATORS_PREFIX}/apiTags`,\n API_OPERATION: `${DECORATORS_PREFIX}/apiOperation`,\n API_RESPONSE: `${DECORATORS_PREFIX}/apiResponse`,\n API_PARAM: `${DECORATORS_PREFIX}/apiParam`,\n API_BODY: `${DECORATORS_PREFIX}/apiBody`,\n API_PROPERTY: `${DECORATORS_PREFIX}/apiProperty`,\n};\n\nexport function ApiTags(...tags: string[]): ClassDecorator {\n return (target: any) => {\n Reflect.defineMetadata(DECORATORS.API_TAGS, tags, target);\n };\n}\n\nexport function ApiOperation(options: { summary?: string; description?: string; deprecated?: boolean }): MethodDecorator {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n Reflect.defineMetadata(DECORATORS.API_OPERATION, options, descriptor.value);\n return descriptor;\n };\n}\n\nexport function ApiResponse(options: { status: number; description: string; type?: any }): MethodDecorator {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const responses = Reflect.getMetadata(DECORATORS.API_RESPONSE, descriptor.value) || {};\n responses[options.status] = options;\n Reflect.defineMetadata(DECORATORS.API_RESPONSE, responses, descriptor.value);\n return descriptor;\n };\n}\n\nexport function ApiProperty(options: { description?: string; type?: any; required?: boolean; example?: any } = {}): PropertyDecorator {\n return (target: any, propertyKey: string | symbol) => {\n const properties = Reflect.getMetadata(DECORATORS.API_PROPERTY, target.constructor) || [];\n properties.push({ key: propertyKey, ...options });\n Reflect.defineMetadata(DECORATORS.API_PROPERTY, properties, target.constructor);\n };\n}\n","import { Container, METADATA_KEYS, RequestMethod } from '@hono-di/core';\nimport { DECORATORS } from '../decorators';\nimport { SwaggerDocument } from '../interfaces';\n\nexport class SwaggerScanner {\n constructor(private readonly container: Container) { }\n\n scan(document: SwaggerDocument): SwaggerDocument {\n const modules = this.container.getModules();\n\n modules.forEach((module) => {\n module.controllers.forEach((wrapper) => {\n this.scanController(wrapper.metatype, document);\n });\n });\n\n return document;\n }\n\n private scanController(controller: any, document: SwaggerDocument) {\n if (!controller) return;\n\n const { prefix } = Reflect.getMetadata(METADATA_KEYS.CONTROLLER, controller) || { prefix: '' };\n const routes = Reflect.getMetadata(METADATA_KEYS.ROUTES, controller) || [];\n const apiTags = Reflect.getMetadata(DECORATORS.API_TAGS, controller) || [];\n\n // Add tags to document\n apiTags.forEach((tag: string) => {\n if (!document.tags.find(t => t.name === tag)) {\n document.tags.push({ name: tag });\n }\n });\n\n routes.forEach((route: any) => {\n const method = route.requestMethod;\n const path = this.normalizePath(prefix, route.path);\n const descriptor = Object.getOwnPropertyDescriptor(controller.prototype, route.methodName);\n const handler = descriptor?.value;\n\n if (!handler) return;\n\n const operation = this.createOperation(handler, apiTags);\n\n if (!document.paths[path]) {\n document.paths[path] = {};\n }\n document.paths[path][method] = operation;\n });\n }\n\n private createOperation(handler: any, controllerTags: string[]) {\n const apiOperation = Reflect.getMetadata(DECORATORS.API_OPERATION, handler) || {};\n const apiResponses = Reflect.getMetadata(DECORATORS.API_RESPONSE, handler) || {};\n\n const responses: Record<string, any> = {};\n Object.keys(apiResponses).forEach(status => {\n responses[status] = {\n description: apiResponses[status].description,\n };\n });\n\n // Default response if none provided\n if (Object.keys(responses).length === 0) {\n responses['200'] = { description: 'Successful operation' };\n }\n\n return {\n summary: apiOperation.summary || '',\n description: apiOperation.description || '',\n tags: controllerTags,\n responses,\n // TODO: Add parameters and request body scanning\n };\n }\n\n private normalizePath(prefix: string, path: string): string {\n const cleanPrefix = prefix ? prefix.replace(/^\\/+/, '').replace(/\\/+$/, '') : '';\n const cleanPath = path ? path.replace(/^\\/+/, '').replace(/\\/+$/, '') : '';\n let result = '';\n if (cleanPrefix) result += `/${cleanPrefix}`;\n if (cleanPath) result += `/${cleanPath}`;\n return (result || '/').replace(/:([^\\/]+)/g, '{$1}'); // Convert :param to {param}\n }\n}\n","import { HonoDiApplication } from '@hono-di/core';\nimport { DocumentBuilder } from './document-builder';\nimport { SwaggerDocument, SwaggerCustomOptions } from './interfaces';\nimport { SwaggerScanner } from './explorers/api-scanner';\n\nexport class SwaggerModule {\n static createDocument(app: HonoDiApplication, config: SwaggerDocument): SwaggerDocument {\n const container = app.getContainer();\n const scanner = new SwaggerScanner(container);\n const document = config;\n return scanner.scan(document);\n }\n\n static setup(path: string, app: HonoDiApplication, document: SwaggerDocument, options?: SwaggerCustomOptions) {\n const httpAdapter = app.getHttpAdapter();\n\n // Serve Swagger JSON\n httpAdapter.get(`${path}-json`, (c: any) => c.json(document));\n\n // Serve Swagger UI\n httpAdapter.get(path, (c: any) => {\n const html = `\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title>${document.info.title}</title>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui.css\" />\n <style>\n html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; }\n *, *:before, *:after { box-sizing: inherit; }\n body { margin: 0; background: #fafafa; }\n </style>\n </head>\n <body>\n <div id=\"swagger-ui\"></div>\n <script src=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js\" charset=\"UTF-8\"> </script>\n <script src=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js\" charset=\"UTF-8\"> </script>\n <script>\n window.onload = function() {\n const ui = SwaggerUIBundle({\n spec: ${JSON.stringify(document)},\n dom_id: '#swagger-ui',\n deepLinking: true,\n presets: [\n SwaggerUIBundle.presets.apis,\n SwaggerUIStandalonePreset\n ],\n plugins: [\n SwaggerUIBundle.plugins.DownloadUrl\n ],\n layout: \"StandaloneLayout\"\n });\n window.ui = ui;\n };\n </script>\n </body>\n </html>`;\n return c.html(html);\n });\n }\n}\n"]}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/document-builder.ts","../src/decorators.ts","../src/explorers/api-scanner.ts","../src/swagger-module.ts"],"names":[],"mappings":";;;;AAAO,IAAM,kBAAN,MAAsB;AAAA,EACR,QAAA,GAAgB;AAAA,IAC7B,OAAA,EAAS,OAAA;AAAA,IACT,IAAA,EAAM;AAAA,MACF,KAAA,EAAO,EAAA;AAAA,MACP,WAAA,EAAa,EAAA;AAAA,MACb,OAAA,EAAS,OAAA;AAAA,MACT,SAAS;AAAC,KACd;AAAA,IACA,MAAM,EAAC;AAAA,IACP,SAAS,EAAC;AAAA,IACV,OAAO,EAAC;AAAA,IACR,UAAA,EAAY;AAAA,MACR,iBAAiB;AAAC;AACtB,GACJ;AAAA,EAEA,SAAS,KAAA,EAAqB;AAC1B,IAAA,IAAA,CAAK,QAAA,CAAS,KAAK,KAAA,GAAQ,KAAA;AAC3B,IAAA,OAAO,IAAA;AAAA,EACX;AAAA,EAEA,eAAe,WAAA,EAA2B;AACtC,IAAA,IAAA,CAAK,QAAA,CAAS,KAAK,WAAA,GAAc,WAAA;AACjC,IAAA,OAAO,IAAA;AAAA,EACX;AAAA,EAEA,WAAW,OAAA,EAAuB;AAC9B,IAAA,IAAA,CAAK,QAAA,CAAS,KAAK,OAAA,GAAU,OAAA;AAC7B,IAAA,OAAO,IAAA;AAAA,EACX;AAAA,EAEA,UAAA,CAAW,IAAA,EAAc,GAAA,EAAa,KAAA,EAAqB;AACvD,IAAA,IAAA,CAAK,SAAS,IAAA,CAAK,OAAA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AG,IAAI,CAAA,KAAA,CAAA,EAAS,CAAC,CAAA,KAAW,CAAA,CAAE,IAAA,CAAK,QAAQ,CAAC,CAAA;AAG5D,IAAA,WAAA,CAAY,GAAA,CAAI,IAAA,EAAM,CAAC,CAAA,KAAW;AAC9B,MAAA,MAAM,IAAA,GAAO;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAA,EAKA,QAAA,CAAS,KAAK,KAAK,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAA,EAeZ,IAAA,CAAK,SAAA,CAAU,QAAQ,CAAC,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAA,CAAA;AAiB5C,MAAA,OAAO,CAAA,CAAE,KAAK,IAAI,CAAA;AAAA,IACtB,CAAC,CAAA;AAAA,EACL;AACJ","file":"index.js","sourcesContent":["export class DocumentBuilder {\n private readonly document: any = {\n openapi: '3.0.0',\n info: {\n title: '',\n description: '',\n version: '1.0.0',\n contact: {},\n },\n tags: [],\n servers: [],\n paths: {},\n components: {\n securitySchemes: {},\n },\n };\n\n setTitle(title: string): this {\n this.document.info.title = title;\n return this;\n }\n\n setDescription(description: string): this {\n this.document.info.description = description;\n return this;\n }\n\n setVersion(version: string): this {\n this.document.info.version = version;\n return this;\n }\n\n setContact(name: string, url: string, email: string): this {\n this.document.info.contact = { name, url, email };\n return this;\n }\n\n addServer(url: string, description?: string): this {\n this.document.servers.push({ url, description });\n return this;\n }\n\n addTag(name: string, description?: string): this {\n this.document.tags.push({ name, description });\n return this;\n }\n\n addBearerAuth(options: any = {}, name = 'bearer'): this {\n this.document.components.securitySchemes[name] = {\n type: 'http',\n scheme: 'bearer',\n bearerFormat: 'JWT',\n ...options,\n };\n return this;\n }\n\n build(): any {\n return this.document;\n }\n}\n","import 'reflect-metadata';\n\nexport const DECORATORS_PREFIX = 'swagger';\nexport const DECORATORS = {\n API_TAGS: `${DECORATORS_PREFIX}/apiTags`,\n API_OPERATION: `${DECORATORS_PREFIX}/apiOperation`,\n API_RESPONSE: `${DECORATORS_PREFIX}/apiResponse`,\n API_PARAM: `${DECORATORS_PREFIX}/apiParam`,\n API_BODY: `${DECORATORS_PREFIX}/apiBody`,\n API_PROPERTY: `${DECORATORS_PREFIX}/apiProperty`,\n};\n\nexport function ApiTags(...tags: string[]): ClassDecorator {\n return (target: any) => {\n Reflect.defineMetadata(DECORATORS.API_TAGS, tags, target);\n };\n}\n\nexport function ApiOperation(options: { summary?: string; description?: string; deprecated?: boolean }): MethodDecorator {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n Reflect.defineMetadata(DECORATORS.API_OPERATION, options, descriptor.value);\n return descriptor;\n };\n}\n\nexport function ApiResponse(options: { status: number; description: string; type?: any }): MethodDecorator {\n return (target: any, propertyKey: string | symbol, descriptor: PropertyDescriptor) => {\n const responses = Reflect.getMetadata(DECORATORS.API_RESPONSE, descriptor.value) || {};\n responses[options.status] = options;\n Reflect.defineMetadata(DECORATORS.API_RESPONSE, responses, descriptor.value);\n return descriptor;\n };\n}\n\nexport function ApiProperty(options: { description?: string; type?: any; required?: boolean; example?: any } = {}): PropertyDecorator {\n return (target: any, propertyKey: string | symbol) => {\n const properties = Reflect.getMetadata(DECORATORS.API_PROPERTY, target.constructor) || [];\n properties.push({ key: propertyKey, ...options });\n Reflect.defineMetadata(DECORATORS.API_PROPERTY, properties, target.constructor);\n };\n}\n","import { Container, METADATA_KEYS, RequestMethod } from '@hono-di/core';\nimport { DECORATORS } from '../decorators';\nimport { SwaggerDocument } from '../interfaces';\n\nexport class SwaggerScanner {\n constructor(private readonly container: Container) { }\n\n scan(document: SwaggerDocument): SwaggerDocument {\n const modules = this.container.getModules();\n\n modules.forEach((module) => {\n module.controllers.forEach((wrapper) => {\n this.scanController(wrapper.metatype, document);\n });\n });\n\n return document;\n }\n\n private scanController(controller: any, document: SwaggerDocument) {\n if (!controller) return;\n\n const { prefix } = Reflect.getMetadata(METADATA_KEYS.CONTROLLER, controller) || { prefix: '' };\n const routes = Reflect.getMetadata(METADATA_KEYS.ROUTES, controller) || [];\n const apiTags = Reflect.getMetadata(DECORATORS.API_TAGS, controller) || [];\n\n // Add tags to document\n apiTags.forEach((tag: string) => {\n if (!document.tags.find(t => t.name === tag)) {\n document.tags.push({ name: tag });\n }\n });\n\n routes.forEach((route: any) => {\n const method = route.requestMethod;\n const path = this.normalizePath(prefix, route.path);\n const descriptor = Object.getOwnPropertyDescriptor(controller.prototype, route.methodName);\n const handler = descriptor?.value;\n\n if (!handler) return;\n\n const operation = this.createOperation(handler, apiTags);\n\n if (!document.paths[path]) {\n document.paths[path] = {};\n }\n document.paths[path][method] = operation;\n });\n }\n\n private createOperation(handler: any, controllerTags: string[]) {\n const apiOperation = Reflect.getMetadata(DECORATORS.API_OPERATION, handler) || {};\n const apiResponses = Reflect.getMetadata(DECORATORS.API_RESPONSE, handler) || {};\n\n const responses: Record<string, any> = {};\n Object.keys(apiResponses).forEach(status => {\n responses[status] = {\n description: apiResponses[status].description,\n };\n });\n\n // Default response if none provided\n if (Object.keys(responses).length === 0) {\n responses['200'] = { description: 'Successful operation' };\n }\n\n return {\n summary: apiOperation.summary || '',\n description: apiOperation.description || '',\n tags: controllerTags,\n responses,\n // TODO: Add parameters and request body scanning\n };\n }\n\n private normalizePath(prefix: string, path: string): string {\n const cleanPrefix = prefix ? prefix.replace(/^\\/+/, '').replace(/\\/+$/, '') : '';\n const cleanPath = path ? path.replace(/^\\/+/, '').replace(/\\/+$/, '') : '';\n let result = '';\n if (cleanPrefix) result += `/${cleanPrefix}`;\n if (cleanPath) result += `/${cleanPath}`;\n return (result || '/').replace(/:([^\\/]+)/g, '{$1}'); // Convert :param to {param}\n }\n}\n","import { HonoDiApplication } from '@hono-di/core';\nimport { DocumentBuilder } from './document-builder';\nimport { SwaggerDocument, SwaggerCustomOptions } from './interfaces';\nimport { SwaggerScanner } from './explorers/api-scanner';\n\nexport class SwaggerModule {\n static createDocument(app: HonoDiApplication, config: SwaggerDocument): SwaggerDocument {\n const container = app.getContainer();\n const scanner = new SwaggerScanner(container);\n const document = config;\n return scanner.scan(document);\n }\n\n static setup(path: string, app: HonoDiApplication, document: SwaggerDocument, options?: SwaggerCustomOptions) {\n const httpAdapter = app.getHttpAdapter();\n\n // Serve Swagger JSON\n httpAdapter.get(`${path}-json`, (c: any) => c.json(document));\n\n // Serve Swagger UI\n httpAdapter.get(path, (c: any) => {\n const html = `\n <!DOCTYPE html>\n <html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\">\n <title>${document.info.title}</title>\n <link rel=\"stylesheet\" type=\"text/css\" href=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui.css\" />\n <style>\n html { box-sizing: border-box; overflow: -moz-scrollbars-vertical; overflow-y: scroll; }\n *, *:before, *:after { box-sizing: inherit; }\n body { margin: 0; background: #fafafa; }\n </style>\n </head>\n <body>\n <div id=\"swagger-ui\"></div>\n <script src=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui-bundle.js\" charset=\"UTF-8\"> </script>\n <script src=\"https://unpkg.com/swagger-ui-dist@5/swagger-ui-standalone-preset.js\" charset=\"UTF-8\"> </script>\n <script>\n window.onload = function() {\n const ui = SwaggerUIBundle({\n spec: ${JSON.stringify(document)},\n dom_id: '#swagger-ui',\n deepLinking: true,\n presets: [\n SwaggerUIBundle.presets.apis,\n SwaggerUIStandalonePreset\n ],\n plugins: [\n SwaggerUIBundle.plugins.DownloadUrl\n ],\n layout: \"StandaloneLayout\"\n });\n window.ui = ui;\n };\n </script>\n </body>\n </html>`;\n return c.html(html);\n });\n }\n}\n"]}
|