# MinLength Decorator

Module
import { MinLength } from "@tsed/common"
Source/packages/common/src/jsonschema/decorators/minLength.ts

# Overview

function MinLength(minLength: number): (...parameters: any[]) => any;

# Description

A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.

The length of a string instance is defined as the number of its characters as defined by RFC 7159.

WARNING

The value of minLength MUST be a non-negative integer.

TIP

Omitting this keyword has the same behavior as a value of 0.

# Example

# With primitive type

class Model {
   @MinLength(10)
   property: number;
}
1
2
3
4

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": "string",
      "maxLength": 10
    }
  }
}
1
2
3
4
5
6
7
8
9

# With array type

class Model {
   @MinLength(10)
   @PropertyType(String)
   property: string[];
}
1
2
3
4
5

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": "array",
      "items": {
         "type": "string",
         "minLength": 10
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12

:::