简体   繁体   English

OpenAPI/Swagger 构建具有多个相同键的对象

[英]OpenAPI/Swagger building objects with multiple same keys

I have some shocking response JSON to work with from an internal client.我有一些令人震惊的回应 JSON 可以从内部客户端使用。 They can't change it on the fly unfortunately as multiple teams are sending them requests and already dealing with this horrendous response.不幸的是,他们无法即时更改它,因为多个团队正在向他们发送请求并且已经在处理这种可怕的响应。

My question is, is there any way to use OpenAPI to build an object structure which will map the incoming JSON below, with the, frankly, moronic name/value setup as you can see:我的问题是,有什么方法可以使用 OpenAPI 构建一个 object 结构,该结构将 map 传入下面的 JSON,坦率地说,您可以看到白痴名称/值设置:

{
    "data": [{
            "name": "something",
            "value": "123"
        },
        {
            "name": "something2",
            "value": "str"
        },
        {
            "name": "something3",
            "value": "str123"
        },
        {
            "name": "something4",
            "value": "str456"
        },
        {
            "name": "something5",
            "value": "str333"
        },
        {
            "name": "something6",
            "value": "str333rr"
        },
        {
            "name": "something7",
            "value": "str333rr322"
        },
        {
            "name": "something8",
            "value": "str333rr354"
        },
        {
            "name": "something9:",
            "value": "str333rr354543"
        }
    ]
}

I don't really see the complexity of this JSON, I've quickly done something in the swagger editor to match the structure:我并没有真正看到这个 JSON 的复杂性,我很快在 swagger 编辑器中做了一些事情来匹配结构:

  NameValue:
    type: object
    properties:
      name:
        type: string
      value:
        type: string

  ResultSet:
    type: object
    properties:
      data:
        type: array
        items:
          $ref: '#/definitions/NameValue'

Am I missing something?我错过了什么吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM