$ ref в примере ответа - PullRequest
0 голосов
/ 29 июня 2018

Пример ответа, который я хотел бы добавить в файл yaml, выглядит примерно так:

{ "name": "Element", "schema": { "properties": { "id": { "type": "string" }, "extension": { "type": "array", "items": { "$ref": "#/definitions/Extension" } } } } }

И ymal этого примера будет:

responses:
    200:
      description: "successful operation, return the definition of the resource type in the body"
      examples:
        application/json:
          name: Element
          schema:
            properties:
              id:
                type: string
              extension:
                type: array
                items: 
                  $ref: '#/definitions/Extension'

Как видите, последняя строка «$ ref: '# / Definations / Extension'», поэтому Swagger считает, что это ссылка, которую он не может найти нигде в файле ymal.

Можно ли избежать этого, чтобы стать эталоном?

1 Ответ

0 голосов
/ 26 июля 2018

Это ошибка в редакторе Swagger и пользовательском интерфейсе.

В качестве обходного пути, определите schema для своего ответа и используйте вместо него пример схемы. Примеры схем хорошо отображаются в Swagger Editor 3.6.6 и Swagger UI 3.17.5. Вы все еще можете видеть ошибку разрешения $ ref в редакторе, но, по крайней мере, пример отображается правильно.

      responses:
        200:
          description: "successful operation, return the definition of the resource type in the body"
          schema:
            $ref: '#/definitions/MyResponseSchema'

definitions:
  MyResponseSchema:
    type: object
    properties:
      name:
        type: string
      schema:
        type: object
        properties:
          ...
    example:    # <------------
      name: Element
      schema:
        properties:
          id:
            type: string
          extension:
            type: array
            items:
              $ref: '#/definitions/Extension'
...