question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Meta annotation input (OverridesAttribute) is ignored

See original GitHub issue

Hello,

i am using springfox 2.9.2 and writing a meta annotation with Size:

@Pattern(regexp="[a-z]*")
@Size
@Target({FIELD,  TYPE, PARAMETER })
@Retention(RUNTIME)
@Constraint(validatedBy = {})
public @interface MyVerify {
    @OverridesAttribute(constraint = Pattern.class, name = "message")
    String message() default "Wrong text";

    @OverridesAttribute(constraint = Size.class, name = "min")
    int min()default 5;

    Class<?>[] groups() default {};
    Class<? extends Payload>[] payload() default {};
}

And using it in model:

@Data
@AllArgsConstructor
@NoArgsConstructor
public class MyInfo {
    private int age;

    @MyVerify(min = 6)
    private String someText;
}

And the rest controller using the model:

    @RequestMapping(value = "/info", method = RequestMethod.POST)
    public MyInfo someInfo(@RequestBody @Valid MyInfo myInfo){
        myInfo.setAge(99);
        return myInfo;
    }

Java will enforce the MyVerify limit with min 5 chars if i will try to post wrong data, but the swagger file will ignore it and will use the min and max value of the Size annotation (0,2147483647):

"definitions": {
    "MyInfo": {
        "type": "object",
        "properties": {
            "age": {
                "type": "integer",
                "format": "int32"
            },
            "someText": {
                "type": "string",
                "minLength": 0,
                "maxLength": 2147483647,
                "pattern": "[a-z]*"
            }
        },
        "title": "MyInfo"
    }
}

The issues will repeat itself if i will use annotation with input: MyVerify(min = 99, max = 200)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
stale[bot]commented, Sep 25, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

0reactions
stale[bot]commented, Oct 9, 2020

This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Java annotation that summarizes other annotations
JPA 2.2 supports "meta-annotations" as per this link. Then it comes down to whether your JPA provider supports JPA 2.2 or not (the...
Read more >
Support Java custom meta-annotations to selectively ignore ...
In our code base, the objects exchanged via our REST API are defined as classes (views) with all fields public, no constructor (i.e....
Read more >
Hibernate Validator 8.0.0.Final - Jakarta Bean Validation ...
The default metadata source are annotations, with the ability to override and extend the meta-data through the use of XML.
Read more >
Bean Validation specification
Any groups definition on a composing annotation is ignored. Payload from the main constraint annotation is inherited by the composing ...
Read more >
Nullable meta annotations are ignored · Issue #973 - GitHub
Describe the feature JSR 303 allows for creating a constraint composition and it seems to not be supported. I can see the code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found