我正在使用spring-boot和Swagger将一个日期解析为一个rest服务,以记录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页面进行测试,我有以下情况:
首先,如果我将日期设置为2020年11月30日,swagger不允许我继续:
如果我将日期设置为11/30/2020,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月份,对我来说是有意义的。
如果我设置05/11/2020,Swagger允许我发送请求,最终日期是11月5日,这是我定义的格式。
对我来说,swagger似乎是通过MM/dd/yyyy
过滤我,而不是使用我的dd/MM/yyyy
,这是真正定义在端点上。有任何选项设置swagger验证为dd/MM/yyyy
吗?
注:使用的是昂首阔步型2.9.2
。Spring Boot型2.1.8.RELEASE
1条答案
按热度按时间xdnvmnnf1#
我们可以用, swagger ..
对于nestj,可以使用