# MaxLength Decorator validation swagger schema
Module | import { MaxLength } from "@tsed/common" |
---|---|
Source | /packages/common/src/jsonschema/decorators/maxLength.ts |
# Overview
function MaxLength(maxLength: number): (...parameters: any[]) => any;
Param | Type | Description |
---|---|---|
maxLength | number | The maximum length allowed |
# 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 maxLength MUST be a non-negative integer.
TIP
Omitting this keyword has the same behavior as a value of 0.
WARNING
This decorator will be removed in v7. For v6 user, use from @tsed/schema instead of @tsed/common.
# Example
# With primitive type
class Model {
@MaxLength(10)
property: number;
}
1
2
3
4
2
3
4
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "string",
"maxLength": 10
}
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# With array type
class Model {
@MaxLength(10)
@CollectionOf(String)
property: string[];
}
1
2
3
4
5
2
3
4
5
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "array",
"items": {
"type": "string",
"maxLength": 10
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Jest
- Seq
- Controllers
- Providers
- Model
- Converters
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing