I’m having trouble with serving and downloading the Swagger JSON file for my API documentation. When I try to access the Swagger JSON file, it just renders the Swagger UI instead. I need the JSON file to import the API documentation into Postman.
These both the URLs just rendering swagger UI.
http://127.0.0.1:5001/nf3tix/us-central1/cloud/api-docs/swagger.json
and
http://127.0.0.1:5001/nf3tix/us-central1/cloud/api-docs/
Not sure where is it breaking.
Here is my swagger-config.js
require("dotenv").config();
const swaggerJsDoc = require("swagger-jsdoc");
const options = {
definition: {
openapi: "3.0.0",
info: {
title: "NF3TIX API Documentation",
version: "1.0.0",
description:
"REST APIs documentation for NF3TIX server running on firebase functions with expressJs",
},
servers: [
{
url: process.env.SERVER_URL,
description: "Firebase clude function APIs",
},
],
components: {
securitySchemes: {
BearerAuth: {
type: "http",
scheme: "bearer",
bearerFormat: "JWT",
},
},
},
security: [
{
BearerAuth: [],
},
],
},
apis: ["./routes/*.js"],
};
const swaggerSpec = swaggerJsDoc(options);
module.exports = swaggerSpec;
and this is my server file
const { onRequest } = require("firebase-functions/v2/https");
const logger = require("firebase-functions/logger");
const express = require("express");
const cors = require("cors");
const swaggerUi = require("swagger-ui-express");
const swaggerSpec = require("./swagger-config");
const path = require("path");
const app = express();
app.use(cors({ origin: true }));
app.use(express.json());
app.use(express.static(path.join(__dirname, "static")));
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "ejs");
app.use(
"/api-docs",
swaggerUi.serve,
swaggerUi.setup(swaggerSpec, {
swaggerOptions: { url: "/api-docs/swagger.json" },
})
);
app.use("/api", require("./routes/index"));
exports.cloud = onRequest(app);