# Maximum Decorator validation swagger schema
Module | import { Maximum } from "@tsed/common" |
---|---|
Source | /packages/common/src/jsonschema/decorators/maximum.ts |
# Overview
function Maximum(maximum: number, exclusive?: boolean): (...parameters: any[]) => any;
Param | Type | Description |
---|---|---|
maximum | number | The maximum value allowed exclusive |
# Description
The value of maximum
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 less than or exactly equal to maximum
.
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 {
@Maximum(10)
property: number;
}
1
2
3
4
2
3
4
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "number",
"maximum": 10
}
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# With array type
class Model {
@Maximum(10)
@CollectionOf(Number)
property: number[];
}
1
2
3
4
5
2
3
4
5
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "array",
"items": {
"type": "number",
"maximum": 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