Comments (6)
It may have something to do with the way your calling your routes to be processed by swagger-jsdoc. Relative routes should work, but what I tend to do in the base of my applications is get the PWD of the base file or if you have libraries outside of that folder that need referencing generate the PROJECT_ROOT (below are app.rootDir) to base all my globs from. This should allow the routes to generate properly. The reference below can be seen here in a koa generator I built with built-in swagger-jsdoc support.
let swaggerOptions =
{ swaggerDefinition:
{ swagger: '2.0'
, info:
{ title: 'API Explorer' // Title (required)
, version: '1.0.0' // Version (required)
, contact:
{ name: ''
, url: ''
}
}
, host: `${config.app.domain || config.app.host}:${config.app.port}`
, basePath: config.app.namespace
}
, apis:
[ app.rootDir + '/routes/**/*.js'
, app.rootDir + '/lib/**/*.js'
, app.rootDir + '/models/**/*.js'
]
};
// Initialize swagger-jsdoc -> returns validated swagger spec in json format
let swaggerSpec = swaggerJSDoc(swaggerOptions);
from swagger-jsdoc.
Hi @sitamailing,
Can you please provide some more information, as well as check other open bugs to see if you're using something that is part of a known issue?
Thanks!
from swagger-jsdoc.
My app.js exist in another folder, not in the root directory. If I put my app.js in the root folder, it works. Do I need to change the path of swagger.json or something else?
from swagger-jsdoc.
Thank you. It works for me.
from swagger-jsdoc.
So, my server configuration looks something like this -
const options = {
swaggerDefinition: {
// Like the one described here: https://swagger.io/specification/#infoObject
info: {
title: 'Test API',
version: '1.0.0',
description: 'Test Express API with autogenerated swagger doc',
},
},
apis: ['./server/abc.ts']
}
const swaggerJsdoc = require('swagger-jsdoc')
const specs = swaggerJsdoc(options);
app.get('/swagger.json', (_req, res) => {
res.send(specs)
})
app.use('/swagger', swaggerUi.serve, swaggerUi.setup(specs));
/**
* @swagger
* /loginUser:
* post:
* tags:
* - Users
* name: Login
* summary: Logs in a user
* consumes:
* - application/json
* parameters:
* - name: body
* in: body
* schema:
* $ref: '#/definitions/User'
* type: object
* properties:
* username:
* type: string
* password:
* type: string
* format: password
* required:
* - username
* - password
* responses:
* 200:
* description: User found and logged in successfully
* 401:
* description: Bad username, not found in db
* 403:
* description: Username and password don't match
*/
app.get('/test', (_req, res, _next) => {
res.send(200)
})
But after running the project, nothing is getting generated in swagger.json and the page looks like this -
{"info":{"title":"Test API","version":"1.0.0","description":"Test Express API with autogenerated swagger doc"},"swagger":"2.0","paths":{},"definitions":{},"responses":{},"parameters":{},"securityDefinitions":{},"tags":[]}
from swagger-jsdoc.
@aayushis12 please open a new issue with your code samples. If you have tried the suggestions in this issue and they do not work for you, you might want to include details what you've tried and what you've received as feedback. Otherwise, if suggestions here are not relevant to your issue: create a new issue in order to keep the topic separate.
from swagger-jsdoc.
Related Issues (20)
- editor.swagger.io gives error HOT 1
- Separate annotation to different files HOT 1
- x-webhooks generates only one entry in resulting JSON
- security vulnerability in [email protected] dependency [email protected] HOT 1
- Wrong "Supported Specifications" list in the README HOT 1
- Where are the update notes? HOT 3
- remove lodash.mergewith End of life lib and use alternative HOT 3
- Vulnerability with dependency [email protected] HOT 6
- Display custom headers in resuable way (Components/parameters) with different field for each header in swagger ui express HOT 7
- Proper way to ignore or exclude specific files from `apis` HOT 2
- Critical dependency: the request of a dependency is an expression HOT 4
- I would like to be able to pass a flag to the cli tool to fail if errors are found HOT 1
- Please update the 'yaml' dependency version to 2.1.0 to fix CVE-2023-2251 Vulnerability HOT 3
- totally does not load on production HOT 1
- Is it possible to generate a swagger.json file? HOT 3
- TypeError: s is not a constructor (using DENO) HOT 1
- Find alternative for concat-map as it is EOL HOT 3
- Update brace-expansion/1.1.11 as it is marked as EOL HOT 3
- Globbing a directory that looks like a file causes crash. HOT 2
- TypeError when using swagger-jsdoc with lint-staged installed HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from swagger-jsdoc.