【发布时间】:2019-06-19 11:10:15
【问题描述】:
简介
在一个简单而裸露的 spring-boot 项目中,我有一个模型类,其类型为 java.time.LocalTime 的单个属性。
如果我运行该项目,springfox 会将LocalTime 检测为非内置类并将其放在definitions 下。
{
"ExampleDto": {
"type": "object",
"properties": {
"time": {
"$ref": "#/definitions/LocalTime"
}
}
}
}
不是我想要的。
我真正想要的
... 是拥有一个字符串类型的属性,它具有一个名为“time”的自定义格式,如下所示:
{
"ExampleDto": {
"type": "object",
"properties": {
"time": {
"type": "string",
"format": "time"
}
}
}
}
我能想到什么
如果我将AlternateTypeRule 从LocalTime 添加到String,我只能得到我想要的一半。
{
"ExampleDto": {
"type": "object",
"properties": {
"time": {
"type": "string"
}
}
}
}
当然,我也尝试了很多东西,但我从未设法设置属性的“格式”。
我发现以某种方式以“时间”作为参数调用构造函数io.swagger.models.properties.StringProperty#StringProperty(java.lang.String) 可以解决问题,但我不知道如何实现。
我在 github 上建立了一个项目来展示我的问题。 https://github.com/LorenzSchumann/springfoxshowcase
【问题讨论】:
标签: spring swagger openapi springfox