# GenericOf Decorator validation swagger schema input generics

Module
import { GenericOf } from "@tsed/schema"
Source/packages/schema/src/decorators/generics/genericOf.ts

# Overview

function GenericOf(...generics: Type<any>[]): GenericOfChainedDecorators;

# Description

Set the types of a Generic class.

# Example

class Product {
  @Property()
  label: string;
}

@Generics("T")
class Paginated<T> {
  @CollectionOf("T")
  data: T[];

  @Property()
  totalCount: number;
}

class Payload {
   @GenericOf(Product)
   products: Paginated<Product>;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# Example with nested generics

class Product {
  @Property()
  label: string;
}

@Generics("T")
class Paginated<T> {
  @CollectionOf("T")
  data: T[];

  @Property()
  totalCount: number;
}

@Generics("D")
class Submission<D> {
  @Property()
  _id: string;

  @Property("D")
  data: D;
}

class Payload {
   @GenericOf(Submissions).Nested(Product)
   submissions: Paginated<Submission<Product>>;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

Other topics