@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
45 lines (44 loc) • 1.18 kB
JavaScript
import { decorateMethodsOf, decoratorTypeOf, DecoratorTypes, UnsupportedDecoratorType } from "@tsed/core";
import { JsonEntityFn } from "../common/jsonEntityFn.js";
/**
* Add deprecated metadata on the decorated element.
*
* ## Examples
*
* ```typescript
*
* @Deprecated()
* class MyCtrl {
* @Deprecated()
* @Get("/")
* method(){
* }
* }
* ```
*
* @param deprecated
* @decorator
* @swagger
* @schema
* @operation
*/
export function Deprecated(deprecated = true) {
return JsonEntityFn((store, args) => {
switch (decoratorTypeOf(args)) {
case DecoratorTypes.METHOD:
store.operation.deprecated(deprecated);
break;
case DecoratorTypes.CLASS:
decorateMethodsOf(args[0], Deprecated(deprecated));
break;
case DecoratorTypes.PARAM:
store.parameter.set("deprecated", deprecated);
break;
case DecoratorTypes.PROP:
store.schema.set("deprecated", deprecated);
break;
default:
throw new UnsupportedDecoratorType(Deprecated, args);
}
});
}