Skip to content

Default

@tsed/schema

Usage

typescript
import { Default } from "@tsed/schema";

See /packages/specs/schema/src/types/decorators/common/default.ts.

Overview

ts
function Default(defaultValue: JSONSchema6Type | undefined | (() => JSONSchema6Type)): (...args: any[]) => any;

Description

There are no restrictions placed on the value of this keyword.

WARNING

For v6 user, use Default from @tsed/schema instead of @tsed/platform-http.

This keyword can be used to supply a default JSON value associated with a particular schema. It is RECOMMENDED that a default value be valid against the associated schema.

Example

typescript
class Model {
   @Default("10")
   property: string = "10";
}

Will produce:

json
{
  "type": "object",
  "properties": {
    "property": {
      "type": "string",
      "default": "10"
    }
  }
}

Released under the MIT License.