# Format Decorator

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). date, time and date-time validate ranges in full mode and only regexp in fast mode (see options).
  • uri: full uri with optional protocol.
  • url: URL record.
  • uri-template: URI template according to RFC6570
  • 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.
  • uuid: Universally Unique IDentifier according to RFC4122.
  • json-pointer: JSON-pointer according to RFC6901.
  • relative-json-pointer: relative JSON-pointer according to this draft.

# 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")
   @PropertyType(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