Mitul_Kheni
10 months agoNew Member
Use $ref in examples
I am building an update API in nest js and I want to document my API. In this update API I have different types of users and based on those users I have different properties (some properties are common across all type of users).
I want to use those DTOs as an example for those different users. Can I do that?
The examples code:
export const updateDirectoryExample = Object.freeze({
sample_1: {
summary: 'Contractor',
// value: {},
$ref: '../dto/update-contractor.dto.ts',
},
sample_2: {
summary: 'Vendor',
// value: {},
$ref: '../dto/update-vendor.dto.ts',
},
});
Nest js controller code:
@ApiOkResponse({
type: UpdateDirectoryResDto,
})
@ApiBody({
type: UpdateDirectoryDto,
examples: updateDirectoryExample,
})
updateDirectory(
@AuthUser() reqUserDetails: IRequestUserDetails,
@Body() body: UpdateDirectoryDto,
@Req() request: Request,
) {
return this.directoryService.updateDirectory(reqUserDetails, body, request);
}