From 62d00e687f74fb921082bf659faa212bec79a1bf Mon Sep 17 00:00:00 2001 From: Frederik Hahne Date: Fri, 17 Jul 2020 23:35:56 +0200 Subject: [PATCH] put introspected on dtos such that they can be validated closes #103 --- .../src/main/java/package/service/dto/EntityDTO.java.ejs | 2 ++ .../src/main/java/package/web/rest/EntityResource.java.ejs | 7 ++----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/generators/entity-server/templates/src/main/java/package/service/dto/EntityDTO.java.ejs b/generators/entity-server/templates/src/main/java/package/service/dto/EntityDTO.java.ejs index d082465d..1a4a4a8a 100644 --- a/generators/entity-server/templates/src/main/java/package/service/dto/EntityDTO.java.ejs +++ b/generators/entity-server/templates/src/main/java/package/service/dto/EntityDTO.java.ejs @@ -18,6 +18,7 @@ -%> package <%= packageName %>.service.dto; +import io.micronaut.core.annotation.Introspected; <%_ let { importApiModelProperty, importJsonIgnore, importJsonIgnoreProperties, importSet, uniqueEnums } = _processJavaEntityImports(fields, relationships); _%> @@ -69,6 +70,7 @@ import <%= packageName %>.domain.enumeration.<%= element %>; <%_ if (typeof javadoc !== 'undefined') { _%> @ApiModel(description = "<%- formatAsApiDescription(javadoc) %>") <%_ } _%> +@Introspected public class <%= asDto(entityClass) %> implements Serializable { private <%= primaryKeyType %> id; diff --git a/generators/entity-server/templates/src/main/java/package/web/rest/EntityResource.java.ejs b/generators/entity-server/templates/src/main/java/package/web/rest/EntityResource.java.ejs index 0748a56b..e7ec3b19 100644 --- a/generators/entity-server/templates/src/main/java/package/web/rest/EntityResource.java.ejs +++ b/generators/entity-server/templates/src/main/java/package/web/rest/EntityResource.java.ejs @@ -113,9 +113,6 @@ import org.springframework.http.HttpStatus; %> import reactor.core.publisher.Flux; <%_ } _%> import javax.annotation.Nullable; -<%_ if (validation) { _%> -import javax.validation.Valid; -<%_ } _%> import java.net.URI; import java.net.URISyntaxException; <%_ if (pagination === 'no' && dto === 'mapstruct' && !viaService && fieldsContainNoOwnerOneToOne === true) { _%> @@ -172,7 +169,7 @@ public class <%= entityClass %>Resource { */ @Post("/<%= entityApiUrl %>") @ExecuteOn(TaskExecutors.IO) - public HttpResponse<<%= instanceType %>> create<%= entityClass %>(<% if (validation) { %>@Valid <% } %>@Body <%= instanceType %> <%= instanceName %>) throws URISyntaxException { + public HttpResponse<<%= instanceType %>> create<%= entityClass %>(@Body <%= instanceType %> <%= instanceName %>) throws URISyntaxException { log.debug("REST request to save <%= entityClass %> : {}", <%= instanceName %>); if (<%= instanceName %>.getId() != null) { throw new BadRequestAlertException("A new <%= entityInstance %> cannot already have an ID", ENTITY_NAME, "idexists"); @@ -212,7 +209,7 @@ public class <%= entityClass %>Resource { */ @Put("/<%= entityApiUrl %>") @ExecuteOn(TaskExecutors.IO) - public HttpResponse<<%= instanceType %>> update<%= entityClass %>(<% if (validation) { %>@Valid <% } %>@Body <%= instanceType %> <%= instanceName %>) throws URISyntaxException { + public HttpResponse<<%= instanceType %>> update<%= entityClass %>(@Body <%= instanceType %> <%= instanceName %>) throws URISyntaxException { log.debug("REST request to update <%= entityClass %> : {}", <%= instanceName %>); if (<%= instanceName %>.getId() == null) { throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull");