@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
48 lines (47 loc) • 1.73 kB
JavaScript
import { OperationVerbs } from "../../constants/OperationVerbs.js";
import { DecoratorContext } from "../../domain/DecoratorContext.js";
import { mapOperationOptions } from "../../utils/mapOperationOptions.js";
class OperationDecoratorContext extends DecoratorContext {
constructor() {
super(...arguments);
this.methods = ["name", "description", "summary", "method", "id", "use", "useAfter", "useBefore"];
}
beforeInit() {
const path = this.get("path");
const method = OperationVerbs[this.get("method")] || OperationVerbs.CUSTOM;
if (path) {
this.operationPath = this.entity.operation.addOperationPath(method, path);
}
}
onMapKey(key, value) {
switch (key) {
case "name":
case "id":
this.entity.operation.operationId(value);
return;
case "summary":
this.operationPath?.summary(value);
this.entity.operation.summary(value);
return;
case "description":
this.operationPath?.description(value);
this.entity.operation.description(value);
return;
case "use":
this.entity.use(value);
return;
case "useAfter":
this.entity.after(value);
return;
case "useBefore":
this.entity.before(value);
return;
}
return super.onMapKey(key, value);
}
}
export function Operation(...args) {
const routeOptions = mapOperationOptions(args);
const context = new OperationDecoratorContext(routeOptions);
return context.build();
}