在Swagger中,如何定义使用文件以及模式参数的API? [英] In Swagger, how to define an API that consumes a file along with a schema parameter?
问题描述
我正在尝试使用Swagger定义一个接受实际文件的API和一个描述文件内容的架构对象.这是Swagger YAML的片段.但是,它不会在Swagger编辑器中验证.
I am trying to use Swagger to define an API that accepts an actual file and a schema object that describes the contents of a file. Here is a snippet of the Swagger YAML. However it won't validate in the Swagger Editor.
/document:
post:
summary: Api Summary
description: Api Description
consumes:
- multipart/form-data
parameters:
- name: documentDetails
in: formData
description: Document Details
required: true
schema:
$ref: '#/definitions/Document'
- name: document
in: formData
description: The actual document
required: true
type: file
Swagger编辑器会引发以下验证错误:
The Swagger Editor throws the following validation error:
挥舞着错误:数据与"oneOf"中的任何架构都不匹配
Swagger Error: Data does not match any schemas from 'oneOf'
我错过了什么吗?还是这不是Swagger支持的功能?
Am I missing something? Or Is this not a supported feature of Swagger?
推荐答案
swagger不支持formData中的'object'类型,仅作为主体参数.
swagger does not support type 'object' in formData, only as body parameters.
这篇关于在Swagger中,如何定义使用文件以及模式参数的API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!