# AllowTypes Decorator schema swagger validation deprecated

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

# Overview

function AllowTypes(type: JSONSchema6TypeName, ...types: JSONSchema6TypeName[]): (...parameters: any[]) => any;

# Description

Set the type of the array items.

WARNING

This decorator will be removed in v7. For v6 user, use from @tsed/schema instead of from @tsed/common.

# Example

# With multiple types

class Model {
   @AllowTypes("string", "number", "boolean", "array")
   property: "string" | "number" | "boolean" | "array";
}
1
2
3
4

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": ["string", "number", "boolean", "array"]
    }
  }
}
1
2
3
4
5
6
7
8

# With array of multiple types

class Model {
   @AllowTypes("string", "number", "boolean", "array")
   property: ("string" | "number" | "boolean" | "array")[];
}
1
2
3
4

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": "array",
      "items": {
         "type": ["string", "number", "boolean", "array"]
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11