为什么@ApiModelProperty "name" 属性没有效果?
Why does @ApiModelProperty "name" attribute has no effect?
在我的 spring 引导应用程序中,我有一个 DTO 对象,其中包含 DTO 对象的嵌套列表。
class:
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "contact")
public class ContactDTO {
@ApiModelProperty(value = "id", example = "1", hidden = true)
private Long id;
@ApiModelProperty(value = "first name", example = "John")
private String firstName;
@ApiModelProperty(value = "last name", example = "Doe")
private String lastName;
@Builder.Default
@ApiModelProperty(value = "list of phone numbers", name = "phonenumbers")
List<PhoneNumberDTO> phoneNumberDTOList = new ArrayList<>();
}
post 请求的 swagger 示例值:
{
"firstName": "John",
"lastName": "Doe",
"phoneNumberDTOList": [
{
"label": "Company",
"number": "put number here"
}
]
}
我以为 @ApiModelProperty
中的 name = ...
属性 覆盖了变量名 phoneNumberDTOList
,但这不起作用:(
我使用 springfox-swagger 2.9.2
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
我做错了什么?
请查看此问题:
@ApiModelProperty "name" attribute has no effect
We don't want ever to have a case where the serialization model is different from whats being documented.
Actually the existence of @ApiModelProperty
is explained by the fact that we want to use the same annotations that swagger-core uses. However we take the philosophy of using the annotations just to supplement documentation. If for e.g. you've annotated your models with @JsonProperty
etc we don't want to duplicate that using @ApiModelProperty
as it is very easy to get out of sync.
有一个带有 @JsonProperty
注释的解决方法:
...
@JsonProperty("phonenumbers")
@ApiModelProperty(value = "list of phone numbers")
List<PhoneNumberDTO> phoneNumberDTOList = new ArrayList<>();
在我的 spring 引导应用程序中,我有一个 DTO 对象,其中包含 DTO 对象的嵌套列表。 class:
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "contact")
public class ContactDTO {
@ApiModelProperty(value = "id", example = "1", hidden = true)
private Long id;
@ApiModelProperty(value = "first name", example = "John")
private String firstName;
@ApiModelProperty(value = "last name", example = "Doe")
private String lastName;
@Builder.Default
@ApiModelProperty(value = "list of phone numbers", name = "phonenumbers")
List<PhoneNumberDTO> phoneNumberDTOList = new ArrayList<>();
}
post 请求的 swagger 示例值:
{
"firstName": "John",
"lastName": "Doe",
"phoneNumberDTOList": [
{
"label": "Company",
"number": "put number here"
}
]
}
我以为 @ApiModelProperty
中的 name = ...
属性 覆盖了变量名 phoneNumberDTOList
,但这不起作用:(
我使用 springfox-swagger 2.9.2
implementation 'io.springfox:springfox-swagger2:2.9.2'
implementation 'io.springfox:springfox-swagger-ui:2.9.2'
我做错了什么?
请查看此问题:
@ApiModelProperty "name" attribute has no effect
We don't want ever to have a case where the serialization model is different from whats being documented.
Actually the existence of
@ApiModelProperty
is explained by the fact that we want to use the same annotations that swagger-core uses. However we take the philosophy of using the annotations just to supplement documentation. If for e.g. you've annotated your models with@JsonProperty
etc we don't want to duplicate that using@ApiModelProperty
as it is very easy to get out of sync.
有一个带有 @JsonProperty
注释的解决方法:
...
@JsonProperty("phonenumbers")
@ApiModelProperty(value = "list of phone numbers")
List<PhoneNumberDTO> phoneNumberDTOList = new ArrayList<>();