Python 如何使requestBody属性在OpenAPI中成为可选属性?
我在python flask中实现了一个OpenAPI3 POST方法,其请求体如下:Python 如何使requestBody属性在OpenAPI中成为可选属性?,python,swagger,openapi,swagger-editor,Python,Swagger,Openapi,Swagger Editor,我在python flask中实现了一个OpenAPI3 POST方法,其请求体如下: /DoSomething: post: operationId: postDoSomething requestBody: content: application/json: schema: $ref: '#/components/schemas/MyBody' required: true compo
/DoSomething:
post:
operationId: postDoSomething
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyBody'
required: true
components:
schemas:
MyBody:
type: object
properties:
Images:
type: array
items:
$ref: '#/components/schemas/Image'
Ids:
type: array
items:
$ref: '#/components/schemas/Ids'
Date:
type: string
format: date-time
我需要属性(图像、ID、日期)作为可选参数
例如,当我从一个C#应用程序将Images数组设置为null时,我在服务器上得到以下错误
validation error: None is not of type 'array'
如何使参数可选?默认情况下,它们是可选的。请张贴您的C#代码。如Helen所示,它们是可选的。问题似乎是,正如您所说,您将图像数组作为null传递。而是一起排除图像数组。如果您有非可选的参数,则应指出它们是必需的。