Swagger: как получить отформатированный пример json

Я действительно изо всех сил пытаюсь понять формат раздела examples ответа. У меня есть следующий ответ, определенный для ошибки 500 Internal Sever.

500InternalServerError:
    description: The server encountered an unexpected condition which prevented it from fulfilling the request
    schema:
      allOf:
        - $ref: '#/definitions/Failure'
    headers:
      X-Rate-Limit-Limit:
        description: The number of allowed requests in the current period
        type: integer
      X-Rate-Limit-Remaining:
        description: The number of remaining requests in the current period
        type: integer
      X-Rate-Limit-Reset:
        description: The number of seconds left in the current period
        type: integer
    examples:
      application/json:
        code: -1
        message: The server encountered an unexpected condition which prevented it from fulfilling the request

Когда я загружаю его в swagger-ui, это выглядит так:

Формат ответа Json

Как мне получить ответ, который будет отформатирован в несколько строк и выглядеть так?:

{
  "code": "-1",
  "message": "The server encountered an unexpected condition which prevented it from fulfilling the request"
}

person SynackSA    schedule 18.04.2017    source источник


Ответы (1)


Отсутствие красивой печати в примерах уровня ответа кажется ошибкой или недостающей функциональностью в пользовательском интерфейсе Swagger 3.0.x. Не стесняйтесь отправлять вопрос на GitHub.

Обходной путь заключается в том, чтобы вместо этого использовать пример уровня схемы:

definitions:
  Failure:
    type: object
    ...
    example:
      code: "-1"  # Quotes force the number to be treated as a string
      message: The server encountered an unexpected condition which prevented it from fulfilling the request


Кстати, при использовании $ref отдельно (без комбинирования с другими предметами) allOf не нужен:

schema:
  $ref: '#/definitions/Failure'
person Helen    schedule 18.04.2017