简体   繁体   English

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

[英]Swagger - No data sent in body (swagger-jsdocs, swagger-ui-express)

for an nodejs-project I am using swagger-ui-express and swagger-jsdocs for the Swagger API.对于 nodejs 项目,我将 swagger-ui-express 和 swagger-jsdocs 用于 Swagger API。 When I try to call an POST-Endpoint of my application with Swagger then there is no data sent with.当我尝试使用 Swagger 调用我的应用程序的 POST-Endpoint 时,没有发送任何数据。 What could be the problem?可能是什么问题呢? My whole relevant code is following:我的整个相关代码如下:

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 is performing get request but when it comes to send data, the d-flag is empty. Swagger 正在执行获取请求,但在发送数据时,d-flag 为空。 Does anyhone have an idea?有人有想法吗?

Best regards此致

Parameters 'in:body' is not valid.参数“in:body”无效。 In Open API 3, you have to pass the requestBody as a separate chunk.在 Open API 3 中,您必须将 requestBody 作为单独的块传递。

Also, you have to use @openapi to use Open API.此外,您必须使用 @openapi 才能使用 Open API。

Refer here , to see examples of requestBody object.请参阅此处,查看 requestBody object 的示例。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 swagger-ui-express未在浏览器中呈现,但在Postma中具有响应正文 - swagger-ui-express is not rendering in browser but has response body in Postma swagger-ui-express 不显示响应 - swagger-ui-express not displaying response 如何在使用 swagger-ui-express 和 swagger-jsdoc 时正确使用 swagger 文件中的 $ref - How to use $ref in swagger file properly while working with swagger-ui-express and swagger-jsdoc Swagger-ui-express模块​​仅实例化最后定义的文档 - Swagger-ui-express module, instantiates only the last defined document 在swagger-ui-express中如何解决CORS问题 - How to solve CORS issue in swagger-ui-express swagger-ui-express 不同 API 文档的多个路由 - swagger-ui-express Multiple Routes for Different API Documentation Swagger-UI-Express 未在 Azure 应用服务中加载:404 Not Found - Swagger-UI-Express not loading in Azure App Service: 404 Not Found 如何使用 swagger-ui-express 加载 YAML 文件? - How to load a YAML file with swagger-ui-express? 如何(自动)列出 Swagger UI 的所有路由(swagger-ui-express) - How to (auto) list all route to Swagger UI (swagger-ui-express) 托管在 aws beanstalk 上的 Nodejs express api swagger-ui-express API 文档上的 Cors 问题 - Cors issues on Nodejs express api swagger-ui-express API documentation hosted on aws beanstalk
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM