hilla icon indicating copy to clipboard operation
hilla copied to clipboard

Bean Validation annotations are ignored if class is in dependency

Open simasch opened this issue 3 years ago • 4 comments
trafficstars

I've found a very strange issue.

I have two projects.

  1. Spring Boot App with Hilla
  2. 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]);
  }
}

simasch avatar Aug 05 '22 13:08 simasch

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.

cromoteca avatar Aug 05 '22 14:08 cromoteca

Ok. But why does it parse the sources? Wouldn't it be easier to parse the compiled classes?

simasch avatar Aug 05 '22 14:08 simasch

That's what version 1.2 does.

cromoteca avatar Aug 05 '22 14:08 cromoteca

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.

Legioth avatar Aug 05 '22 18:08 Legioth

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

platosha avatar Aug 23 '22 11:08 platosha