[英]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.