diff --git a/packages/common/src/jsonschema/decorators/ignoreProperty.ts b/packages/common/src/jsonschema/decorators/ignoreProperty.ts index 331ae305522..0d2c534e4aa 100644 --- a/packages/common/src/jsonschema/decorators/ignoreProperty.ts +++ b/packages/common/src/jsonschema/decorators/ignoreProperty.ts @@ -1,5 +1,5 @@ +import {PropertyFn} from "@tsed/common"; import {PropertyMetadata} from "../class/PropertyMetadata"; -import {PropertyRegistry} from "../registries/PropertyRegistry"; /** * Disable serialization for this property when the Converters service will render the JSON object. @@ -63,7 +63,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry"; * @converters */ export function IgnoreProperty() { - return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => { + return PropertyFn((propertyMetadata: PropertyMetadata) => { propertyMetadata.ignoreProperty = true; }); } diff --git a/packages/common/src/jsonschema/decorators/jsonProperty.ts b/packages/common/src/jsonschema/decorators/jsonProperty.ts index 39f899fb6a0..acf90325521 100644 --- a/packages/common/src/jsonschema/decorators/jsonProperty.ts +++ b/packages/common/src/jsonschema/decorators/jsonProperty.ts @@ -1,4 +1,4 @@ -import {isEmpty, Type} from "@tsed/core"; +import {DecoratorParameters, isEmpty, Type} from "@tsed/core"; import {IPropertyOptions} from "../../converters/interfaces/IPropertyOptions"; import {PropertyMetadata} from "../class/PropertyMetadata"; import {PropertyRegistry} from "../registries/PropertyRegistry"; @@ -91,7 +91,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry"; * @converters */ export function JsonProperty(options?: IPropertyOptions | string): Function { - return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => { + return PropertyFn((propertyMetadata: PropertyMetadata) => { if (typeof options === "string") { propertyMetadata.name = options as string; } else if (typeof options === "object") { @@ -192,3 +192,7 @@ export function JsonProperty(options?: IPropertyOptions | string): Function { export function Property(options?: IPropertyOptions | string) { return JsonProperty(options); } + +export function PropertyFn(fn: (propertyMetadata: PropertyMetadata, parameters: DecoratorParameters) => void): Function { + return PropertyRegistry.decorate(fn); +} diff --git a/packages/common/src/jsonschema/decorators/propertyName.ts b/packages/common/src/jsonschema/decorators/propertyName.ts index c0b6a2de1ea..c35928fdfe2 100644 --- a/packages/common/src/jsonschema/decorators/propertyName.ts +++ b/packages/common/src/jsonschema/decorators/propertyName.ts @@ -1,5 +1,5 @@ import {PropertyMetadata} from "../class/PropertyMetadata"; -import {PropertyRegistry} from "../registries/PropertyRegistry"; +import {PropertyFn} from "./jsonProperty"; /** * Create an alias of the propertyKey that must be used by the converter. @@ -23,7 +23,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry"; * @converters */ export function PropertyName(name: string) { - return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => { + return PropertyFn((propertyMetadata: PropertyMetadata) => { propertyMetadata.name = name; }); } diff --git a/packages/common/src/jsonschema/decorators/propertyType.ts b/packages/common/src/jsonschema/decorators/propertyType.ts index 241b1540c36..0271915ef92 100644 --- a/packages/common/src/jsonschema/decorators/propertyType.ts +++ b/packages/common/src/jsonschema/decorators/propertyType.ts @@ -1,6 +1,6 @@ import {Type} from "@tsed/core"; import {PropertyMetadata} from "../class/PropertyMetadata"; -import {PropertyRegistry} from "../registries/PropertyRegistry"; +import {PropertyFn} from "./jsonProperty"; /** * Set the type of the array items. The possible value is String, Boolean, Number, Date, Object, Class, etc... @@ -44,7 +44,7 @@ import {PropertyRegistry} from "../registries/PropertyRegistry"; * @converters */ export function PropertyType(type: Type) { - return PropertyRegistry.decorate((propertyMetadata: PropertyMetadata) => { + return PropertyFn((propertyMetadata: PropertyMetadata) => { propertyMetadata.type = type; }); }