In Express app, I've created swagger autogen tags.
In this place this setup does not work, because description and schema fields from response are in parameters in output. I'm using "swagger-autogen": "2.23.1". This error appears in some controllers, in other not. I can delete #swagger.responses[200] part, but then there is no body in file.
export const getDiary = async (req: Request, res: Response) => {
/*
#swagger.tags = ['Diary']
#swagger.description = 'Get all Diary entries'
#swagger.parameters['date'] = {
in: 'query',
description: 'Date of diary entry',
required: false,
}
#swagger.responses[200] = {
description: 'Diary entries successfully obtained',
schema: { $ref: '#/definitions/DiaryResponse'}
}
*/
let { date } = req.query;
const mappedRows = date
? await DiaryService.getAllDiaryEntriesByDate(date as string)
: await DiaryService.getAllDiaryEntries();
let response: HttpResponse<Diary[]> = {
data: mappedRows,
length: mappedRows.length,
};
return res.status(RESPONSE_CODES.OK).send(response);
};
generated swagger
"/api/diary/": {
"get": {
"tags": [
"Diary"
],
"description": "Get all Diary entries",
"parameters": [
{
"name": "date",
"in": "query",
"description": "Date of diary entry",
"required": false,
"type": "string"
},
{
"name": "description", // this should not be here
"in": "query",
"type": "string"
},
{
"name": "schema", // this should not be here
"in": "query",
"type": "string"
}
],
Solution is to add.
Then description and schema from responses are ignored as a parameters and generated file is fixed. Whole solution