我有一个在 Flask/Connexion 上运行的 API。API 是用 OpenAPI 3 为 Swagger 编写的。我通过 multipart/form-data 将数据发送到端点,除了上传的文件之外,一切都通过了。我将从分享我的 OpenAPI YAML 文件开始。对于我引用的有关如何指定架构的文档的文件。
openapi: "3.0.0"
info:
description: No one is reading this
version: "1.0.0"
title: Super basic API endpoint
# Paths supported by the server application
paths:
/api/submit:
post:
summary: Process a new text submission asynchronously
operationId: submit.submit
requestBody:
content:
multipart/form-data:
schema:
x-body-name: submission
$ref: '#/components/schemas/Submission'
responses:
'200':
description: That's nice
components:
schemas:
Submission:
type: object
required:
- url
- mimeType
- language
- content
properties:
url:
type: string
format: uri
mimeType:
type: string
description: MIME type of the file submission
language:
type: string
pattern: '^[a-z]{3}$'
content:
type: array
items:
type: string
format: binary
submit.submit操作调用以下 Python 代码:
from datetime import datetime
import uuid
def get_timestamp():
return datetime.now().strftime(("%Y-%m-%d %H:%M:%S"))
def submit(submission):
print(str(submission))
return { "timestamp": get_timestamp(), "uuid": str(uuid.uuid4()) }
Python 打印的是:
{'url': 'http://nosite.none', 'mimeType': 'text/plain', 'language': 'eng'}
所以不存在“内容”。但我知道数据正在发送,因为我在浏览器中将其捕获到出站:
-----------------------------138508216052
Content-Disposition: form-data; name="url"
http://nosite.none
-----------------------------138508216052
Content-Disposition: form-data; name="mimeType"
text/plain
-----------------------------138508216052
Content-Disposition: form-data; name="language"
eng
-----------------------------138508216052
Content-Disposition: form-data; name="content"; filename="nonsense.txt"
Content-Type: text/plain
Now is the time for
all good men to come
to the aid of their
party.
-----------------------------138508216052--
我应该对 Connexion 进行额外的调试,它会告诉我是否/为什么它没有传递“内容”文件?