I've been working on an Express API and decided to implement documentation using Swagger and JSDoc. However, the documentation is not working as expected. Here's how I've set it up:
docs.ts:
import swaggerJSDoc, { Options } from "swagger-jsdoc";
const swaggerOptions: Options = {
definition: {
info: {
title: "Project Nonya Documentation.",
description: "Documentation for the Project Nonya API",
contact: {
name: "Joe Mama",
},
version: "6.9.0",
},
},
apis: ["./routes/*.routes.ts"],
};
export const swaggerDocs = swaggerJSDoc(swaggerOptions);
router.ts:
...
import swaggerUi from "swagger-ui-express";
import { swaggerDocs } from "./docs";
...
app.use("/api/documentation", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
...
Despite accessing the docs endpoint, I keep receiving a No Operations defined in spec!
message. One of the files in the routes folder is as follows:
testing.routes.ts:
import express, { Router } from "express";
import { testing} from "../controllers/testing/testing.controller";
const router: Router = express.Router();
/**
* @swagger
* /:
* get:
* description: Why you no work?
* responses:
* 200:
* description: Returns nothing cause this won't work.
*/
router.post("/testing/:id", testing);
export default router;
I'm struggling to identify what I'm doing incorrectly. My file directories are as follows: src/docs.ts
, src/router.ts
, and src/routes/testing.router.ts
.
Side Question:
Since I am using TypeScript and need to compile to JavaScript, should I adjust the file specifications in the apis
array in docs.ts
from *.routes.ts
to *routes.js
?
Thank you for your help!