Surnet / swagger-jsdoc

Generates swagger/openapi specification based on jsDoc comments and YAML files.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger jsdoc not reading api's path and not generating api's after deployment with next js

devanshsinghvaluecoders opened this issue · comments

this is the docs file.

import React from "react";
import swaggerJSDoc from "swagger-jsdoc";
import SwaggerUI from "swagger-ui-react";
import "swagger-ui-react/swagger-ui.css";
import { join } from "path";

// import { join } from '';
function createSwaggerSpec({
openApiVersion = "3.0.0",
title,
version,
apiFolder = "pages/api",
}) {
const apiDirectory = join(process.cwd(), apiFolder);
const directy = join(__dirname, apiFolder);
const options = {
definition: {
openapi: openApiVersion,
info: {
title,
version,
},
servers: [
{
url: "http://localhost:3000",
description: "Development server",
},
{
url: "https://go-regi.com",
description: "Production server",
},
],
},

apis: [
  `${apiDirectory}/about.js`,
  `${directy}/about.js`,
  `/api/about.js`,
  `./api/about.js`,
  `./pages/api/about.js`,

  `/pages/api/about.js`,
], // files containing annotations as above

};

return swaggerJSDoc(options);
}

const Doc = ({ spec, classes }) => {
return (
<>


<div /* className={classes.container} */>



</>
);
};

export const getServerSideProps = async (ctx) => {
const spec = createSwaggerSpec({
title: "Go-regi.com API",
version: "3.0.0",
});
return {
props: {
spec,
},
};
};

export default Doc;

and one the api's

/**

  • @Swagger
  • /api/auth:
  • post:
  • summary: Login (By Email and Password).
    
  • tags:
    
  •   - User
    
  • requestBody:
    
  •   required: true
    
  •   content:
    
  •     application/json:
    
  •       schema:
    
  •         type: object
    
  •         properties:
    
  •           email:
    
  •             type: string
    
  •             example: devanshsingh0808@gmail.com
    
  •           password:
    
  •             type: string
    
  •             example: NopB1597@
    
  • responses:
    
  •   200:
    
  •     description: User Details
    
  •     content:
    
  •       application/json:
    
  •         schema:
    
  •           type: object
    
  •           properties:
    
  •             token:
    
  •               type: string
    
  •               description: user token id
    
  •             user:
    
  •               type: object
    
  •               description: user details
    
  •               properties:
    
  •                 _id:
    
  •                   type: string
    
  •                 id:
    
  •                   type: number
    
  •                 firstName:
    
  •                   type: string
    
  •                 lastname:
    
  •                   type: string
    
  •                 email:
    
  •                   type: string
    
  •                 verified:
    
  •                   type: boolean
    
  •                 role:
    
  •                   type: array
    
  •                   description: type of user
    
  •                   items:
    
  •                     type: string
    
  •                 type:
    
  •                   type: string
    
  •                 provider:
    
  •                   type: string
    
  •                 created_at:
    
  •                   type: string
    
  •                 modified_at:
    
  •                   type: string
    
  •                 loginAttempt:
    
  •                   type: number
    
  •                 settings:
    
  •                   type: object
    
  •                   properties:
    
  •                     advertisementSettings:
    
  •                       type: boolean
    
  •                     automaticallyApplyCoupons:
    
  •                       type: boolean
    
  •                     findLowestCostItem:
    
  •                       type: boolean
    
  •                     alertofSlipperyFloors:
    
  •                       type: boolean
    
  •                     ratings:
    
  •                       type: boolean
    
  •                     budgetLimit:
    
  •                       type: boolean
    
  •                     updatedAt:
    
  •                       type: string
    
  •                 dwollaCustomerID:
    
  •                   type: string
    
  •                 stripeCustomerID:
    
  •                   type: string
    
  •   401:
    
  •     description: Access token is missing or invalid
    

*/

this code working perfectly on local server but no api's visible after deployment.
Capture

Hi, @devanshsinghvaluecoders

Can you format your issue to be able to read it? You can follow this guide to do it. https://www.freecodecamp.org/news/how-to-format-code-in-markdown/

Also, since you said that the API is generated local but on production don't, seems that the problem could be with the production environment.

Do you have log files for production?

How can you provide more information about it?

We would like to see a repo replicating the problem to be easier to understand what is happening and help you faster.

Provide a code example since we cannot reproduce your error without it.