Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

scala - How to generate validators file only for message that contains validate rules?

How to generate validator file only for message that contains validates rules ?

In the example below, actually sbt compilation generates 4 scala classes: one for protobufA, one for protobufB and one validator message for both.

    int32 id = 1;
    string action = 2 [(validate.rules).string = {in: ["tonic", "gin", "martini"]}];
}
message protobufB {
    option (scalapb.message).annotations = "@JsonNaming(classOf[SnakeCaseStrategy])";
    int32 id = 1;
    string name = 2 ;
}

I would like to generate only three classes : one for protobufA, one for protobufB and the last for protobufA validator classes.

I have version 0.1.3 of scalapb-validate-codegen.

question from:https://stackoverflow.com/questions/66059344/how-to-generate-validators-file-only-for-message-that-contains-validate-rules

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is currently (as of version 0.2.1 of scalapb-validate) no way to suppress the generation of validation classes once you add the validation plugin. The only way, right now to do that would be to separate the messages you don't want to have validators for to separate SBT subprojects which doesn't have the validator plugin turned on.

Feel free to start a github issue on scalapb-validate github to discuss this as a feature request, and include also the motivation for a change like this. This would require some thought since messages that have validators require all the message that they transitively reference to have validators as well, so the plugin would have to detect this situation when disabling generation.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...