2016-01-28 3 views
3

У меня есть определение отчет объект. У меня есть другое определение сообщает объект, который имеет массив отчет объектов (через $ ref).Как повторно использовать пример из другого определения в swagger?

В описании определение, у меня есть пример, который отлично работает в пользовательском интерфейсе swagger.

В сообщает определения, я хочу, чтобы использовать пример из отчета определения.

Как это сделать? Я попробовал несколько вещей, используя $ реф, ближайший я получил то, что я в следующем YAML ...

definitions: 
    report: 
    type: object 
    properties: 
     ID: 
     type: number 
     format: int 
     description: "DB record ID of the report." 
     readOnly: true 
     ErrorContent: 
     type: string 
     description: "The actual problem or error infomation for this report. This can be exception stack, etc." 
     readOnly: true 
     UserComments: 
     type: string 
     description: "Any user comments collected by the app and submitted with the report." 
     readOnly: true 
     ReportedBy: 
     type: string 
     description: "The person using the app when it triggered the error this report is for." 
     readOnly: true 
     ReportedDateTime: 
     type: string 
     description: "The date/time the report was submitted." 
     readOnly: true 
    required: 
     - ID 
     - ErrorContent 
     - ErrorType 
     - UserComments 
     - ReportedBy 
     - ReportedDateTime 
    example: 
     ID: 11367 
     ErrorContent: "Operation is not valid due to the current state of the object." 
     ErrorType: "Exception" 
     UserComments: "Was clicking this and that and then Boom!" 
     ReportedBy: "domain\\name" 
     ReportedDateTime: "2016-01-19 14:07:00" 
    reports: 
    properties: 
     message: 
     type: string 
     reports: 
     type: array 
     items: 
      $ref: '#/definitions/report' 
    example: 
     message: "success" 
     reports: 
     - $ref: '#/definitions/report' 

Однако в Swagger UI, приведенные выше результаты в ...

{ 
    "message": "success", 
    "reports": [ 
    { 
     "$ref": "#/definitions/report" 
    } 
    ] 
} 

Одна интересная заметка, в пользовательском интерфейсе Swagger, когда я смотрю на модельный вид, у нее есть все отчет даже с описаниями.

ответ

0

Это поведение верное: в разделе examples нельзя ссылаться на указатель JSON. См. OAI Specification для того, что в настоящее время поддерживается.

Если вы считаете, что это обычный прецедент, пожалуйста, откройте проблему в репозитории.

+0

Спасибо! Я открою ошибку. Без этого изменения я должен дублировать примеры в нескольких местах. – Hoss