Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] enum.use.custom 没有生效 #1089

Open
ChenYilei2016 opened this issue Dec 6, 2023 · 4 comments
Open

[Bug] enum.use.custom 没有生效 #1089

ChenYilei2016 opened this issue Dec 6, 2023 · 4 comments
Labels
status: feedback required feedback required type: question&discussion Further information is requested

Comments

@ChenYilei2016
Copy link

easy api config:

enum.use.custom[groovy:it.isExtend("com.zbycorp.fenghuo.domain.common.constants.BaseEnum")]=code

基类

public interface BaseEnum {
    default String enumClass() {
        return this.getClass().getName();
    }

    /**
     * 枚举一般作为value的字段
     */
    Object getCode();
}

实现类

@Getter
public enum StrategyTypeEnum implements BaseEnum {

    CAMPAIGN_BUDGET("广告活动分时预算"),
    TARGET_BID("分时竞价")

    ;

    private String desc;


    StrategyTypeEnum(String desc) {
        this.desc = desc;
    }


    @Override
    public String getCode() {
        return this.name();
    }
}

使用地方

    /**
     * @see StrategyTypeEnum
     */
    @ApiModelProperty("策略类型")
    private String strategyType;

结果
没有输出任何值, 去掉配置之后 就可以输出了, 不知道为啥, 也没报错

@ChenYilei2016 ChenYilei2016 added the type: bug Something isn't working label Dec 6, 2023
@tangcent
Copy link
Owner

tangcent commented Dec 6, 2023

😂,目前还没有办法解析方法, 虽然你这里的例子并不复杂。

    @Override
    public String getCode() {
        return this.name();
    }

但如果你这里getCode返回的总是name(),那可以试试直接配:

enum.use.custom[groovy:it.isExtend("com.zbycorp.fenghuo.domain.common.constants.BaseEnum")]=name()

@tangcent tangcent added type: question&discussion Further information is requested status: feedback required feedback required and removed type: bug Something isn't working labels Dec 6, 2023
@ChenYilei2016
Copy link
Author

只是部分枚举用到了name() , 还是希望能支持下方法撒 😄

@tangcent
Copy link
Owner

tangcent commented Dec 7, 2023

有尝试过实现方法推断,但是代码逻辑太复杂了可能导致卡死,目前还没有找到好的实现方案。
https://github.com/tangcent/easy-yapi/blob/master/idea-plugin/src/main/kotlin/com/itangcent/idea/plugin/api/DefaultMethodInferHelper.kt


只是部分枚举用到了name()

其他的大概是怎么样的?

@ChenYilei2016
Copy link
Author

就是部分枚举 没有写任何属性, 直接继承了 BaseEnum , 重写了 getCode 直接用的 name() (⊙o⊙)…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback required feedback required type: question&discussion Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants