-
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.
Resolve jakarta persistence id and version annotations as nullable by…
… default Fixes: #2809
- Loading branch information
Showing
8 changed files
with
181 additions
and
4 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; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...-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,47 @@ | ||
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.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()); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
...-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,83 @@ | ||
{ | ||
"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" | ||
} | ||
], | ||
"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" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"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 | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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