-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: show autoform non-rendered property errors (#2833)
* Shows hidden property errors to the form and scroll to it Fixes: #2217 * Resolve jakarta persistence id and version annotations as nullable by default Fixes: #2809 * fix formatting * Fix type check Fixes: #2217 * Add test for nonnull and nullable hierarchy Fixes: #2833 * Add test for nonnull and nullable hierarchy Fixes: #2833 * fix formatting --------- Co-authored-by: Anton Platonov <platosha@gmail.com>
- Loading branch information
Showing
12 changed files
with
326 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...ugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/Endpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vaadin.hilla.parser.plugins.nonnull.nullable; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface Endpoint { | ||
} |
11 changes: 11 additions & 0 deletions
11
...nnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/EndpointExposed.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.vaadin.hilla.parser.plugins.nonnull.nullable; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface EndpointExposed { | ||
} |
20 changes: 20 additions & 0 deletions
20
...null/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.vaadin.hilla.parser.plugins.nonnull.nullable; | ||
|
||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Version; | ||
|
||
@Endpoint | ||
public class NullableEndpoint { | ||
|
||
public NullableFieldModel nullableFieldModel( | ||
NullableFieldModel nullableFieldModel) { | ||
return nullableFieldModel; | ||
} | ||
|
||
public static class NullableFieldModel { | ||
@Id | ||
public String id; | ||
@Version | ||
public Long version; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.vaadin.hilla.parser.plugins.nonnull.nullable; | ||
|
||
import com.vaadin.hilla.parser.core.Parser; | ||
import com.vaadin.hilla.parser.plugins.backbone.BackbonePlugin; | ||
import com.vaadin.hilla.parser.plugins.nonnull.AnnotationMatcher; | ||
import com.vaadin.hilla.parser.plugins.nonnull.NonnullPlugin; | ||
import com.vaadin.hilla.parser.plugins.nonnull.NonnullPluginConfig; | ||
import com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi.NullableNonNullEndpoint; | ||
import com.vaadin.hilla.parser.plugins.nonnull.test.helpers.TestHelper; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.net.URISyntaxException; | ||
import java.util.Set; | ||
|
||
public class NullableTest { | ||
private final TestHelper helper = new TestHelper(getClass()); | ||
|
||
@Test | ||
public void should_ApplyNullableAnnotation() | ||
throws IOException, URISyntaxException { | ||
var plugin = new NonnullPlugin(); | ||
plugin.setConfiguration(new NonnullPluginConfig()); | ||
|
||
var openAPI = new Parser().classLoader(getClass().getClassLoader()) | ||
.classPath(Set.of(helper.getTargetDir().toString())) | ||
.endpointAnnotation(Endpoint.class.getName()) | ||
.endpointExposedAnnotation(EndpointExposed.class.getName()) | ||
.addPlugin(new BackbonePlugin()).addPlugin(plugin).execute(); | ||
|
||
helper.executeParserWithConfig(openAPI); | ||
} | ||
|
||
@Test | ||
public void annotationMatcher_shouldHaveDefaultConstructorAndSetter() { | ||
// to enable maven initialize instances of AnnotationMatcher from | ||
// pom.xml configurations, properly, it should have the default | ||
// constructor and setter methods: | ||
AnnotationMatcher annotationMatcher = new AnnotationMatcher(); | ||
annotationMatcher.setName("name"); | ||
annotationMatcher.setScore(100); | ||
annotationMatcher.setMakesNullable(true); | ||
Assertions.assertEquals("name", annotationMatcher.getName()); | ||
Assertions.assertEquals(100, annotationMatcher.getScore()); | ||
Assertions.assertTrue(annotationMatcher.doesMakeNullable()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
.../com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi; | ||
|
||
import com.vaadin.hilla.parser.plugins.nonnull.nullable.Endpoint; | ||
import jakarta.annotation.Nonnull; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Version; | ||
|
||
@Endpoint | ||
public class NullableNonNullEndpoint { | ||
|
||
public NullableNonNullFieldModel nullableNonNullFieldModel( | ||
NullableNonNullFieldModel nullableNonNullFieldModel) { | ||
return nullableNonNullFieldModel; | ||
} | ||
|
||
public static class NullableNonNullFieldModel { | ||
public String required; | ||
@Id | ||
public String id; | ||
@Version | ||
public Long version; | ||
@Version | ||
@Nonnull | ||
public Long notNullVersion; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...c/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
@NonNullApi | ||
package com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi; | ||
|
||
import org.springframework.lang.NonNullApi; |
150 changes: 150 additions & 0 deletions
150
...-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
{ | ||
"openapi" : "3.0.1", | ||
"info" : { | ||
"title" : "Hilla Application", | ||
"version" : "1.0.0" | ||
}, | ||
"servers" : [ | ||
{ | ||
"url" : "http://localhost:8080/connect", | ||
"description" : "Hilla Backend" | ||
} | ||
], | ||
"tags" : [ | ||
{ | ||
"name" : "NullableEndpoint", | ||
"x-class-name" : "com.vaadin.hilla.parser.plugins.nonnull.nullable.NullableEndpoint" | ||
}, | ||
{ | ||
"name" : "NullableNonNullEndpoint", | ||
"x-class-name" : "com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi.NullableNonNullEndpoint" | ||
} | ||
], | ||
"paths" : { | ||
"/NullableEndpoint/nullableFieldModel" : { | ||
"post" : { | ||
"tags" : [ | ||
"NullableEndpoint" | ||
], | ||
"operationId" : "NullableEndpoint_nullableFieldModel_POST", | ||
"requestBody" : { | ||
"content" : { | ||
"application/json" : { | ||
"schema" : { | ||
"type" : "object", | ||
"properties" : { | ||
"nullableFieldModel" : { | ||
"nullable" : true, | ||
"anyOf" : [ | ||
{ | ||
"$ref" : "#/components/schemas/com.vaadin.hilla.parser.plugins.nonnull.nullable.NullableEndpoint$NullableFieldModel" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses" : { | ||
"200" : { | ||
"description" : "", | ||
"content" : { | ||
"application/json" : { | ||
"schema" : { | ||
"nullable" : true, | ||
"anyOf" : [ | ||
{ | ||
"$ref" : "#/components/schemas/com.vaadin.hilla.parser.plugins.nonnull.nullable.NullableEndpoint$NullableFieldModel" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"/NullableNonNullEndpoint/nullableNonNullFieldModel" : { | ||
"post" : { | ||
"tags" : [ | ||
"NullableNonNullEndpoint" | ||
], | ||
"operationId" : "NullableNonNullEndpoint_nullableNonNullFieldModel_POST", | ||
"requestBody" : { | ||
"content" : { | ||
"application/json" : { | ||
"schema" : { | ||
"type" : "object", | ||
"properties" : { | ||
"nullableNonNullFieldModel" : { | ||
"anyOf" : [ | ||
{ | ||
"$ref" : "#/components/schemas/com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi.NullableNonNullEndpoint$NullableNonNullFieldModel" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses" : { | ||
"200" : { | ||
"description" : "", | ||
"content" : { | ||
"application/json" : { | ||
"schema" : { | ||
"anyOf" : [ | ||
{ | ||
"$ref" : "#/components/schemas/com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi.NullableNonNullEndpoint$NullableNonNullFieldModel" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"components" : { | ||
"schemas" : { | ||
"com.vaadin.hilla.parser.plugins.nonnull.nullable.NullableEndpoint$NullableFieldModel" : { | ||
"type" : "object", | ||
"properties" : { | ||
"id" : { | ||
"type" : "string", | ||
"nullable" : true | ||
}, | ||
"version" : { | ||
"type" : "integer", | ||
"format" : "int64", | ||
"nullable" : true | ||
} | ||
} | ||
}, | ||
"com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi.NullableNonNullEndpoint$NullableNonNullFieldModel" : { | ||
"type" : "object", | ||
"properties" : { | ||
"required" : { | ||
"type" : "string" | ||
}, | ||
"id" : { | ||
"type" : "string", | ||
"nullable" : true | ||
}, | ||
"version" : { | ||
"type" : "integer", | ||
"format" : "int64", | ||
"nullable" : true | ||
}, | ||
"notNullVersion" : { | ||
"type" : "integer", | ||
"format" : "int64" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.