# Decorator UniqueItems
Decorator validation swagger schema input collectionsModule | import { UniqueItems } from "@tsed/schema" |
---|---|
Source | /packages/schema/src/decorators/collections/uniqueItems.ts |
# Overview
function UniqueItems(uniqueItems?: boolean): (...args: any[]) => any;
# Description
If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.
WARNING
For v6 user, use UniqueItems from @tsed/schema instead of @tsed/common.
# Example
class Model {
@UniqueItems() // default true
property: number[];
}
1
2
3
4
2
3
4
class Model {
@CollectionOf(String)
@UniqueItems()
property: string[];
}
1
2
3
4
5
2
3
4
5
Will produce:
{
"type": "object",
"properties": {
"property": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string"
}
}
}
}
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Other topics
- Session & cookies
- Passport.js
- TypeORM
- Mongoose
- GraphQL
- Socket.io
- Swagger
- AJV
- Multer
- Serve static files
- Templating
- Throw HTTP Exceptions
- Customize 404
- AWS
- Seq
- OIDC
- Stripe
- Controllers
- Providers
- Model
- JsonMapper
- Middlewares
- Pipes
- Interceptors
- Authentication
- Hooks
- Exceptions
- Hooks
- Response Filter
- Injection scopes
- Custom providers
- Custom endpoint decorator
- Testing