Description
When parsing io.swagger.annotations.ApiModelProperty annotation via field scanning (e.g. ClassGraph's fieldInfo.getAnnotation()), we hit a critical issue with annotation shorthand usage:
- ❌ Failed Scenario: Using
@ApiModelProperty("description") (shorthand for default value attribute) → fieldInfo.getAnnotation(ApiModelProperty.class) always returns null, cannot resolve the annotation
- ✅ Working Scenario: Using
@ApiModelProperty(value = "description") (explicit value attribute declaration) → Annotation is resolved successfully and all attributes can be retrieved normally
By Java annotation specification, the shorthand @Ann("xxx") should be equivalent to @Ann(value="xxx") when value is the annotation's only required/default attribute, but this equivalence is not recognized during scanning here.
Environment
- Library for scanning: ClassGraph (or your actual scanning lib)
- Swagger Annotation Version:
io.swagger:swagger-annotations:${your-version}
- JDK Version: ${your-jdk-version}
Steps to Reproduce
- Define a Java bean field with shorthand
ApiModelProperty annotation
public class DemoBean {
// Can NOT be resolved, getAnnotation returns null
@ApiModelProperty("User name description")
private String userName;
// Can be resolved normally
@ApiModelProperty(value = "User age description")
private Integer userAge;
}
- Scan the field via
fieldInfo.getAnnotation(ApiModelProperty.class)
- Observe that
userName field's annotation returns null, while userAge field's annotation is retrieved successfully
Expected Behavior
Shorthand @ApiModelProperty("description") should be resolved the same as @ApiModelProperty(value="description"), fieldInfo.getAnnotation() should return the valid annotation instance instead of null.
Actual Behavior
@ApiModelProperty("description") returns null, only explicit value declaration works.
Additional Context
- No custom annotation processors are used
- Other annotations' shorthand usage (e.g.
@NotNull) can be resolved normally in the same scanning logic
Description
When parsing
io.swagger.annotations.ApiModelPropertyannotation via field scanning (e.g. ClassGraph'sfieldInfo.getAnnotation()), we hit a critical issue with annotation shorthand usage:@ApiModelProperty("description")(shorthand for defaultvalueattribute) →fieldInfo.getAnnotation(ApiModelProperty.class)always returnsnull, cannot resolve the annotation@ApiModelProperty(value = "description")(explicitvalueattribute declaration) → Annotation is resolved successfully and all attributes can be retrieved normallyBy Java annotation specification, the shorthand
@Ann("xxx")should be equivalent to@Ann(value="xxx")whenvalueis the annotation's only required/default attribute, but this equivalence is not recognized during scanning here.Environment
io.swagger:swagger-annotations:${your-version}Steps to Reproduce
ApiModelPropertyannotationfieldInfo.getAnnotation(ApiModelProperty.class)userNamefield's annotation returnsnull, whileuserAgefield's annotation is retrieved successfullyExpected Behavior
Shorthand
@ApiModelProperty("description")should be resolved the same as@ApiModelProperty(value="description"),fieldInfo.getAnnotation()should return the valid annotation instance instead ofnull.Actual Behavior
@ApiModelProperty("description")returnsnull, only explicitvaluedeclaration works.Additional Context
@NotNull) can be resolved normally in the same scanning logic