ts-deco
v1.0.36
Published
TypeScript decorator utilities for Node.js with strict validation standards
Downloads
336
Maintainers
Readme
ts-deco
검증과 Swagger 작성을 동시에 처리하는 함축적인 데코레이터 라이브러리
TypeScript decorator utilities with strict validation standards and automatic Swagger documentation
하나의 데코레이터로 타입 검증과 Swagger API 문서화를 동시에 처리하는 Node.js/TypeScript용 DTO 데코레이터 라이브러리입니다.
NestJS와 Node.js (Express, Fastify 등) 모든 프로젝트에서 사용할 수 있습니다.
설치
npm install ts-deco빠른 시작
DTO 검증 + Swagger 문서화
Property 데코레이터 하나로 타입 검증과 Swagger 문서 작성을 동시에 처리할 수 있습니다:
import { Property } from "ts-deco";
class CreateUserDto {
@Property({
type: String,
optional: false,
description: "사용자 이름",
example: "홍길동",
})
name: string;
@Property({ type: Number, min: 0, max: 120, optional: false })
age: number;
}Controller Swagger 문서화
Resource와 Endpoint로 Controller 문서화를 한 번에 처리할 수 있습니다:
import { Resource, Endpoint } from "ts-deco";
@Resource("Users", "/api/users")
export class UserController {
@Endpoint({
method: "POST",
summary: "사용자 생성",
tags: ["Users"],
body: { type: CreateUserDto, required: true },
responses: [
{ status: 201, description: "생성 성공" },
{ status: 400, description: "Validation 실패" },
],
})
@Post()
create(@Body() dto: CreateUserDto) {}
}주요 기능
- ✅ 함축적: 하나의 데코레이터로 검증과 Swagger 문서화 동시 처리
- ✅ 간결함: 코드 중복 제거, 가독성 향상
- ✅ 타입 안전성: 엄격한 타입 체크로 컴파일 타임 에러 방지
- ✅ 자동 문서화: Swagger API 문서 자동 생성
- ✅ 호환성: NestJS와 Node.js (Express, Fastify 등) 모두 지원
- ✅ 런타임 안정성: 명확한 에러 메시지 제공
문서
| 문서 | 내용 |
| --------------------------------------------- | ------------------------------------------------------------ |
| Property 데코레이터 | Property 데코레이터 사용법, 옵션 레퍼런스, 검증 동작 방식 |
| 개별 데코레이터 | DtoString, DtoNumber, DtoDate, DtoBoolean, DtoEnum |
| Controller 데코레이터 | Resource, Endpoint, DocTags, DocOperation 등 |
| 사용 예제 | NestJS, Express 전체 예제 |
| 설치 및 환경 | 의존성, 지원 환경, tsconfig 설정 |
라이선스
ISC License
