问题描述
我正在针对包含的规范开发在openapi中生成的客户端(通过spring generator gradle插件)
components:
parameters:
FooBa:
type: object
description: >
Contains a Foo and optionally a Ba.
properties:
foo:
type: string
ba:
type: boolean
required:
- foo
使用邮递员,我可以将以下Request Body
发送到服务器:
{"FooBa":{"foo":"a","ba":"true"}}
{"FooBa":{"foo":"a"}}
以下内容无效:
{"FooBa":{"foo":"a","ba":"null"}}
然后服务器以400 Bad Request
和消息Can not construct instance of java.lang.Boolean from String value 'null'
响应。
现在,我想以编程方式发送此类请求,有时我没有有关可选属性ba
的信息,并希望将其忽略。但是,在生成的model
中,FooBa类型必须具有ba
作为字段,但是可以为空。
- 服务器是否错误,并且在可选时应接受null属性?
- 在这种情况下,客户负责发送忽略可选参数的请求吗?
- 如果是的话,我该怎么做?
##更新
useOptional
选项似乎很有希望,但是我看不到生成的代码有任何更改。当我期望ba
是Optional<Boolean>
时,private func ValidateForm(title: UITextField,description: UITextView,category: UITextField){
if title.text!.isEmpty && description.text.isEmpty && category.text!.isEmpty {
saveBtn.isEnabled = false
} else {
saveBtn.isEnabled = true
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
ValidateForm(title: titleTextField,description: descriptionTextView,category: categoryTextField)
}
仍然是布尔值。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)