Skillshub nestjs-api-standards
Response wrapping, pagination, and error standardization. Use when standardizing API response envelopes, pagination, or error formats in NestJS. (triggers: **/*.controller.ts, **/*.dto.ts, ApiResponse, Pagination, TransformInterceptor)
install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/HoangNguyen0403/agent-skills-standard/nestjs-api-standards" ~/.claude/skills/comeonoliver-skillshub-nestjs-api-standards && rm -rf "$T"
manifest:
skills/HoangNguyen0403/agent-skills-standard/nestjs-api-standards/SKILL.mdsource content
NestJS API Standards & Common Patterns
Priority: P1 (OPERATIONAL)
Standardized API response patterns and common NestJS conventions.
Generic Response Wrapper
- Concept: Standardize all successful API responses.
- Implementation: Use
to wrap data inTransformInterceptor
.{ statusCode, data, meta }
Response Mapping (Critical)
- [Rule] Zero-Entity Exposure: Controllers MUST NOT return raw ORM entities. Every endpoint must map its result to a dedicated Response DTO (e.g.,
) to prevent accidental exposure of internal fields or circular dependencies.plainToInstance(UserResponseDto, user)
Deep Validation (Critical)
- [Rule] Nested Validation: When a DTO property is an object or an array of objects, you MUST use
along with@ValidateNested()
from@Type(() => TargetDto)
to ensure deep validation.class-transformer
Pagination Standards (Pro)
- DTOs: Use strict
(page/take/order) andPageOptionsDto
(data/meta).PageDto<T> - Swagger Logic: Generics require
and schema path resolution.ApiExtraModels - Reference: See Pagination Wrapper Implementation for the complete
decorator code.ApiPaginatedResponse
Custom Error Response
- Standard Error Object: Define
withApiErrorResponse
,statusCode
,message
,error
,timestamp
. See Error Response Class.path - Docs: Apply
globally or per controller.@ApiBadRequestResponse({ type: ApiErrorResponse })
Anti-Patterns
- No raw entity returns: Always map to a Response DTO; raw entities leak internal fields.
- No unvalidated nested DTOs: Use
+@ValidateNested()
for all nested object properties.@Type() - No generic 200 docs: Apply
with exact types per endpoint.@ApiResponse({ status, type })