在Swagger中创建我自己的类型

时间:2015-09-09 12:55:49

标签: swagger swagger-2.0 swagger-editor

我有这个摇摇欲坠的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”定义?

1 个答案:

答案 0 :(得分:2)

查询参数不能具有JSON模式。如果您想要参数的架构,则应将参数in更改为bodyformData并使用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.