hola amigos, no me funciona swagger en aws sabian, alguien me ayuda

0

aca esta el codigo: const swaggerJSDoc = require('swagger-jsdoc'); const swaggerUi = require('swagger-ui-express');

const options = { definition: { openapi: '3.0.0', info: { title: 'Blog Appi', version: '1.0.0',

    }
},
apis: ['./routes/auth.routes.js', './models/user.model.js','./routes/post.routes.js','./models/post.model.js','./routes/comment.routes.js','./models/comment.model.js','./routes/user.routes.js','./models/user.model.js','./sockets/index.js']

};

const swaggerSpec = swaggerJSDoc(options)

const swaggerDocs=(app, port)=>{ app.use('/api/v1/docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec)); app.get('/api/v1/docs.js', (req, res)=>{ res.setHeader('Content-type', 'application/json') res.send(swaggerSpec) }) console.log(Docs are avalible at http://localhost:${port}/api/v1/docs) }

module.exports=swaggerDocs;

1 回答
0
已接受的回答

English:

Your code seems to be fine in general, but there are a couple of things I would like to point out.

  1. Make sure all your file paths are correct. The most common errors usually come from incorrect file paths in the Swagger options. Verify that all the paths in the apis option are correct.

  2. The last console.log is not formatted correctly. It needs to be inside the reverse quotes (` `) so you can use string interpolation with ${port}. Here is the fix:

console.log(`Docs are available at http://localhost:${port}/api/v1/docs`);

If you continue to experience problems, it would be helpful to have more information about the errors you are getting. Are you getting any particular error messages?

Spanish:

Tu código parece estar bien en general, pero hay un par de cosas que me gustaría resaltar.

  1. Asegúrate de que todas las rutas de tus archivos estén correctas. Los errores más comunes suelen provenir de rutas de archivos incorrectas en las opciones de Swagger. Verifica que todas las rutas en la opción apis sean correctas.

  2. El último console.log no está correctamente formateado. Necesita estar dentro de las comillas inversas (` `) para que puedas usar interpolación de cadenas con ${port}. Aquí está la corrección:

console.log(`Docs are available at http://localhost:${port}/api/v1/docs`);

Si continúas experimentando problemas, sería útil tener más información sobre los errores que estás obteniendo. ¿Recibes algún mensaje de error en particular?

profile picture
专家
已回答 1 年前
  • Hello Ivan, look, all the API endpoints are working, the only thing that is not working is Swagger. It tries to load the page but it appears blank. Everything works perfectly on my local machine or PC.

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则