NodeJS Swagger -正文中不发送数据(swagger-jsdocs,swagger-ui-express)

bmvo0sr5  于 2023-04-29  发布在  Node.js
关注(0)|答案(2)|浏览(130)

对于一个nodejs-project,我使用swagger-ui-express和swagger-jsdocs作为Swagger API。当我尝试使用Swagger调用应用程序的POST-Endpoint时,没有数据发送。会有什么问题呢?我的整个相关代码如下:

const swaggerOptionsJSDocs = {
swaggerDefinition: {
    openapi: '3.0.1', //tried with 3.0.0 as well
    info: {
        title: "Testproject",
        description: "Middleware for bla bla ",
        contact: {
            name: "John Doo"
        }
    }
},
apis: ["index.js"]
};



const swaggerDocs = swaggerJsDoc(swaggerOptionsJSDocs);

app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerDocs));

**
 * @swagger
 * /user/upload:
 *  post:
 *      description: Receives a zipped and base64 encoded user
 *      consumes: 
 *         - application/json
 *      parameters:
 *          - in: body
 *            name: fullRequest // name here doesn't matter 
 *            description: ...
 *            schema:
 *              type: object
 *              required:
 *                  - user
 *              properties:
 *                  user:
 *                      type: string
 *                  jobId:
 *                      type: string
 *                  responseUrl:
 *                      type: string
 *                  inaugurationDate:
 *                      type: string
 *      responses:
 *          '201':
 *              description: user received and uploaded successfully
 *          '400':
 *              description: user data is missing or invalid
 *          '500':
 *              description: Internal server error
 *      
 *  
 *           
 */
app.post('/user/upload', function(req, res) {
  ....
}

Swagger正在执行get请求,但当它发送数据时,d-flag为空。有人有主意吗?
最好的问候

gwo2fgha

gwo2fgha1#

“:body”中的参数“”无效。在API 3中,你必须将requestBody作为一个单独的块传递。
此外,您必须使用@openapi才能使用Open API。
参考这里,查看requestBody对象的示例。

**
 * @openapi
...
 *      requestBody:
 *            description: ...
 *            schema:
 *              type: object
 *              required:
 *                  - user
 *              properties:
 *                  user:
 *                      type: string
 *                  jobId:
 *                      type: string
 *                  responseUrl:
 *                      type: string
 *                  inaugurationDate:
 *                      type: string
....
dbf7pr2w

dbf7pr2w2#

我也遇到了同样的问题,请尝试更换

openapi: '3.0.1', //tried with 3.0.0 as well

swagger: '2.0',

相关问题