Skip to content

Min

@tsed/schema

Usage

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

See /packages/specs/schema/src/types/decorators/common/minimum.ts.

Overview

ts
const Min: import("../../utils/withErrorMsg.js").ErrorChainedDecorator<(minimum: number, exclusive?: boolean) => (...args: any[]) => any>;

Description

The value of minimum MUST be a number, representing an inclusive upper limit for a numeric instance.

If the instance is a number, then this keyword validates only if the instance is greater than or exactly equal to minimum.

Example

With primitive type

typescript
class Model {
   @Min(10)
   property: number;
}

Will produce:

json
{
  "type": "object",
  "properties": {
    "property": {
      "type": "number",
      "minimum": 10
    }
  }
}

With array type

typescript
class Model {
   @Min(10)
   @CollectionOf(Number)
   property: number[];
}

Will produce:

json
{
  "type": "object",
  "properties": {
    "property": {
      "type": "array",
      "items": {
         "type": "number",
         "minimum": 10
      }
    }
  }
}

Released under the MIT License.