【问题标题】:How to create a Json object from the Schema definitions of swagger如何从 swagger 的 Schema 定义中创建 Json 对象
【发布时间】:2019-12-27 19:54:24
【问题描述】:

我无法从我希望 swagger 从架构定义中生成的 json 请求正文中删除外部数组。

我要生成这个对象:

{
    "name": 
    { 
        "value": "test04" 

    },
    "mail": { 
        "value": "test04@gmail.com" 
    }
}

但招摇给我的是这个:

[
  {
    "name": {
      "value": "string"
    },
    "mail": {
      "value": "string"
    }
  }
]

这是我的定义部分:

definitions:
  user:
    type: "object"
    properties:
       name: 
        type: object
        properties: 
          value: 
            type: string
       mail: 
        type: object
        properties: 
          value: 
            type: string

请您提供帮助。我是新来的。我使用的是 2.0 版

【问题讨论】:

  • 您的架构定义是正确的。很可能在参数/请求正文/响应定义中的某处有一个额外的type: array。你能发布问题操作的完整 YAML 吗?
  • 你是对的,谢谢你的帮助。如果您将此作为答案发布,我会接受它

标签: json object yaml swagger openapi


【解决方案1】:

您的 User 架构是正确的,因此这意味着在使用此架构的参数、请求正文或响应中的某处有一个额外的 type: array

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-17
    • 2020-08-19
    • 2020-12-17
    相关资源
    最近更新 更多