OpenFeign / feign-annotation-error-decoder

Apache License 2.0
51 stars 9 forks source link

Meta-annotation support #31

Closed BigMichi1 closed 3 years ago

BigMichi1 commented 4 years ago

Mainly in combination with spring-cloud-openfeign it would be really helpfull to have support for meta-annotations. This will reduce the amount of annotations in the interface.

The idea is to have a custom annotation which combines the @RequestMapping annotations with the @ErrorHandling annotation on a method/class level. the SpringDecoder is able to work with the meta-annotations already so it is more consistent to have also @ErrorHandling working in a meta-annotation

e.g.

@ErrorHandling(codeSpecific =
    {
        @ErrorCodes( codes = {401}, generate = UnAuthorizedException.class),
        @ErrorCodes( codes = {403}, generate = ForbiddenException.class),
        @ErrorCodes( codes = {404}, generate = UnknownItemException.class),
    },
    defaultException = MethodLevelDefaultException.class
)
@RequestMapping(method = RequestMethod.GET, consumes = APPLICATION_CBOR_VALUE, produces = APPLICATION_CBOR_VALUE)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface GetMappingWithErrorHandling {
    @AliasFor(annotation = RequestMapping.class)
    String[] path() default {};
}

and so it is possible to have in the interface only one annotation

public interface GitHub {
    @GetMappingWithErrorHandling(path="https://github.com/projects"
    List<Contributor> projects();
}
BigMichi1 commented 3 years ago

has been merged into the official repo https://github.com/OpenFeign/feign/issues/1457