Skip to content

MaxProperties

@tsed/schema

Usage

typescript
import { MaxProperties } from "@tsed/schema";

See /packages/specs/schema/src/types/decorators/collections/maxProperties.ts.

Overview

ts
const MaxProperties: import("../../utils/withErrorMsg.js").ErrorChainedDecorator<(maxProperties: number) => (...args: any[]) => any>;

Description

An object instance is valid against maxProperties if its number of properties is less than, or equal to, the value of this keyword.

WARNING

The value of this keyword MUST be a non-negative integer.

WARNING

This decorator will be removed in v7. For v6 user, use MaxProperties from @tsed/schema instead of @tsed/platform-http.

Example

On prop

typescript
class Model {
   @MaxProperties(10)
   property: any;
}

Will produce:

json
{
  "type": "object",
  "properties": {
    "property": {
      "type": "any",
      "maxProperties": 10
    }
  }
}

On class

typescript
@MaxProperties(10)
class Model {
}

Will produce:

json
{
  "type": "object",
  "maxProperties": 10
}

On Parameter

typescript

class Model {
  method(@Any() @MaxProperties(10) obj: any){}
}

Released under the MIT License.