在形式数据中发送对象数组。 Swagger,OpenAPI 3

发布于 2025-02-04 17:37:11 字数 1035 浏览 2 评论 0原文

我正在尝试发送具有一系列对象的表单数据请求。问题在于,我在Express服务器上收到的数据以数组的形式出现,其中所有对象都变成字符串。我无法更改服务器中的任何内容,我需要使用Swagger解决此问题。

      "requestBody": {
     "content": {
         "multipart/form-data": {
            "schema": {
               "type": "object",
               "properties": {
                   "video[]": {
                    "type": "array",
                    "items": {
                       "type": "object",
                       "properties": {
                          "_id": {
                             "type": "string"
                          }
                       }
                    },
                    "describtion": "Video ids "
                 }
               }
            },
            "encoding": {
               "video[]": {
                 "contentType": "application/json",
                 "explode": true
               }
            }
         }
     }
 },

我期望在服务器上:{视频:[{_id:“ string”}]}

我得到的:{video:['{“ _id”:“ string”}']}

I am trying to send a form-data request which has an array of objects. The problem is that the data that I receive on my Express server comes in the form of an array in which all objects are turned into a string. I can't change anything in the server, I need to solve this problem using Swagger.

      "requestBody": {
     "content": {
         "multipart/form-data": {
            "schema": {
               "type": "object",
               "properties": {
                   "video[]": {
                    "type": "array",
                    "items": {
                       "type": "object",
                       "properties": {
                          "_id": {
                             "type": "string"
                          }
                       }
                    },
                    "describtion": "Video ids "
                 }
               }
            },
            "encoding": {
               "video[]": {
                 "contentType": "application/json",
                 "explode": true
               }
            }
         }
     }
 },

What I expect on server: { video: [{ _id: "string" }] }

What I get: { video: [ '{"_id": "string"}' ] }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

探春 2025-02-11 17:37:11

看来您不是在解析“视频”属性。在控制器函数中尝试以下代码。

const {video} = req.body;
parsedVideo = JSON.parse(video);
console.log(parsedVideo);

it seems you are not parsing the 'video' property. Try the below code in the controller function.

const {video} = req.body;
parsedVideo = JSON.parse(video);
console.log(parsedVideo);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文