微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Swagger JSON - 如何修复响应呈现错误?

如何解决Swagger JSON - 如何修复响应呈现错误?

我一直在尝试修复 Swagger 无法呈现我的 JSON 响应的错误 - here is an attached picture of it.

控制台没有显示任何错误,所以我正在努力分配问题可能出现的地方 - here is the console result.

如果有人能提出解决该问题的方法,我将不胜感激。

这是我的代码

  "paths": {
    "/unit/{jobs}": {
      "get": {
        "tags": [
          "Services"
        ],"summary": "Jobs information","description": "Returns JSON with content of jobs details.","operationId": "unitJobs","security": [
          {
            "Application": []
          },{
            "Profile": []
          },{
            "Authorization": []
          }
        ],"parameters": [
          {
            "name": "jobs","in": "path","required": true,"schema": {
              "type": "string"
            },"description": "Jobs"
          }
        ],"responses": {
          "200": {
            "description": "Success!","content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Job"
                }
              }
            }
          }
        }
      }
    }
  },"components": {
    "securitySchemes": {
      "Application": {
        "name": "X-Application","type": "apiKey","in": "header"
      },"Profile": {
        "name": "X-Profile","Authorization": {
        "type": "http","scheme": "bearer"
      }
    },"schemas": {
      "Job": {
        "properties": {
          "id": {
            "type": "integer","example": 2584075,"description": "Unique identifier"
          },"currency_code": {
            "type": "string","example": "GBP","description": "Currency code"
          },"payment_method": {
            "type": "array"
          },"app_time": {
            "type": "integer","example": 1504620000,"description": "Appointment time for the job in UTC timestamp"
          },"flexible_from": {
            "type": "integer","example": null,"description": "Start of timeframe to execute the job in UTC timestamp"
          },"flexible_to": {
            "type": "integer","description": "End of timeframe to execute the job in UTC timestamp"
          },"insufficient_travel_time_warning_time": {
            "type": "integer","example": "1504616400","description": "Time up until Pro should leave prevIoUs job in order to get to this job in time in UTC timestamp"
          },"total_formatted": {
            "type": "string","example": "£97","description": "Price of the service after discounts"
          },"base_total_formatted": {
            "type": "string","description": "Price of the service before discounts"
          },"price_notes": {
            "type": "array","example": [
              "Credit applied","Compensation included"
            ],"description": "Description notes for the price of the services."
          },"require_summary": {
            "type": "integer","example": 4,"description": "\n * `0` - No summary required \n * `1` - Should send summary at the end of the day \n * `2` - Should send summary Now \n * `3` - Can’t proceed until summary sent \n * `4` - Summary sent"
          },"work_time": {
            "type": "integer","example": 120,"description": "Job duration in minutes"
          },"valid_to": {
            "type": "integer","example": "1504620000","description": "Time after which job is no more valid and has to be updated in UTC timestamp"
          },"attachments.origin_key": {
            "type": "string","example": "checklist","description": "\n Identifies where the attachment is coming from: \n * `checklist` - from answering a question that requires attachment \n * `job` - from job screen \n * `configurator` - from booking process when filling a choice item of type attachment"
          },"services_price_modifiers": {
            "type": "array","example": ""
          },"reference_number": {
            "type": "string","example": "20082602SYS","description": "Unique identifying number for each job"
          },"purchase_order_number": {
            "type": "string","example": "12-13-14-15-16","description": "Unique number assigned to a purchase order form"
          },"contacts": {
            "type": "array","items": {
              "$ref": "#/components/schemas/Contact"
            }
          },"message_templates": {
            "type": "array","items": {
              "$ref": "#/components/schemas/MessageTemplate"
            }
          },"decline_reason_groups": {
            "type": "array","items": {
              "$ref": "#/components/schemas/DeclineReasonGroup"
            }
          },"icons": {
            "type": "array","items": {
              "$ref": "#/components/schemas/Icon"
            }
          }
        }
      },"Contact": {
        "properties": {
          "id": {
            "type": "integer","example": 203,"value": {
            "type": "string","example": "02034042956","description": "Contact number"
          },"type": {
            "$ref": "#/components/schemas/ContactType"
          },"description": {
            "type": "string","example": "Customer Service","description": "Name of the corresponding department"
          },"display_positions": {
            "type": "array","example": [
              2,3,7
            ],"description": ""
          }
        }
      },"MessageTemplate": {
        "properties": {
          "id": {
            "type": "integer","example": 15,"title": {
            "type": "string","example": "In front of the property","description": "Template message title"
          },"message": {
            "type": "string","example": "Dear [CLIENT_NAME],I am in front of your property. Please let me in or call our office on 02034041930. Your Fantastic Professional","description": "The containing text of the message"
          },"vars": {
            "type": "array","items": {
              "$ref": "#/components/schemas/Var"
            },},"destination_option_title": {
            "type": "string","example": "to office","description": "Optionally defines the destination of the title"
          }
        }
      },"DeclineReasonGroup": {
        "properties": {
          "title": {
            "type": "string","example": "Technical issues","description": "Decline reason title"
          },"sort": {
            "type": "integer","example": 100,"description": ""
          },"decline_reasons": {
            "type": "array","items": {
              "$ref": "#/components/schemas/DeclineReason"
            }
          }
        }
      },"Icon": {
        "properties": {
          "name": {
            "type": "string","example": "Key:","description": "The name of the icon"
          },"note": {
            "type": "string","example": "Yes","description": "Addiditonal information about the icon"
          }
        }
      },"Var": {
        "properties": {
          "variable": {
            "type": "string","example": "CLIENT_NAME","description": "Different client details"
          },"type": {
            "$ref": "#/components/schemas/VarType"
          },"field": {
            "type": "string","example": "clientName","description": "Fields where the client's information is filled"
          }
        }
      },"DeclineReason": {
        "properties": {
          "id": {
            "type": "integer","example": 11,"name": {
            "type": "string","example": "Car is broken","description": "The name of a decline reason"
          },"requires_comment": {
            "type": "boolean","example": true,"description": "Determines whether the comment section is required to be filled "
          },"success_message": {
            "type": "string","example": "Please contact Stanimir Tomov on 07472761402 - he can find you another.","description": "The message which pops up after the request made is successful"
          },"ContactType": {
        "type": "integer","enum": [
          1,2,4
        ],"description": "* `1` - Customer Service \n * `2` - Sales \n * `3` - Finance \n * `4` - Other"
      },"VarType": {
        "type": "string","enum": [
          "auto","manual"
        ],"description": "* `auto` - information being filled automatically \n * `manual` - information being filled manually "
      }
    }
  }
}

解决方法

问题不在于他们自己的响应,而在于 Job 模式中“payment_method”的定义:

您需要在数组定义中定义项目,试试这个:

"payment_method": {
  "type": "array","items": {
    "type": "string"
  }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。