如果将in:body作为数组字符串,则将json转换为客户端无法正常工作

问题描述 投票:0回答:1

我正在尝试从swagger JSON生成swagger客户端,但是当我运行swagger代码gen时,它会抛出错误,例如无法完成操作。以下是我的招摇JSON

"/api/{id}/MO/{MOid}/pop/api": {
      "post": {
        "tags": [
          "cam"
        ],
        "summary": "summay",
        "operationId": "ApiCamByIdMOByMOIdPOPApiPost",
        "consumes": [
          "application/json-patch+json",
          "application/json",
          "text/json",
          "application/*+json"
        ],
        "produces": [
          "text/plain",
          "application/json",
          "text/json"
        ],
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "description": "cam id",
            "required": true,
            "type": "string"
          },
          {
            "name": "moId",
            "in": "path",
            "description": "mo's id",
            "required": true,
            "type": "integer",
            "format": "int32"
          },
          {
            "name": "apiItemIds",
            "in": "body",
            "description": "List of api items",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }
        ],
        "responses": {
          "200": {
            "description": "API pop report",
            "schema": {
              "$ref": "#/definitions/Operation"
            }
          },
          "404": {
            "description": "Cam, mo not found"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },

[当我尝试使用通用代码Gen将此JSON转换为Java客户端时,它失败并显示

 Could not process operation:

一旦删除此部分

{
            "name": "apiItemIds",
            "in": "body",
            "description": "List of api items",
            "schema": {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          }

代码生成正常。我不知道这部分出了什么问题,对我来说一切都很好。我在邮递员中尝试了此请求,并使用curl命令使其正常运行。我尝试了许多没有优势的事情。帮助将不胜感激。

java swagger swagger-ui swagger-2.0 swagger-codegen
1个回答
0
投票

我不确定,但是从语义上讲,[...]块中应该有items大括号作为schema,因为它是一个数组。

所以我想说尝试一下:

      {
        "name": "apiItemIds",
        "in": "body",
        "description": "List of api items",
        "schema": {
          "type": "array",
          "items": [{
            "type": "string"
          }]
        }
      }
© www.soinside.com 2019 - 2024. All rights reserved.