@tsed/schema
Version:
JsonSchema module for Ts.ED Framework
48 lines (47 loc) • 993 B
JavaScript
import { decoratorTypeOf, DecoratorTypes } from "@tsed/core";
import { JsonEntityFn } from "../common/jsonEntityFn.js";
/**
* Add a name metadata on the decorated element.
*
* ## Examples
* ### On parameters
*
* ```typescript
* async myMethod(@Name("nameOf") @PathParams("id") id: string): Promise<Model> {
*
* }
* ```
*
* ### On parameters
*
* ```typescript
* @Name("AliasName")
* @Controller("/")
* class ModelCtrl {
*
* }
* ```
*
* @param name
* @decorator
* @validation
* @swagger
* @schema
* @input
* @classDecorator
* @operation
*/
export function Name(name) {
return JsonEntityFn((store, args) => {
switch (decoratorTypeOf(args)) {
case DecoratorTypes.CLASS:
store.schema.name(name);
break;
case DecoratorTypes.PARAM:
store.parameter.name(name);
break;
default:
store.parent.schema.addAlias(args[1], name);
}
});
}