# Ignore Decorator validation swagger schema

Module
import { Ignore } from "@tsed/schema"
Source/packages/schema/src/decorators/common/ignore.ts

# Overview

function Ignore(cb?: boolean | IgnoreCallback): (...args: any[]) => any;
Param Type Description
cb boolean "|" IgnoreCallback Optional. Callback to know if the property must be ignored

# Description

Ignore the property when JsonMapper serialize the class to a Plain Object JavaScript.

WARNING

Swagger will not generate documentation for the ignored property.

class User {
  @Ignore()
  _id: string;

  @Property()
  firstName: string;

  @Property()
  lastName: string;

  @Ignore((value, ctx) => !ctx.mongoose) // don't ignore prop only if mongoose
  password: string;
}
1
2
3
4
5
6
7
8
9
10
11
12
13

The controller:

import {Post, Controller, BodyParams} from "@tsed/common";
import {Person} from "../models/Person";

@Controller("/")
export class UsersCtrl {
  @Get("/")
  get(): User {
    const user = new User();
    user._id = "12345";
    user.firstName = "John";
    user.lastName = "Doe";
    user.password = "secretpassword";
    return
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

The expected json object:

{
 "firstName": "John",
 "lastName": "Doe"
}
1
2
3
4

Other topics