Express server experiencing issues with generating Swagger documentation

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!

Answer №1

After searching extensively, I came across a Github issue that provided the perfect solution for my problem.

Visit the GitHub page here

Answer №2

Dealing with a similar issue here. Mine pertains to JavaScript rather than TypeScript. The error stemmed from the paths I had defined for my routes.

const options = {
  swaggerDefinition,
  apis: ["./routes/*.js"],
};

I suspect the problem arose because the wildcard path didn't align with my actual routes.

To rectify this, I specified the exact path needed.

const options = {
  swaggerDefinition,
  apis: ["./routes/users/userRoutes.js"],
};

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The image will come to life with animation as the background position is adjusted using Skrollr

Trying to create a div that switches the background image every X pixels scrolled. Initially experimented with changing the background-image, including using sprites and adjusting background position, but encountered a distracting "flickering" effect. Exa ...

Building the logic context using NodeJS, SocketIO, and Express for development

Exploring the world of Express and SocketIO has been quite an eye-opener for me. It's surprising how most examples you come across simply involve transmitting a "Hello" directly from app.js. However, reality is far more complex than that. I've hi ...

Utilize npm node to dynamically adjust screen resolution

Currently developing a game using electron. I'm experiencing FPS drops when running it in full-screen mode. To improve the game's performance, I need to change the screen resolution programmatically. My current resolution is 1280x800, but I would ...

transmit data from Node.js Express to Angular application

I am making a request to an OTP API from my Node.js application. The goal is to pass the response from the OTP API to my Angular app. Here is how the API service looks on Angular: sendOtp(params): Observable<any> { return this.apiService.post(&q ...

The pop-up box triggered by Onbeforeunload will not be displayed

Currently, I am in the process of developing a website that includes user profiles. At this stage, I am focusing on the image upload functionality. When a user successfully uploads an image, it is stored in four different folders: one for size 25, 100, 150 ...

Could there be any concerns with simultaneous connections to a Node.js application hosted behind nginx?

I've been trying to determine if there are any potential issues with simultaneous connections to an upstream server in nginx. My nginx configuration follows the standard setup: upstream nodejs_app { server 127.0.0.1:3000; } server { listen 80; ...

Utilize PHP SVG images to trigger internal JavaScript code through the <img> tag

Here is a php function that generates an SVG image. public function actionJsTest() { header('Content-Type: image/svg+xml'); $svg = ''; $svg .= '<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/ ...

Tips for invoking the href function in jwplayer with individual arguments

I need assistance with configuring jwplayer to load a list of href links one by one. Each href link includes a function that needs to be triggered automatically with specific parameters passed to JavaScript. Below is the code snippet I am currently worki ...

Enhance jQuery dataTable with live updates from Firestore querySnapshot

Currently, I have implemented jQuery dataTable in my project to display data from Firestore. While everything seems to be working fine, an alert keeps popping up in the browser whenever there is an update in the Firestore data: DataTables warning: table i ...

Is it possible to execute the .push() method on an array a specific number of times without using a for loop?

Currently, I am tackling the "Move Zeroes" Leetcode challenge. The task requires moving all zeroes to the end of the array without altering the sequence of non-zero elements. My strategy involves iterating through the array, splicing out each zero encounte ...

Node.js command-line interface for chat application

Can someone help me figure out the best method for creating a command line interface chat app using nodejs? I'm considering using http and possibly phantomjs to display it in the terminal, but I have a feeling there's a more efficient approach. A ...

Nested Promises in Angular's $q Library

I'm facing an issue with a function that should return a list of favorite locations. Here's the code snippet in question: When I call LocationsFactory.getFavoriteLocations(), it returns a promise like this: getFavoriteLocations: function() { ...

Combine PHP, jQuery, and AJAX to retrieve multiple values simultaneously

I have been using jQuery AJAX for my projects. When I make an AJAX call to a PHP page, it normally returns a single value to the success function of AJAX. However, I am now looking to retrieve multiple data individually. How can I achieve this? This is th ...

What is the method for utilizing an alias at the top within a subquery?

Is it possible to use an alias from the top query in a subquery? I am currently encountering an error with 'artc'. let myQuery = this.articles.createQueryBuilder('artc') .select(['artc.title']) .addSelect(qb => ...

Connecting a button's action to a specific element in an array using AJAX and Firebase

I am currently working on a project that involves making an AJAX request from a social API and then appending the results with a button inside the div. This button is meant to save the corresponding item in the array to my Firebase database. For brevity, ...

Tips for configuring VS Code to automatically change a callable property to an arrow function instead of a standard function

When interacting with ts/tsx files in VS Code, the autocompletion feature for callable properties offers two options: propertyName and propertyName(args): https://i.sstatic.net/BFVTm.png However, selecting the second option generates a standard function: ...

Finding your way through Bootstrap Datepicker using the Previous and Next Buttons

Is there a way to implement Previous and Next Button functionality for navigating a Bootstrap Datepicker using jQuery, similar to the illustration below? https://i.sstatic.net/e9I7P.png I attempted the following approach: function PrevNext(isnextbtn) ...

Use javascript to modify a specific section of a link

I have a set of datatable rows with links that contain data, and I need to modify part of the link text. For instance, if the link is 200.0.0.10, I want to change it to 160.11.10.12. Despite attempting the following code, the link does not change: var ...

Steps to turn off the automatic completion feature for orders in WooCommerce on your WordPress website

Looking for assistance with changing the order status from completed to processing. When an order is placed, it automatically goes to completed status which is not the desired outcome. The status should change based on the virtual product purchased. I wou ...

When using React Ant Design, the form.resetFields() function does not trigger the onChange event of the Form.Items component

In my project, I am working with the Ant Design <Form> component and handling onChange events within <Form.Items>. Whenever the onChange event function evaluates to true, additional content is displayed dynamically. For instance, in the code s ...