Skip to content

io.github.classgraph.FieldInfo fieldInfo.getAnnotation(ApiModelProperty.class) returns null for shorthand @ApiModelProperty("desc") but works for @ApiModelProperty(value="desc") #928

@yongyongwang

Description

@yongyongwang

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:

  1. Failed Scenario: Using @ApiModelProperty("description") (shorthand for default value attribute) → fieldInfo.getAnnotation(ApiModelProperty.class) always returns null, cannot resolve the annotation
  2. 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

  1. 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;
    }
  2. Scan the field via fieldInfo.getAnnotation(ApiModelProperty.class)
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions