![](/img/trans.png)
[英]how to set the springfox.documentation.swagger.v2.path from application.properties
[英]Configure how Springfox Swagger orders properties?
在我的 Spring Boot rest api 中,我有以下类:
@Entity
@Table(name="Items")
@JsonPropertyOrder({ "itemId", "description", "viewed" })
public class Item {
@ApiModelProperty(notes="Id of the item.", required=true, value="100000")
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@JsonProperty(access=Access.READ_ONLY)
private int itemId = 0;
@ApiModelProperty(notes="Item description.", required=true, value="Item1")
@NotNull
@Size(min=1, max=256)
private String description;
private int viewed;
public int getItemId() {
return this.itemId;
}
public String getDescription() {
return this.description;
}
public void setDescription(String description) {
this.description = description;
}
public int getViewed() {
return this.viewed;
}
}
当我执行请求时,会遵守 JsonPropertyOrder,但是,在 Swagger UI(和 Swagger 文档)中,属性被列为描述、itemId、已查看。 即按字母顺序。 我从来没有打开字母排序,所以不知道为什么要这样做……有什么办法可以关闭它? 它对我所有以常识/逻辑顺序排列的课程都这样做......
您可以使用ApiModelProperty#position定义属性的显示顺序。
例子:
class MyClass {
@ApiModelProperty(position = 0)
String myFirstProperty;
@ApiModelProperty(position = 1)
String mySecondProperty;
}
这不是最方便的方法,但我找不到任何其他方法来实现这一目标......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.