1

对于 nodejs 项目,我将 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 为空。有人有想法吗?

此致

4

1 回答 1

-1

参数“in:body”无效。在 Open 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
....
于 2020-11-17T05:15:22.737 回答