Skip to main content

DTO Definition

Basic Structure

dto:
DTOName:
meta: dto [annotations]
fields:
fieldName: fieldType [annotations]

Meta Annotations

  • @template(EntityName): Specify the base entity
  • @searchable(entity=EntityName, pageSize=n): Search DTO

Field Annotations

  • @ref(fieldPath): Reference to source field (supports nested references)
  • --: Exclude field (when using templates)

DTO Examples

dto:
ArticleDTO:
meta: dto @template(Article)
fields:
boardName: string @ref(board.name) -- Board name
boardType: BoardType @ref(board.boardType) -- Board type
createDate: -- # Excluded from template

ArticleSearchDTO:
meta: dto @searchable(entity=Article, pageSize=50)
fields:
title: string @search(like) -- Title search
boardType: List<BoardType> @search(in) @ref(board.boardType) -- Board type
createDateFrom: date @search(between) -- Creation date start
createDateTo: date @search(between) -- Creation date end

Template Inheritance

Multiple Template Inheritance

dto:
CarProfileInfoDTO:
meta: dto @template(CarProfileDTO,CarInfoDTO)
fields:
additionalInfo: string -- Additional info

You can combine multiple DTOs to create a new DTO. Specify multiple templates separated by commas in the @template annotation.

Search DTO Details

@searchable Annotation

dto:
ArticleSearchDTO:
meta: dto @searchable(entity=Article, pageSize=50)
# or
meta: dto @searchable(entity=Article, pageSize=50, pageable=true)

Parameters:

  • entity: Target entity name (required)
  • pageSize: Page size (default: 100)
  • pageable: Enable pagination (default: true, automatically enabled when pageSize is specified)

Auto-generated Fields:

  • pageNumber: Page number (default: 0)
  • pageSize: Page size (configured value)
  • sortCode: Sort field name

Field Reference (@ref)

Used to retrieve field values from related entities in DTOs.

# When the entity has a field defined as board: Board
boardName: string @ref(board.name) # Simple reference
boardTypeName: string @ref(board.boardType.name) # Nested reference

DTO Type Specification (@dtype)

articles: List<Article> @dtype(List<ArticleDTO>)
  • Specifies the type to use when converting to DTOs
  • Prevents circular references and ensures type safety

Naming Conventions

DTOs

  • Class name: EntityName + "DTO" (BoardDTO, ArticleDTO)
  • Search DTO: EntityName + "SearchDTO" (ArticleSearchDTO)
tip

For more detailed information on annotations, see Annotation Guide.