2

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

4

1 回答 1

3

查询参数不能有 JSON 模式。如果您想为参数设置架构,则应将in参数更改为bodyorformData并使用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.
于 2015-09-15T20:57:37.400 回答