Как передать 1 или более массивов из 4 строк для запроса в чванстве?

По сути, я хочу настроить swagger, чтобы принимать что-то подобное в запросе

[
    {
        "input_id": "",
        "city": "",
        "state": "",
        "zipcode": "20500"
    },
    {
        "input_id": "",
        "city": "Cupertino",
        "state": "CA",
        "zipcode": ""
    },
    {
        "input_id": "",
        "city": "",
        "state": "",
        "zipcode": "95014"
    },
    {
        "input_id": "Apple",
        "city": "Cupertino",
        "state": "ca",
        "zipcode": "90210"
    }
]

У меня возникли проблемы с моей текущей настройкой

  - name: testing
    in: query
    description: 'zip request info'
    type: array
    items:
      type: object
      properties:
        input_id:
          type: string
        city:
          type: string
        state:
          type: string
        zipcode:
          type: string

Это устанавливает URL-адрес POST для доступа к этим элементам, например ...testing[0][city]=burbank&testing[0][state]=ca...

Когда я хочу получить к ним доступ вот так ...city=burbank&state=ca... для каждой пары город/штат/почтовый индекс/входной_идентификатор.

ОБНОВИТЬ:

моя новая настройка работает, кроме ошибок, выдаваемых чванством. Однако это работает!

    - name: City/State pair or ZIP Code
      in: body
      description: 1 or more
      type: array
      items:
        minimum: 1
        type: object
        properties:
          input_id:
            type: string
            description: A unique identifier for this address used in your application; this field will be copied into the output
          city:
            type: string
            description: The city name
          state:
            type: string
            description: State name or abbreviation
          zipcode:
            type: string
            description: The 5-digit ZIP Code 

Если кто-то может найти лучшее решение, чем это (без ошибок), дайте мне знать


person camiblanch    schedule 16.06.2015    source источник


Ответы (1)


Я был почти прав в своем редактировании. Мне просто нужно было добавить schema: в строку перед добавлением type: array

name: 'City/State pair or ZIP Code'
in: body
description: 1 or more
schema:
  type: array
  items:
    type: object
    properties:
      input_id:
        type: string
        description: A unique identifier for this address used in your application; this field will be copied into the output
      city:
        type: string
        description: The city name
      state:
        type: string
        description: State name or abbreviation
      zipcode:
        type: string
        description: 'The 5-digit ZIP Code'

Это работает и не имеет ошибок. Я могу добавить несколько объектов в свой массив, чтобы он публиковался в нужном мне формате.

person camiblanch    schedule 17.06.2015