apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.44k stars 2.93k forks source link

[Task] simplify the use of client annotations with @AliasFor #3485

Closed loongs-zhang closed 2 years ago

loongs-zhang commented 2 years ago

Description

For example, below is how we use @ShenyuXXXXClient now:

@RestController
@RequestMapping("/order")
@ShenyuSpringCloudClient(path = "/order")
public class OrderController {

    /**
     * Save order dto.
     *
     * @param orderDTO the order dto
     * @return the order dto
     */
    @PostMapping("/save")
    @ShenyuSpringCloudClient(path = "/save")
    public OrderDTO save(@RequestBody final OrderDTO orderDTO) {
        orderDTO.setName("hello world spring cloud save order");
        return orderDTO;
    }

}

After use @AliasFor with @ShenyuSpringCloudClient like below:

@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE, ElementType.METHOD})
public @interface ShenyuSpringCloudClient {

    /**
     * Path string.
     *
     * @return the string
     */
    @AliasFor(attribute = "path")
    String value() default "";

    /**
     * Path string.
     *
     * @return the string
     */
    @AliasFor(attribute = "value")
    String path() default "";

    /**
     * Rule name string.
     *
     * @return the string
     */
    String ruleName() default "";

    /**
     * Desc string.
     *
     * @return String string
     */
    String desc() default "";

    /**
     * Enabled boolean.
     *
     * @return the boolean
     */
    boolean enabled() default true;
}

We can simplify client annotation usage to:

@RestController
@RequestMapping("/order")
@ShenyuSpringCloudClient("/order")
public class OrderController {

    /**
     * Save order dto.
     *
     * @param orderDTO the order dto
     * @return the order dto
     */
    @PostMapping("/save")
    @ShenyuSpringCloudClient("/save")
    public OrderDTO save(@RequestBody final OrderDTO orderDTO) {
        orderDTO.setName("hello world spring cloud save order");
        return orderDTO;
    }

}

You can refer to the implementation scheme of shenyu-client-springcloud, don't forget to use org.springframework.core.annotation.AnnotatedElementUtils#findMergedAnnotation.

And if you have some great ideas, please leave a message below, let's discuss it.

Task List

    • [x] simplify @ShenyuDubboClient in alibaba dubbo; @sunshujie1990
    • [x] simplify @ShenyuDubboClient in apache dubbo; @sunshujie1990
    • [x] simplify @ShenyuGrpcClient; @weihubeats
    • [x] simplify @ShenyuSpringMvcClient; @Albertsirius
    • [x] simplify @ShenyuMotanClient; @ChineseTony
    • [x] simplify @ShenyuSofaClient; @ShawnSiao
    • [x] simplify @ShenyuTarsClient; @weihubeats
    • [x] simplify @ShenyuSpringWebSocketClient; @weihubeats
Albertsirius commented 2 years ago

Hi, @dragon-zhang , can you assign ShenyuSpringMvcClient task to me?

loongs-zhang commented 2 years ago

Hi, @dragon-zhang , can you assign ShenyuSpringMvcClient task to me?

sure, enjoy the contribution !

ShawnSiao commented 2 years ago

Can i take task 6,thank you.

loongs-zhang commented 2 years ago

Can i take task 6,thank you.

sure, why not.

ChineseTony commented 2 years ago

Can i take task 5,thank you.

sunshujie1990 commented 2 years ago

May i take task 1 and 2 for ShenyuDubboClient ?

weihubeats commented 2 years ago

Can i take task 3,thank you.

weihubeats commented 2 years ago

Can i take task 8,thank you.

loongs-zhang commented 2 years ago

Can i take task 8,thank you.

sure, thanks

weihubeats commented 2 years ago

Can i take task 7,thank you.

loongs-zhang commented 2 years ago

Thanks for your contribution !

loongs-zhang commented 2 years ago

If you have other great ideas, please submit a new ISSUE .