java - 如何将 swagger 文档设置为使用 dd/MM/yyyy 格式?
问题描述
我正在使用 spring-boot 和 Swagger 将日期解析为休息服务以记录 api。
在端点上,我只想有没有时间的日期。并且很容易实现@DateTimeFormat(pattern = "dd/MM/yyyy")
。请注意,比起几个月,我更喜欢日子在先。
使用 curl 时端点工作正常,那么我认为这不是问题所在。例如设置当年 11 月 30 日,我可以用 Curl 调用它,如下所示:
curl -X GET "http://localhost:8085/app/api/endpoint?creationTime=30%2F11%2F2020" -H "accept: application/json"
并且工作正常。但是,如果我直接使用 Swagger 页面进行测试,我会遇到以下情况:
首先,如果我将日期设置为 30/11/2020,swagger 不允许我继续:
如果我将日期设置为 2020 年 11 月 30 日,swagger 允许我继续,但我收到此错误:
"message": "Failed to convert value of type 'java.lang.String' to required type 'java.util.Date'; nested exception is org.springframework.core.convert.ConversionFailedException: Failed to convert from type [java.lang.String] to type [@io.swagger.annotations.ApiParam @org.springframework.web.bind.annotation.RequestParam @org.springframework.format.annotation.DateTimeFormat java.util.Date] for value '11/30/2020'; nested exception is org.joda.time.IllegalFieldValueException: Cannot parse \"11/30/2020\": Value 30 for monthOfYear must be in the range [1,12]",
正如我所说,那是第 30 个月。对我来说很有意义。
如果我设置为 2020 年 5 月 11 日,Swagger 允许我发送请求,最后日期是 11 月 5 日,这是我定义的格式。
对我来说,swagger 似乎是按MM/dd/yyyy
格式过滤我,而不是使用dd/MM/yyyy
在端点上真正定义的我。是否有任何选项可以将 swagger 验证设置为dd/MM/yyyy
?
注意:使用 swagger 版本2.9.2
。春季启动版本2.1.8.RELEASE
解决方案
推荐阅读
- php - 如何在我解码为 PHP 的 JSON 中找到特定的密钥?我想找到的键在多层嵌套上重复
- angular - Angular 6:如何保护帐户激活链接的路由
- jquery - 更改 Fullcalendar 主题系统的默认值
- python - python - UnicodeEncodeError,需要修复
- java - Android Studio:“Gradle 同步失败:无法从选定的 JDK 运行 JVM。”
- pandas - 确定 Pandas Grouped By df 中的最大计数,并将其用作返回记录的标准
- javascript - 根据现有子数组中的值创建一个新数组,javascript
- ruby-on-rails - Rails - 多态has_many:通过模型不建立在创建
- python - 有什么方法可以使像素不可见的油漆更平滑?
- node.js - 在整个应用程序中使用单个数据库连接?