scottie1984 / swagger-ui-express

Adds middleware to your express app to serve the Swagger UI bound to your Swagger document. This acts as living documentation for your API hosted from within your app.
MIT License
1.42k stars 225 forks source link

No operations defined in spec! #248

Closed Diex closed 2 years ago

Diex commented 3 years ago

using js-docs it renders no path doc at all. just a message: "No operations defined in spec!"

pkgs: "swagger-jsdoc": "^6.0.0", "swagger-ui-express": "^4.1.6" node10

config goes like this:

`

  const swaggerDefinition = {
  basePath: '/',
  openapi: '3.0.0',
  info: {
    version: '1.0.0',
    title: 'My API',
    description: 'Loading and retrieving  data from firebase firestore'
  },
  servers: [
    { url: 'http://localhost:5001/myapi/api/v1/' },
  ],
};

const swaggerOptions = {
  swaggerDefinition,
  apis: ['./**/*.ts'],
};
const swaggerDocs = swaggerJsDoc(swaggerOptions);

app.use('/api-docs', swaggerUi.serve);
app.get('/api-docs', swaggerUi.setup(swaggerDocs, { explorer: true }));

'swaggerDocs' looks like this:

  {
    basePath: '/',
    openapi: '3.0.0',
    info: {
      version: '1.0.0',
      title: 'My API',
      description: 'Loading and retrieving  data from firebase firestore'
    },
    servers: [
      { url: 'http://localhost:5001/myapi/api/v1/' }
    ],
    paths: {
      path: {
        '/artists/': [Object],
        '/artists/page/:page': [Object],
        '/artists/:id/': [Object],
        '/artists/:id': [Object],
        '/artists/tags/': [Object],
        '/catalogs/': [Object],
        '/medias/:id': [Object],
        '/medias/rendered/all': [Object],
        '/medias/': [Object],
        '/medias': [Object],
        'medias/:id/': [Object],
        '/medias/tags/': [Object],
        ':user/playlist/': [Object],
        'playlist/:id/': [Object],
        'playlist/:user': [Object],
        '/playlist/:playlist/:id/add/': [Object],
        '/playlist/:playlist/:id/remove/': [Object],
        '/tags/': [Object],
        '/tags/:id': [Object],
        'users/:user/:category/liked/': [Object],
        'users/:user/liked/': [Object],
        '/users/:user': [Object],
        '/me': [Object],
      }
    },
    components: {},
    tags: []
  }

any thoughts?

thx

scottie1984 commented 2 years ago

Please look at regarding swagger-jsdoc and openapi 3.0

https://github.com/scottie1984/swagger-ui-express/issues/189#issuecomment-738986346

Codehouze commented 9 months ago

This issue is caused by the way the route is referenced. The referencing must always start from the root of your application. So './routes/abc.js' must be changed to 'the-folder-name-in-root/routes/abc.js'

rpitreeni commented 2 months ago

This issue is caused by the way the route is referenced. The referencing must always start from the root of your application. So './routes/abc.js' must be changed to 'the-folder-name-in-root/routes/abc.js'

changes like "./the-folder-name-in-root/routes/abc.js"