Создайте свой собственный тип в Swagger

У меня есть этот YAML-код чванства, и мне нужно создать свой собственный тип (с именем MyOwnType).

Если я использую "MyOwnType", возникает ошибка компиляции.

paths:
  /in/total:
    get:
      summary: My summary.
      description: My description.

      parameters:
        - name: total
          in: query
          description: Total.
          required: true
          type: MyOwnType # -- THIS LINE OCCURS ERROR --
          format: MyOwnType
      responses:
        201:
          description: Respose
          schema:
            $ref: '#/definitions/MyOwnType'

definitions:
  MyOwnType:
    properties:
      var:
        type: string
        description: data.

Я создал определение «MyOwnType» и могу использовать его следующим образом: «$ref: '#/definitions/MyOwnType'» в схеме.

Но как я могу использовать определение MyOwnType для типа параметра?


person Computered    schedule 09.09.2015    source источник


Ответы (1)


Параметр запроса не может иметь схему JSON. Если вы хотите иметь схему для вашего параметра, вы должны изменить in вашего параметра на body или formData и использовать ключ schema:

swagger: '2.0'
info:
  version: 0.0.0
  title: '<enter your title>'
paths:
  /in/total:
    get:
      summary: My summary.
      description: My description.

      parameters:
        - name: total
          in: body
          description: Total.
          required: true
          schema:
            $ref: '#/definitions/MyOwnType'
      responses:
        201:
          description: Respose
          schema:
            $ref: '#/definitions/MyOwnType'

definitions:
  MyOwnType:
    properties:
      var:
        type: string
        description: data.
person Mohsen    schedule 15.09.2015