为我的烧瓶 python 项目使用以下版本:
connexion==2.3.0 swagger-ui-bundle==0.0.5 OAS 3.0
我想让所有 requestBody 字段都是可选的,现在我已经定义了如下所示的 json 并且我假设如果您没有在 requestBody 中提供必填字段,那么它应该被视为 false 并且如果我没有提供任何值在这些字段的招摇 UI 中,它不应该使用带有 -d 选项的字段生成 curl 请求。
"openapi": "3.0.0",
"info": {
"description": "Dev",
"version": "1.0.0",
"title": "DEV-API",
"contact": {
"email": "dev@email.com"
},
"license": {
"name": "Dev",
"url": "https://opensource.org/licenses/MIT"
}
},
"servers": [
{
"url": "http://xx.yy.zz.a:8080"
}
],
"tags": [
{
"name": "Custom Event Post Request",
"description": "Example API for posting custom events"
}
],
"paths": {
"/api/v1/calls/{id}/{event-name}": {
"post": {
"tags": [
"Post Event"
],
"summary": "Post Custom Event to a call",
"operationId": "post_call_custom_event_data",
"parameters": [
{
"name": "id",
"in": "path",
"schema": {
"type": "string"
},
"required": true
},
{
"name": "event-name",
"in": "path",
"schema": {
"type": "string"
},
"required": true
}
],
"requestBody": {
"content": {
"application/x-www-form-urlencoded":{
"schema": {
"type": "object",
"properties": {
"event1": {
"type":"boolean"
},
"event2":{
"type": "string"
},
"event3": {
"type":"string"
}
}
},
"encoding": {
"event2": {
"allowReserved": true
},
"event3": {
"allowReserved": true
}
}
}
}
},
"responses": {
"200": {
"description": "ok"
},
"400": {
"description": "Failed. Bad Post Data"
}
}
}
}
}
但它确实生成没有值,如下所示:
curl -X POST " http://xx.yy.zz.a:8080/api/v1/calls/5454/custom-event " -H "accept: / " -H "Content-Type: application/x-www -form-urlencoded" -d "event1=&event2=&document="
我不确定如何使 requestBody 字段/元素在 swagger UI 中显示为可选