首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在formData 2.0中为相同的操作定义路径和OpenAPI参数?

如何在formData 2.0中为相同的操作定义路径和OpenAPI参数?
EN

Stack Overflow用户
提问于 2017-08-06 16:35:19
回答 1查看 11.5K关注 0票数 9

我有一个看起来像/test/{id}/relationships/image的图像上传端点。我想用OpenAPI 2.0 (Swagger2.0)描述这个端点。

端点具有路径和formData参数。我尝试了以下几点:

代码语言:javascript
复制
swagger: '2.0'
info:
  title: API
  version: 1.0.0
host: api.server.de
schemes:
  - https
produces:
  - application/json
paths:
  '/test/{id}/relationships/image':
    post:
      operationId: addImage
      consumes:
        - multipart/form-data
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
            format: int32
        - in: formData
          name: file
          type: file
          required: true
          description: The file to upload.
        - in: formData
          name: metadata
          type: string
          required: false
          description: Description of file contents.
      responses:
        '202':
          description: Uploaded

但是Swagger显示了错误:

paths'/test/{id}/relationships/image'.post.parameters.in上的模式错误应该等于allowedValues: body,header,formData,query到第17行的允许值之一 paths'/test/{id}/relationships/image'.post.parameters中的架构错误不应该具有附加属性additionalProperty: additionalProperty、in、name、required跳转到第17行

我做错了什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-06 16:49:17

在path参数中更改

代码语言:javascript
复制
          schema:
            type: integer
            format: int32

代码语言:javascript
复制
          type: integer
          format: int32

在OpenAPI/Swagger2.0中,path、header、query和formData参数直接使用type,而不使用schemaschema关键字仅用于身体参数。

票数 17
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45534187

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档