Files
What you'll learn
- Put Schema Object keywords (description, example, minimum, default) on a property with @ApiProperty's options, and rename or describe a schema with @ApiSchema
- Document an enum, and give it a schema of its own with enumName so generated clients share one type
- Describe an array property with type: [String], and an array body with @ApiBody, because TypeScript keeps no metadata for either
- Describe query and path parameters beyond what the scanner infers, with @ApiQuery and @ApiParam
Press Run tests to start the app. Its log appears here.Graded endpoints
@ApiSchema renames CreateCatDto to NewCat in the document and gives it a description; the request body's $ref follows the new name
The options given to @ApiProperty land on the Schema Object: name has an example and a description, age a description, a minimum and a default
enumName turns Breed into a reusable schema listing the three values, and the breed property references it instead of repeating them
type: [String] documents nicknames as an array of strings; TypeScript's metadata only says Array
@ApiQuery makes the breed filter optional with the enum's values; @ApiParam adds a description to the id the scanner already found
@ApiBody({ type: [CreateCatDto] }) documents POST /cats/bulk as an array whose items reference the schema
The API accepts what the document describes
ParseArrayPipe validates each item of the array body
The optional query parameter narrows the list
The document lists three values; ParseEnumPipe is what refuses a fourth
The second item's age is a string; the error names the item that failed
The delete route is unchanged by any of this
The only Siamese is gone