Files
What you'll learn
- Derive DTOs with PartialType, PickType, OmitType and IntersectionType from @nestjs/swagger, which carry both the document's and class-validator's metadata, and compose them
- Keep a property out of a schema with @ApiHideProperty and a route out of the document with @ApiExcludeEndpoint (or a controller with @ApiExcludeController), while the app keeps serving them
- Serve more than one specification from one app with createDocument's include option and a second setup path
- Say what the Nest CLI's Swagger plugin would add at build time, and why this browser, like ts-jest or plain tsc, compiles without it
Press Run tests to start the app. Its log appears here.Graded endpoints
PartialType makes every property optional (no required list); PickType keeps only age; OmitType drops nicknames and IntersectionType adds foundAt. Each keeps the source's examples and bounds
The update, the birthday and the intake reference their derived schemas; the summaries and response models from before are still there
@ApiHideProperty keeps internalNote out of the Cat schema, @ApiExcludeEndpoint keeps the internal-note route out, and include: [CatsModule] keeps the internal module's routes out; foundAt is in
A second document, built with include: [InternalModule], lists only the internal routes, under their own tag, and nothing about cats
setup('api/internal', ...) serves a Swagger UI page there too, loading its own init script
The answer is what a reader may see: no internalNote, even though the column exists
The composed DTO: CreateCatDto's fields without nicknames, plus where the cat was found
IntersectionType kept IntakeNotesDto's validator: foundAt is required
PartialType made every field optional; the two given are applied
PartialType keeps the validators: an age that is not an integer is still refused
PickType kept only age; the whitelist strips the name that was sent along
PickType kept the @Min(0) that came with age
Excluded from the document, not from the app
select: false on the column, @ApiHideProperty on the schema: the reader sees neither
A route the public document does not list, answering as ever
The internal document's other route: it counts through its own repository of the shared entity
204 with no body
The count follows the delete