# Format Decorator validation swagger schema input

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

# Overview

function Format(format: string): (...parameters: any[]) => any;

# Description

The following formats are supported for string validation with format keyword:

  • date: full-date according to RFC3339.
  • time: time with optional time-zone.
  • date-time: date-time from the same source (time-zone is mandatory).
  • uri: full uri with optional protocol.
  • email: email address.
  • hostname: host name according to RFC1034.
  • ipv4: IP address v4.
  • ipv6: IP address v6.
  • regex: tests whether a string is a valid regular expression by passing it to RegExp constructor.

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 {
   @Format("email")
   property: string;
}
1
2
3
4
{
  "type": "object",
  "properties": {
    "property": {
      "type": "string",
      "format": "email"
    }
  }
}
1
2
3
4
5
6
7
8
9

# With array type

class Model {
   @Format("email")
   @CollectionOf(String)
   property: string[];
}
1
2
3
4
5

Will produce:

{
  "type": "object",
  "properties": {
    "property": {
      "type": "array",
      "items": {
         "type": "string",
         "format": "email"
      }
    }
  }
}
1
2
3
4
5
6
7
8
9
10
11
12