OkaeriPoland / okaeri-configs

Simple Java/POJO config library written with love and Lombok
MIT License
77 stars 11 forks source link

Subconfigurations validation seem to be not implemented #32

Open Brikster opened 2 years ago

Brikster commented 2 years ago

Describe the bug I have such code:

@Getter
@SuppressWarnings("FieldMayBeFinal")
@Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
public class ModerationConfig extends OkaeriConfig {

    private CapsModerationConfig caps = new CapsModerationConfig();

    @Positive
    private int exampleField = 6;

    @Getter
    @SuppressWarnings("FieldMayBeFinal")
    @Names(strategy = NameStrategy.HYPHEN_CASE, modifier = NameModifier.TO_LOWER_CASE)
    public static class CapsModerationConfig extends OkaeriConfig {

        private boolean enable = true;

        @Positive
        private int length = 6;

        @Min(0) @Max(100)
        private int percent = 80;

        private boolean block = true;

    }

}

If I set "exampleField" and "length" to zeros, I get exception only for the field from topper class. If I set to zero "length" only, result is the same.

Library version

implementation 'eu.okaeri:okaeri-configs-yaml-bukkit:4.0.6'
implementation 'eu.okaeri:okaeri-configs-serdes-commons:4.0.6'
implementation 'eu.okaeri:okaeri-configs-serdes-bukkit:4.0.6'
implementation 'eu.okaeri:okaeri-configs-validator-okaeri:4.0.6'
dasavick commented 1 year ago

After giving it some thought (about half a year it seems), I believe this is actually a okaeri-validator limitation (related to OkaeriPoland/okaeri-validator#2) and not something to be fixed in the okaeri-configs directly.

I guess in the meanwhile, validator-jakartaee is a viable alternative. It may require @Valid annotation on the parent field, but that should be all that's needed to get multi level validation working.