# Const Decorator validation swagger schema
Module | import { Const } from "@tsed/common" |
---|---|
Source | /packages/common/src/jsonschema/decorators/const.ts |
# Overview
function Const(constValue: JSONSchema6Type | any): (...parameters: any[]) => any;
# Description
The const keyword is used to restrict a value to a fixed value.
WARNING
This decorator will be removed in v7. For v6 user, use from @tsed/schema instead of @tsed/common.
# Example
# With a string
class Model {
@Const("value1")
property: "value1";
}
1
2
3
4
2
3
4
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "string",
"const": "value1"
}
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
# With a boolean
class Model {
@Const(true)
property: boolean;
}
1
2
3
4
2
3
4
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "boolean",
"const": true
}
}
}
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
- 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