hilla
hilla copied to clipboard
Bean Validation annotations are ignored if class is in dependency
I've found a very strange issue.
I have two projects.
- Spring Boot App with Hilla
- Simply dependency with classes with Bean Validation annotations
The generator only generates the Model correctly for project 1 but not for project 2.
I assume the generator scans the source code, not the class files.
Example
public class Animal {
@NotBlank
@Email
private String email;
is generated as
export default class AnimalModel<T extends Animal = Animal> extends ObjectModel<T> {
static createEmptyValue: () => Animal;
get email(): StringModel {
return this[_getPropertyModel]('email', StringModel, [true]);
}
}
The generator only parses sources in the module the Hilla application is in. That's by design. Work is in progress in version 1.2.0 to overcome this limitation.
Ok. But why does it parse the sources? Wouldn't it be easier to parse the compiled classes?
That's what version 1.2 does.
The original reason for parsing sources is that we wanted to carry over method parameter names and JavaDocs to the generated TS. The new architecture uses bytecode as the main input and then supplements with additional details from sources if available.
As mentioned, this is a limitation of a source-based parser.
Let me close this, as we are focusing on the multi-module engine to overcome this particular and some other limitations. See https://github.com/vaadin/hilla/issues/123