Parameters Swagger 2.0:如何指定类型为';对象';

Parameters Swagger 2.0:如何指定类型为';对象';,parameters,swagger,Parameters,Swagger,使用Swagger 2.0,我试图指定object类型的输入参数: 代码段: paths: '/thingies/{thingy_id}.json': put: summary: Update an existing thingy description: Updates an existing thingy parameters: - name: thingy_id description: ID of the

使用Swagger 2.0,我试图指定object类型的输入参数:

代码段:

paths:
  '/thingies/{thingy_id}.json':
    put:
      summary: Update an existing thingy
      description: Updates an existing thingy
      parameters:
        - name: thingy_id
          description: ID of the thingy to update
          in: path
          required: true
          type: integer
        - name: translation
          description: Name and Locale for new translation
          in: formData
          type: object
          properties:
            name:
              type: string
            locale:
              type: string
然而,验证器正在抱怨
类型:object
部分


如何正确指定输入参数?

Swagger只允许对象输入作为主体参数

原因与内容的序列化方式有关,这取决于
内容类型
标题(
在Swagger中生成
)。该头部与整个有效负载相关

传递表单参数时,您将使用两种mime类型之一:
multipart/formdata
application/x-www-form-urlencoded
。虽然前者允许您为每个部件指定mime类型,但Swagger目前不支持这样的定义。它上面有一个开放的票证,允许在规范的未来版本中使用它


目前,在指定表单参数时,只能指定基本体或基本体数组。

好的,多亏@ron的输入,我已经找到了解决方案。是的,我需要使用
body
而不是
formData
,但即使这样,它也没有验证,抱怨
type:object
。但是如果我先定义对象,然后定义
$ref
,那么它就可以工作了。下面的代码确实有效

swagger: '2.0'
info:
  version: '1'
  title: Thingy Service
  description: Everyone loves their thingy
schemes:
  - http
consumes:
  - application/json
produces:
  - application/json

definitions:
  localisation:
    type: object
    required:
      - name
      - locale
    properties:
      name:
        type: string
      locale:
        type: string

paths:
  '/thingies/{thingy_id}.json':
    put:
      summary: Update an existing thingy
      description: Updates an existing thingy
      parameters:
        - name: thingy_id
          description: ID of the thingy to update
          in: path
          required: true
          type: integer
        - name: translation
          description: Name and Locale for new translation
          in: body
          schema:
            $ref: '#/definitions/localisation'
      responses:
        204:
          description: No data
        404:
          description: Thingy not found

如果我将
formData
更改为
body
,代码仍然不会生效。有什么建议吗?它没有验证,因为您需要在
schema
属性中包含定义,但我看您已经解决了这个问题。
body
参数的结构在这个意义上与其他参数不同,因为它允许完整的模式定义。是的,谢谢。我试了一下才弄到的:-)车票号码是多少?