mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-11 10:20:30 +00:00
Compare commits
1 Commits
revert-664
...
swagger
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74b6e41cd4 |
63
packages/server/src/decorators/swagger-decorators.ts
Normal file
63
packages/server/src/decorators/swagger-decorators.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
export const swaggerDocs = {
|
||||
tags: {},
|
||||
paths: {},
|
||||
};
|
||||
|
||||
// Decorator to set a tag for a route
|
||||
export function ApiTags(tag) {
|
||||
return function (target) {
|
||||
if (!swaggerDocs.tags[tag]) {
|
||||
swaggerDocs.tags[tag] = { name: tag };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Decorator to add an operation for a specific route
|
||||
export function ApiOperation(options) {
|
||||
return function (target, propertyKey, descriptor) {
|
||||
const routePath = Reflect.getMetadata('path', target, propertyKey);
|
||||
|
||||
swaggerDocs.paths[routePath] = swaggerDocs.paths[routePath] || {};
|
||||
swaggerDocs.paths[routePath].get = {
|
||||
summary: options.summary,
|
||||
description: options.description || '',
|
||||
responses: options.responses || {
|
||||
200: {
|
||||
description: 'Successful Response',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
// Decorator to define the route path
|
||||
export function Route(path) {
|
||||
return function (target, propertyKey, descriptor) {
|
||||
Reflect.defineMetadata('path', path, target, propertyKey);
|
||||
};
|
||||
}
|
||||
|
||||
// Decorator to add a response schema for a specific route
|
||||
export function ApiResponse(options) {
|
||||
return function (target, propertyKey, descriptor) {
|
||||
const routePath = Reflect.getMetadata('path', target, propertyKey);
|
||||
|
||||
if (!swaggerDocs.paths[routePath]) {
|
||||
swaggerDocs.paths[routePath] = { get: {} };
|
||||
}
|
||||
|
||||
swaggerDocs.paths[routePath].get.responses =
|
||||
swaggerDocs.paths[routePath].get.responses || {};
|
||||
|
||||
swaggerDocs.paths[routePath].get.responses[options.status] = {
|
||||
description: options.description || 'No description provided',
|
||||
content: {
|
||||
'application/json': {
|
||||
schema: options.schema || {},
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user