From 2248e829896e418246df7b57c29d708842e7a57b Mon Sep 17 00:00:00 2001 From: Krisjanis Seglins Date: Tue, 15 Oct 2024 11:32:41 +0300 Subject: [PATCH 1/7] Shows hidden property errors to the form and scroll to it Fixes: #2217 --- packages/ts/react-crud/src/autoform.tsx | 19 +++++++++++---- packages/ts/react-crud/test/autoform.spec.tsx | 23 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/packages/ts/react-crud/src/autoform.tsx b/packages/ts/react-crud/src/autoform.tsx index 17a8847f99..5f59ea7dc8 100644 --- a/packages/ts/react-crud/src/autoform.tsx +++ b/packages/ts/react-crud/src/autoform.tsx @@ -12,6 +12,7 @@ import { type ReactElement, useEffect, useMemo, + useRef, useState, } from 'react'; import { AutoFormField, type AutoFormFieldProps, type FieldOptions } from './autoform-field.js'; @@ -278,6 +279,7 @@ export function AutoForm({ const form = useForm(model, { onSubmit: async (formItem) => service.save(formItem), }); + const formErrorRef = useRef(null); const [formError, setFormError] = useState(''); const [showDeleteDialog, setShowDeleteDialog] = useState(false); const modelInfo = useMemo(() => new ModelInfo(model, itemIdProperty), [model]); @@ -294,21 +296,30 @@ export function AutoForm({ } }, [item]); + useEffect(() => { + formErrorRef.current?.scrollIntoView({ behavior: 'smooth', block: 'end' }); + }, [formError]); + function handleSubmitError(error: unknown) { if (error instanceof ValidationError) { const nonPropertyErrorMessages = error.errors - .filter((validationError) => !validationError.property) - .map((validationError) => validationError.validatorMessage ?? validationError.message); + .filter((validationError) => !validationError.property || typeof validationError.property === 'string') + .map((validationError) => { + const property = typeof validationError.property === 'string' ? `${validationError.property}: ` : ''; + return `${property}${ + validationError.validatorMessage ? validationError.validatorMessage : validationError.message + }`; + }); if (nonPropertyErrorMessages.length > 0) { setFormError( - <> +
Validation errors:
    {nonPropertyErrorMessages.map((message, index) => (
  • {message}
  • ))}
