我正在为我们的项目使用dropwizard框架,我使用@JsonSnakeCase注释将格式从CamelCase转换为snake_case。但是当我尝试使用swagger注释生成swagger.json时,它会在CamelCase中生成定义。是否需要设置swagger中的任何配置,将属性的格式从CamelCase更改为snake_case?
我的模特课:
@Data
@JsonSnakeCase
public class ServiceRequest {
@NotNull
private Long categoryId;
@NotNull @NotEmpty
private String serviceName;
@NotNull @NotEmpty
private String serviceDesc;
private boolean isRootService;
private Long parentServiceId;
private String imageLink;
private String imageDescription;
private String videoLink;
private String serviceHelpText;
}
这就是生成swagger.json的方法
"ServiceRequest": {
"type": "object",
"required": [
"categoryId",
"serviceDesc",
"serviceName"
],
"properties": {
"categoryId": {
"type": "integer",
"format": "int64"
},
"serviceName": {
"type": "string"
},
"serviceDesc": {
"type": "string"
},
"parentServiceId": {
"type": "integer",
"format": "int64"
},
"imageLink": {
"type": "string"
},
"imageDescription": {
"type": "string"
},
"videoLink": {
"type": "string"
},
"serviceHelpText": {
"type": "string"
},
"rootService": {
"type": "boolean",
"default": false
}
}
},
答案 0 :(得分:1)
Swagger的默认ObjectMapper
不考虑这一点。您可以指定自己的映射器以供swagger用于模型转换。
ObjectMapper converter = new ObjectMapper();
converter.setPropertyNamingStrategy(
PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
ModelConverters.getInstance().addConverter(new ModelResolver(converter));
FYI ModelConverter
是Swagger
核心的单身人士。因此,这可能会影响所有使用它的地方。