I have a simple rest API that works with Koa and MySQL and now I want to add some swagger documentation, I have done the first part of the api-docs route works however it doesn’t seem to be able to load the options I defined.
I expect it to load the option and the annotations I defined
Thanks a lot in advance and a happy new year 😀
**login.ts**
import { verifyLogin, verifyCaptcha } from "../middlewares/login.middleware"
import LoginController from "../controller/login.controller"
const KoaRouter = require('@koa/router')
const loginRouter = new KoaRouter({
prefix: '/login'
})
/**
* @swagger
* /login:
* post:
* description: User Login
* responses:
* '200':
* description: Successfully login
* '500':
* description: Bad Request
* parameters:
* - name: username
* in: body
* required: true
* schema:
* type: string
* format: string
* - password: password
* in: body
* required: true
* schema:
* type: string
* format: string
* - code: code
* in: body
* required: true
* schema:
* type: string
* format: string
*/
loginRouter.post('/', verifyLogin, verifyCaptcha, LoginController.generateToken)
export default loginRouter
**swagger.ts**
const path = require('path');
const KoaRouter = require('@koa/router')
const swaggerJsdoc = require('swagger-jsdoc');
import { koaSwagger } from 'koa2-swagger-ui';
const options = {
swaggerDefinition: {
openapi: '3.0.0',
info: {
title: 'My API',
version: '1.0.0',
description: 'This is a sample server',
},
},
apis: [path.join(__dirname, '../router/*.ts')],
};
const swaggerDocs = swaggerJsdoc(options);
const docsRouter = new KoaRouter({
prefix: '/api'
})
docsRouter.get('/docs', koaSwagger({ routePrefix: false, swaggerOptions: { swaggerDocs } }))
export default docsRouter
This is what happens when the console prints