- , +
, ); } } else if (error instanceof EndpointError) { diff --git a/packages/ts/react-crud/test/autoform.spec.tsx b/packages/ts/react-crud/test/autoform.spec.tsx index aafb79782b..554eb7e651 100644 --- a/packages/ts/react-crud/test/autoform.spec.tsx +++ b/packages/ts/react-crud/test/autoform.spec.tsx @@ -429,6 +429,29 @@ describe('@vaadin/hilla-react-crud', () => { expect(result.queryByText('just a message')).to.not.be.null; }); + it('shows error for whole form has string property', async () => { + const service: CrudService & HasTestInfo = createService(personData); + const person = await getItem(service, 1); + // eslint-disable-next-line @typescript-eslint/require-await + service.save = async (_item: Person): Promise => { + const valueError: ValueError = { + property: 'myProp', + message: 'message', + value: person, + validator: { message: 'message', validate: () => false }, + validatorMessage: 'foobar', + }; + throw new ValidationError([valueError]); + }; + + const result = render(); + const form = await FormController.init(user, result.container); + await form.typeInField('First name', 'J'); // to enable the submit button + await form.submit(); + expect(result.queryByText('message')).to.be.null; + expect(result.queryByText('myProp: foobar')).to.not.be.null; + }); + it('shows a predefined error message when the service returns no entity after saving', async () => { const service: CrudService & HasTestInfo = createService(personData); service.save = async (item: Person): Promise => Promise.resolve(undefined); From a8d91e774dc44de2e8b8395c4b0f6da200c19b9e Mon Sep 17 00:00:00 2001 From: Krisjanis Seglins Date: Tue, 15 Oct 2024 11:34:10 +0300 Subject: [PATCH 2/7] Resolve jakarta persistence id and version annotations as nullable by default Fixes: #2809 --- .../java/parser-jvm-plugin-nonnull/pom.xml | 5 ++ .../plugins/nonnull/NonnullPluginConfig.java | 4 + .../plugins/nonnull/nullable/Endpoint.java | 11 +++ .../nonnull/nullable/EndpointExposed.java | 11 +++ .../nonnull/nullable/NullableEndpoint.java | 20 +++++ .../nonnull/nullable/NullableTest.java | 47 +++++++++++ .../plugins/nonnull/nullable/openapi.json | 83 +++++++++++++++++++ .../hilla/test/reactgrid/AbstractEntity.java | 4 - 8 files changed, 181 insertions(+), 4 deletions(-) create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/Endpoint.java create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/EndpointExposed.java create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json diff --git a/packages/java/parser-jvm-plugin-nonnull/pom.xml b/packages/java/parser-jvm-plugin-nonnull/pom.xml index fdabd6e64d..3ba281e4b8 100644 --- a/packages/java/parser-jvm-plugin-nonnull/pom.xml +++ b/packages/java/parser-jvm-plugin-nonnull/pom.xml @@ -54,5 +54,10 @@ ${project.version} test + + jakarta.persistence + jakarta.persistence-api + test + diff --git a/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java b/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java index 50a2530a09..7e74317cc1 100644 --- a/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java +++ b/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java @@ -47,6 +47,10 @@ static class Processor extends ConfigList.Processor { // Package-level annotations have low score new AnnotationMatcher("org.springframework.lang.NonNullApi", false, 10), + // Id and Version annotation usually mark nullable fields for CRUD operations. + // Low score allows other annotations to override them. + new AnnotationMatcher("jakarta.persistence.Id", true, 20), + new AnnotationMatcher("jakarta.persistence.Version", true, 20), // Nullable-like annotations get a higher score. This should // only matter when they are used in conjunction with // package-level annotations diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/Endpoint.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/Endpoint.java new file mode 100644 index 0000000000..e5eab005f8 --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/Endpoint.java @@ -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 { +} diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/EndpointExposed.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/EndpointExposed.java new file mode 100644 index 0000000000..0ed232996c --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/EndpointExposed.java @@ -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 { +} diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java new file mode 100644 index 0000000000..a00f525725 --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java @@ -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; + } +} diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java new file mode 100644 index 0000000000..682796b269 --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java @@ -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()); + } +} diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json b/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json new file mode 100644 index 0000000000..5b4a0ef834 --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json @@ -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 + } + } + } + } + } +} diff --git a/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/AbstractEntity.java b/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/AbstractEntity.java index 6fd3f55640..955cee14bb 100644 --- a/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/AbstractEntity.java +++ b/packages/java/tests/spring/react-grid-test/src/main/java/com/vaadin/hilla/test/reactgrid/AbstractEntity.java @@ -6,17 +6,13 @@ import jakarta.persistence.MappedSuperclass; import jakarta.persistence.Version; -import com.vaadin.hilla.Nullable; - @MappedSuperclass public class AbstractEntity { @Id - @Nullable @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Version - @Nullable private Long version; public Long getId() { From d38a4097540a560c8f7b190d5825a4a774e3e68d Mon Sep 17 00:00:00 2001 From: Kriss Seglins Date: Tue, 15 Oct 2024 11:36:47 +0300 Subject: [PATCH 3/7] fix formatting --- .../hilla/parser/plugins/nonnull/NonnullPluginConfig.java | 3 ++- .../parser/plugins/nonnull/nullable/NullableEndpoint.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java b/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java index 7e74317cc1..40b197e597 100644 --- a/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java +++ b/packages/java/parser-jvm-plugin-nonnull/src/main/java/com/vaadin/hilla/parser/plugins/nonnull/NonnullPluginConfig.java @@ -47,7 +47,8 @@ static class Processor extends ConfigList.Processor { // Package-level annotations have low score new AnnotationMatcher("org.springframework.lang.NonNullApi", false, 10), - // Id and Version annotation usually mark nullable fields for CRUD operations. + // Id and Version annotation usually mark nullable fields for + // CRUD operations. // Low score allows other annotations to override them. new AnnotationMatcher("jakarta.persistence.Id", true, 20), new AnnotationMatcher("jakarta.persistence.Version", true, 20), diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java index a00f525725..a3ab8aed6c 100644 --- a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableEndpoint.java @@ -1,13 +1,13 @@ 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) { + public NullableFieldModel nullableFieldModel( + NullableFieldModel nullableFieldModel) { return nullableFieldModel; } From 36ab823997036ee91fc0c39b337cf6d61ad253d6 Mon Sep 17 00:00:00 2001 From: Krisjanis Seglins Date: Tue, 15 Oct 2024 11:55:53 +0300 Subject: [PATCH 4/7] Fix type check Fixes: #2217 --- packages/ts/react-crud/src/autoform.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/ts/react-crud/src/autoform.tsx b/packages/ts/react-crud/src/autoform.tsx index 5f59ea7dc8..1f63639063 100644 --- a/packages/ts/react-crud/src/autoform.tsx +++ b/packages/ts/react-crud/src/autoform.tsx @@ -305,7 +305,10 @@ export function AutoForm({ const nonPropertyErrorMessages = error.errors .filter((validationError) => !validationError.property || typeof validationError.property === 'string') .map((validationError) => { - const property = typeof validationError.property === 'string' ? `${validationError.property}: ` : ''; + const property = + validationError.property && typeof validationError.property === 'string' + ? `${validationError.property}: ` + : ''; return `${property}${ validationError.validatorMessage ? validationError.validatorMessage : validationError.message }`; From 88a4beffc95a2123d7039f9a990c71ab1ad29e23 Mon Sep 17 00:00:00 2001 From: Krisjanis Seglins Date: Fri, 25 Oct 2024 10:16:27 +0300 Subject: [PATCH 5/7] Add test for nonnull and nullable hierarchy Fixes: #2833 --- .../nonnull/nullable/NullableTest.java | 1 + .../nonNullApi/NullableNonNullEndpoint.java | 25 +++++++ .../nullable/nonNullApi/package-info.java | 4 ++ .../plugins/nonnull/nullable/openapi.json | 67 +++++++++++++++++++ 4 files changed, 97 insertions(+) create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java create mode 100644 packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/package-info.java diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java index 682796b269..4cc06489ee 100644 --- a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/NullableTest.java @@ -5,6 +5,7 @@ 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; diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java new file mode 100644 index 0000000000..da2efdb062 --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java @@ -0,0 +1,25 @@ +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; + } +} diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/package-info.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/package-info.java new file mode 100644 index 0000000000..1f8562e6e5 --- /dev/null +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/package-info.java @@ -0,0 +1,4 @@ +@NonNullApi +package com.vaadin.hilla.parser.plugins.nonnull.nullable.nonNullApi; + +import org.springframework.lang.NonNullApi; diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json b/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json index 5b4a0ef834..07336d76d8 100644 --- a/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/resources/com/vaadin/hilla/parser/plugins/nonnull/nullable/openapi.json @@ -14,6 +14,10 @@ { "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" : { @@ -60,6 +64,48 @@ } } } + }, + "/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" : { @@ -77,6 +123,27 @@ "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" + } + } } } } From 7ae20c5aa1e5cd83dcbea2f2e0abe0c63bb006c4 Mon Sep 17 00:00:00 2001 From: Krisjanis Seglins Date: Fri, 25 Oct 2024 10:17:34 +0300 Subject: [PATCH 6/7] Add test for nonnull and nullable hierarchy Fixes: #2833 --- packages/java/parser-jvm-plugin-nonnull/pom.xml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/java/parser-jvm-plugin-nonnull/pom.xml b/packages/java/parser-jvm-plugin-nonnull/pom.xml index 3ba281e4b8..f976b7fc03 100644 --- a/packages/java/parser-jvm-plugin-nonnull/pom.xml +++ b/packages/java/parser-jvm-plugin-nonnull/pom.xml @@ -54,10 +54,15 @@ ${project.version} test - - jakarta.persistence - jakarta.persistence-api - test - + + jakarta.persistence + jakarta.persistence-api + test + + + org.springframework + spring-core + test + From 74b4a76df687dc45d4171ca1a34d4c466f6c40d5 Mon Sep 17 00:00:00 2001 From: Kriss Seglins Date: Fri, 25 Oct 2024 10:18:28 +0300 Subject: [PATCH 7/7] fix formatting --- .../nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java index da2efdb062..edd5342c0d 100644 --- a/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java +++ b/packages/java/parser-jvm-plugin-nonnull/src/test/java/com/vaadin/hilla/parser/plugins/nonnull/nullable/nonNullApi/NullableNonNullEndpoint.java @@ -8,7 +8,8 @@ @Endpoint public class NullableNonNullEndpoint { - public NullableNonNullFieldModel nullableNonNullFieldModel(NullableNonNullFieldModel nullableNonNullFieldModel) { + public NullableNonNullFieldModel nullableNonNullFieldModel( + NullableNonNullFieldModel nullableNonNullFieldModel) { return nullableNonNullFieldModel; }