@aetherionfw/docs 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Cristian Londoño
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ export declare class OpenApiBuilder {
2
+ build(title: string, version?: string): any;
3
+ }
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.OpenApiBuilder = void 0;
4
+ const core_1 = require("@aetherionfw/core");
5
+ const DocsRegistry_1 = require("../registry/DocsRegistry");
6
+ class OpenApiBuilder {
7
+ build(title, version = '1.0.0') {
8
+ const metaRegistry = core_1.MetadataRegistry.getInstance();
9
+ const docsRegistry = DocsRegistry_1.DocsRegistry.getInstance();
10
+ const openapi = {
11
+ openapi: '3.0.0',
12
+ info: { title, version },
13
+ paths: {},
14
+ components: {
15
+ schemas: {}
16
+ }
17
+ };
18
+ // 1. Build Schemas
19
+ const schemas = docsRegistry.getSchemas();
20
+ for (const [target, properties] of schemas) {
21
+ const schemaName = target.name;
22
+ const requiredProps = [];
23
+ const propertiesObj = {};
24
+ for (const prop of properties) {
25
+ propertiesObj[prop.name] = {
26
+ type: prop.type,
27
+ description: prop.description,
28
+ example: prop.example
29
+ };
30
+ if (prop.required !== false) {
31
+ requiredProps.push(prop.name);
32
+ }
33
+ }
34
+ openapi.components.schemas[schemaName] = {
35
+ type: 'object',
36
+ properties: propertiesObj,
37
+ required: requiredProps.length > 0 ? requiredProps : undefined
38
+ };
39
+ }
40
+ // 2. Build Paths & Operations
41
+ const controllers = metaRegistry.getControllers();
42
+ for (const [target, _] of controllers) {
43
+ const tagMeta = docsRegistry.getTag(target);
44
+ const routes = metaRegistry.getRoutes(target);
45
+ // In a real implementation we would map route -> prototype method name.
46
+ // For this simplified version, let's assume route paths are properly mapped
47
+ // and we just try to find the matching documentation via a heuristic (or the stored method name).
48
+ const prototype = target.prototype;
49
+ const methods = Object.getOwnPropertyNames(prototype).filter(m => m !== 'constructor');
50
+ for (const method of methods) {
51
+ // Did @Route tag this method?
52
+ const routeMeta = Reflect.getMetadata('route', prototype, method);
53
+ if (routeMeta && routeMeta.path && routeMeta.method) {
54
+ const path = routeMeta.path;
55
+ const httpMethod = routeMeta.method.toLowerCase();
56
+ if (!openapi.paths[path]) {
57
+ openapi.paths[path] = {};
58
+ }
59
+ const opMeta = docsRegistry.getOperation(target, method) || { summary: method };
60
+ const responsesMeta = docsRegistry.getResponses(target, method);
61
+ const responsesObj = {};
62
+ if (responsesMeta.length === 0) {
63
+ responsesObj['200'] = { description: 'Success' };
64
+ }
65
+ else {
66
+ for (const res of responsesMeta) {
67
+ responsesObj[String(res.status)] = {
68
+ description: res.description,
69
+ content: res.type ? {
70
+ 'application/json': {
71
+ schema: { $ref: `#/components/schemas/${res.type.name}` }
72
+ }
73
+ } : undefined
74
+ };
75
+ }
76
+ }
77
+ openapi.paths[path][httpMethod] = {
78
+ summary: opMeta.summary,
79
+ description: opMeta.description,
80
+ tags: tagMeta ? [tagMeta.name] : ['Default'],
81
+ responses: responsesObj
82
+ };
83
+ }
84
+ }
85
+ }
86
+ return openapi;
87
+ }
88
+ }
89
+ exports.OpenApiBuilder = OpenApiBuilder;
@@ -0,0 +1,4 @@
1
+ import { ApiOperationMetadata, ApiResponseMetadata } from '../registry/DocsRegistry';
2
+ export declare function ApiTag(name: string, description?: string): ClassDecorator;
3
+ export declare function ApiOperation(metadata: ApiOperationMetadata): MethodDecorator;
4
+ export declare function ApiResponse(metadata: ApiResponseMetadata): MethodDecorator;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiTag = ApiTag;
4
+ exports.ApiOperation = ApiOperation;
5
+ exports.ApiResponse = ApiResponse;
6
+ const DocsRegistry_1 = require("../registry/DocsRegistry");
7
+ function ApiTag(name, description) {
8
+ return (target) => {
9
+ DocsRegistry_1.DocsRegistry.getInstance().registerTag(target, name, description);
10
+ };
11
+ }
12
+ function ApiOperation(metadata) {
13
+ return (target, propertyKey) => {
14
+ DocsRegistry_1.DocsRegistry.getInstance().registerOperation(target.constructor, String(propertyKey), metadata);
15
+ };
16
+ }
17
+ function ApiResponse(metadata) {
18
+ return (target, propertyKey) => {
19
+ DocsRegistry_1.DocsRegistry.getInstance().registerResponse(target.constructor, String(propertyKey), metadata);
20
+ };
21
+ }
@@ -0,0 +1,2 @@
1
+ import { ApiPropertyMetadata } from '../registry/DocsRegistry';
2
+ export declare function ApiProperty(metadata?: Omit<ApiPropertyMetadata, 'name'>): PropertyDecorator;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApiProperty = ApiProperty;
4
+ const DocsRegistry_1 = require("../registry/DocsRegistry");
5
+ function ApiProperty(metadata = { type: 'string' }) {
6
+ return (target, propertyKey) => {
7
+ DocsRegistry_1.DocsRegistry.getInstance().registerProperty(target.constructor, {
8
+ name: String(propertyKey),
9
+ ...metadata,
10
+ });
11
+ };
12
+ }
@@ -0,0 +1,5 @@
1
+ export * from './registry/DocsRegistry';
2
+ export * from './decorators/api-operation.decorator';
3
+ export * from './decorators/api-property.decorator';
4
+ export * from './builder/OpenApiBuilder';
5
+ export * from './scalar';
package/dist/index.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./registry/DocsRegistry"), exports);
18
+ __exportStar(require("./decorators/api-operation.decorator"), exports);
19
+ __exportStar(require("./decorators/api-property.decorator"), exports);
20
+ __exportStar(require("./builder/OpenApiBuilder"), exports);
21
+ __exportStar(require("./scalar"), exports);
@@ -0,0 +1,36 @@
1
+ export interface ApiPropertyMetadata {
2
+ name: string;
3
+ type?: any;
4
+ description?: string;
5
+ example?: any;
6
+ required?: boolean;
7
+ }
8
+ export interface ApiOperationMetadata {
9
+ summary: string;
10
+ description?: string;
11
+ }
12
+ export interface ApiResponseMetadata {
13
+ status: number;
14
+ description: string;
15
+ type?: any;
16
+ }
17
+ export declare class DocsRegistry {
18
+ private static instance;
19
+ private schemas;
20
+ private operations;
21
+ private responses;
22
+ private tags;
23
+ private constructor();
24
+ static getInstance(): DocsRegistry;
25
+ registerProperty(target: any, metadata: ApiPropertyMetadata): void;
26
+ getSchemas(): [any, ApiPropertyMetadata[]][];
27
+ registerOperation(target: any, method: string, metadata: ApiOperationMetadata): void;
28
+ getOperation(target: any, method: string): ApiOperationMetadata | undefined;
29
+ registerResponse(target: any, method: string, metadata: ApiResponseMetadata): void;
30
+ getResponses(target: any, method: string): ApiResponseMetadata[];
31
+ registerTag(target: any, name: string, description?: string): void;
32
+ getTag(target: any): {
33
+ name: string;
34
+ description?: string;
35
+ } | undefined;
36
+ }
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DocsRegistry = void 0;
4
+ class DocsRegistry {
5
+ static instance;
6
+ schemas = new Map();
7
+ operations = new Map(); // Controller -> method -> Metadata
8
+ responses = new Map(); // Controller -> method -> Metadata
9
+ tags = new Map(); // Controller -> Tag
10
+ constructor() { }
11
+ static getInstance() {
12
+ if (!DocsRegistry.instance) {
13
+ DocsRegistry.instance = new DocsRegistry();
14
+ }
15
+ return DocsRegistry.instance;
16
+ }
17
+ registerProperty(target, metadata) {
18
+ if (!this.schemas.has(target)) {
19
+ this.schemas.set(target, []);
20
+ }
21
+ this.schemas.get(target).push(metadata);
22
+ }
23
+ getSchemas() {
24
+ return Array.from(this.schemas.entries());
25
+ }
26
+ registerOperation(target, method, metadata) {
27
+ if (!this.operations.has(target)) {
28
+ this.operations.set(target, new Map());
29
+ }
30
+ this.operations.get(target).set(method, metadata);
31
+ }
32
+ getOperation(target, method) {
33
+ return this.operations.get(target)?.get(method);
34
+ }
35
+ registerResponse(target, method, metadata) {
36
+ if (!this.responses.has(target)) {
37
+ this.responses.set(target, new Map());
38
+ }
39
+ const methodResponses = this.responses.get(target);
40
+ if (!methodResponses.has(method)) {
41
+ methodResponses.set(method, []);
42
+ }
43
+ methodResponses.get(method).push(metadata);
44
+ }
45
+ getResponses(target, method) {
46
+ return this.responses.get(target)?.get(method) || [];
47
+ }
48
+ registerTag(target, name, description) {
49
+ this.tags.set(target, { name, description });
50
+ }
51
+ getTag(target) {
52
+ return this.tags.get(target);
53
+ }
54
+ }
55
+ exports.DocsRegistry = DocsRegistry;
@@ -0,0 +1,2 @@
1
+ export declare function generateStaticDocs(outputDir: string, title?: string): void;
2
+ export declare function startScalarServer(port?: number, title?: string): void;
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36
+ return (mod && mod.__esModule) ? mod : { "default": mod };
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.generateStaticDocs = generateStaticDocs;
40
+ exports.startScalarServer = startScalarServer;
41
+ const fs = __importStar(require("fs"));
42
+ const path = __importStar(require("path"));
43
+ const express_1 = __importDefault(require("express"));
44
+ const OpenApiBuilder_1 = require("../builder/OpenApiBuilder");
45
+ function generateStaticDocs(outputDir, title = 'Aetherion API') {
46
+ const builder = new OpenApiBuilder_1.OpenApiBuilder();
47
+ const spec = builder.build(title);
48
+ const fullPath = path.resolve(outputDir, 'openapi.json');
49
+ fs.mkdirSync(path.dirname(fullPath), { recursive: true });
50
+ fs.writeFileSync(fullPath, JSON.stringify(spec, null, 2));
51
+ console.log(`Generated OpenAPI spec at ${fullPath}`);
52
+ }
53
+ function startScalarServer(port = 3000, title = 'Aetherion API') {
54
+ const app = (0, express_1.default)();
55
+ app.get('/openapi.json', (req, res) => {
56
+ const builder = new OpenApiBuilder_1.OpenApiBuilder();
57
+ const spec = builder.build(title);
58
+ res.json(spec);
59
+ });
60
+ app.get('/docs', (req, res) => {
61
+ const html = `
62
+ <!doctype html>
63
+ <html>
64
+ <head>
65
+ <title>${title} Reference</title>
66
+ <meta charset="utf-8" />
67
+ <meta
68
+ name="viewport"
69
+ content="width=device-width, initial-scale=1" />
70
+ </head>
71
+ <body>
72
+ <script
73
+ id="api-reference"
74
+ data-url="/openapi.json"></script>
75
+ <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
76
+ </body>
77
+ </html>
78
+ `;
79
+ res.send(html);
80
+ });
81
+ app.listen(port, () => {
82
+ console.log(`Scalar docs available at http://localhost:${port}/docs`);
83
+ });
84
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@aetherionfw/docs",
3
+ "version": "1.0.0",
4
+ "description": "OpenAPI Documentation & Scalar for Aetherion Framework",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "dependencies": {
8
+ "express": "^4.19.0",
9
+ "reflect-metadata": "^0.2.2",
10
+ "@aetherionfw/core": "1.0.0"
11
+ },
12
+ "devDependencies": {
13
+ "@types/express": "^4.17.21",
14
+ "typescript": "^5.5.4"
15
+ },
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "package.json",
22
+ "README.md"
23
+ ],
24
+ "author": "CrisD3v",
25
+ "license": "MIT",
26
+ "scripts": {
27
+ "build": "tsc",
28
+ "clean": "rm -rf dist"
29
+ }
30
+ }