From 70eb6abec306529c5036c4e55ef5eed7009faa06 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sat, 31 Aug 2024 09:54:24 +0100 Subject: [PATCH 01/11] [plugins/backend-application-default] improves sonnar reports --- .../src/test/java/ArchitectureTest.java.hbs | 2 +- .../jpa/imperative/ServiceTest.java.hbs | 2 +- .../mongodb/imperative/ServiceTest.java.hbs | 2 +- .../EntityRepositoryIntegrationTest.java.hbs | 30 +++++++++---------- .../EntityRepositoryIntegrationTest.java.hbs | 12 ++++---- 5 files changed, 24 insertions(+), 24 deletions(-) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/ArchitectureTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/ArchitectureTest.java.hbs index ae429864..53dac8a1 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/ArchitectureTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/ArchitectureTest.java.hbs @@ -12,7 +12,7 @@ import static com.tngtech.archunit.library.Architectures.layeredArchitecture; import static com.tngtech.archunit.library.Architectures.onionArchitecture; @AnalyzeClasses(packages = "{{basePackage}}", importOptions = DoNotIncludeTests.class) -public class ArchitectureTest { +class ArchitectureTest { /** * Validates that dependencies between layers respect hexagonal/onion/clean architecture. diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs index 6f91a924..0d29bc3b 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/jpa/imperative/ServiceTest.java.hbs @@ -29,7 +29,7 @@ import static org.mockito.Mockito.*; /** * Acceptance Test for {{service.name}}. */ -public class {{service.name}}Test { +class {{service.name}}Test { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs index 130b935a..02de272c 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/core/implementation/mongodb/imperative/ServiceTest.java.hbs @@ -28,7 +28,7 @@ import static org.mockito.Mockito.*; /** * Acceptance Test for {{service.name}}. */ -public class {{service.name}}Test { +class {{service.name}}Test { private final Logger log = LoggerFactory.getLogger(getClass()); diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs index d5101717..a674c150 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/jpa/imperative/EntityRepositoryIntegrationTest.java.hbs @@ -13,7 +13,7 @@ import org.springframework.beans.factory.annotation.Autowired; import jakarta.persistence.EntityManager; -public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositoryIntegrationTest { +class {{entity.className}}RepositoryIntegrationTest extends BaseRepositoryIntegrationTest { @Autowired EntityManager entityManager; @@ -22,26 +22,26 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor {{entity.className}}Repository {{entity.instanceName}}Repository; @Test - public void findAllTest() { + void findAllTest() { var results = {{entity.instanceName}}Repository.findAll(); Assertions.assertFalse(results.isEmpty()); } @Test - public void findByIdTest() { + void findByIdTest() { var id = 1L; var {{entity.instanceName}} = {{entity.instanceName}}Repository.findById(id).orElseThrow(); - Assertions.assertTrue({{entity.instanceName}}.getId() != null); - Assertions.assertTrue({{entity.instanceName}}.getVersion() != null); + Assertions.assertNotNull({{entity.instanceName}}.getId()); + Assertions.assertNotNull({{entity.instanceName}}.getVersion()); {{~#if (or entity.options.auditing entity.options.extendsAuditing)}} - Assertions.assertTrue({{entity.instanceName}}.getCreatedBy() != null); - Assertions.assertTrue({{entity.instanceName}}.getCreatedDate() != null); + Assertions.assertNotNull({{entity.instanceName}}.getCreatedBy()); + Assertions.assertNotNull({{entity.instanceName}}.getCreatedDate()); {{~/if}} } @Test - public void saveTest() { + void saveTest() { {{entity.className}} {{entity.instanceName}} = new {{entity.className}}(); {{~#each entity.fields as |field|}} {{entity.instanceName}}.set{{capitalize field.name}}({{{populateField field}}}); @@ -79,18 +79,18 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor // reloading to get relationships persisted by id entityManager.flush(); entityManager.refresh(created); - Assertions.assertTrue(created.getId() != null); - Assertions.assertTrue(created.getVersion() != null); + Assertions.assertNotNull(created.getId()); + Assertions.assertNotNull(created.getVersion()); {{~#if (or entity.options.auditing entity.options.extendsAuditing)}} - Assertions.assertTrue(created.getCreatedBy() != null); - Assertions.assertTrue(created.getCreatedDate() != null); + Assertions.assertNotNull(created.getCreatedBy()); + Assertions.assertNotNull(created.getCreatedDate()); {{~/if}} {{#each entity.relationships as |relationship|}} {{~#if relationship.fieldName}} {{~#if relationship.ownerSide}} {{~#if (endsWith relationship.type 'OneToOne')}} - Assertions.assertTrue({{entity.instanceName}}.get{{capitalize relationship.fieldName}}().getId() != null); + Assertions.assertNotNull({{entity.instanceName}}.get{{capitalize relationship.fieldName}}().getId() != null); {{~else if (endsWith relationship.type 'ToOne')}} Assertions.assertTrue({{entity.instanceName}}.get{{capitalize relationship.fieldName}}().getId() == {{relationship.fieldName}}Id); {{~else}} @@ -102,7 +102,7 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor } @Test - public void updateTest() { + void updateTest() { var id = 1L; var {{entity.instanceName}} = {{entity.instanceName}}Repository.findById(id).orElseThrow(); {{~#each entity.fields as |field|}} @@ -116,7 +116,7 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor } @Test - public void deleteTest() { + void deleteTest() { var id = 1L; {{entity.instanceName}}Repository.deleteById(id); var notFound = {{entity.instanceName}}Repository.findById(id); diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs index 2c5cbdf1..10a5a52d 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/infrastructure/mongodb/imperative/EntityRepositoryIntegrationTest.java.hbs @@ -6,20 +6,20 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositoryIntegrationTest { +class {{entity.className}}RepositoryIntegrationTest extends BaseRepositoryIntegrationTest { @Autowired {{entity.className}}Repository {{entity.instanceName}}Repository; @Test - public void findAllTest() { + void findAllTest() { var results = {{entity.instanceName}}Repository.findAll(); Assertions.assertFalse(results.isEmpty()); } @Test - public void findByIdTest() { + void findByIdTest() { var id = "1"; var {{entity.instanceName}} = {{entity.instanceName}}Repository.findById(id).orElseThrow(); Assertions.assertTrue({{entity.instanceName}}.getId() != null); @@ -30,7 +30,7 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor } @Test - public void saveTest() { + void saveTest() { {{entity.className}} {{entity.instanceName}} = new {{entity.className}}(); {{~#each entity.fields as |field|}} {{entity.instanceName}}.set{{capitalize field.name}}(null); @@ -45,7 +45,7 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor } @Test - public void updateTest() { + void updateTest() { var id = "1"; var {{entity.instanceName}} = {{entity.instanceName}}Repository.findById(id).orElseThrow(); {{~#each entity.fields as |field|}} @@ -59,7 +59,7 @@ public class {{entity.className}}RepositoryIntegrationTest extends BaseRepositor } @Test - public void deleteTest() { + void deleteTest() { var id = "1"; {{entity.instanceName}}Repository.deleteById(id); var notFound = {{entity.instanceName}}Repository.findById(id); From 37e4ebc3a7f024ebb4ee76a5b6cda5c77e19f1b4 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sat, 31 Aug 2024 09:59:14 +0100 Subject: [PATCH 02/11] [plugins/openapi-controllers] implements pageOf method with sorting --- .../src/main/java/web/mvc/ServiceApiController.java.hbs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs index c19d56fd..df7f3c9d 100644 --- a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs +++ b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs @@ -24,6 +24,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.web.context.request.NativeWebRequest; @@ -102,6 +103,12 @@ public class {{serviceName}}ApiController implements {{serviceName}}Api { {{~/each}} protected Pageable pageOf(Optional page, Optional limit, Optional> sort) { - return PageRequest.of(page.orElse(0), limit.orElse(10)); + Sort sortOrder = sort.map(s -> Sort.by(s.stream().map(sortParam -> { + String[] parts = sortParam.split(":"); + String property = parts[0]; + Sort.Direction direction = parts.length > 1 ? Sort.Direction.fromString(parts[1]) : Sort.Direction.ASC; + return new Sort.Order(direction, property); + }).toList())).orElse(Sort.unsorted()); + return PageRequest.of(page.orElse(0), limit.orElse(10), sortOrder); } } From 5dfb6ab41abd3e34e42102af95b37538c8326f14 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Sun, 1 Sep 2024 11:29:14 +0100 Subject: [PATCH 03/11] [plugins/asyncapi-spring-cloud-streams3] adds support for `modelNamePrefix` and `modelNameSuffix` --- plugins/asyncapi-spring-cloud-streams3/README.md | 2 ++ .../io/zenwave360/sdk/processors/AsyncApiProcessor.java | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/asyncapi-spring-cloud-streams3/README.md b/plugins/asyncapi-spring-cloud-streams3/README.md index 6404aea6..ff77031f 100644 --- a/plugins/asyncapi-spring-cloud-streams3/README.md +++ b/plugins/asyncapi-spring-cloud-streams3/README.md @@ -82,6 +82,8 @@ jbang zw -p io.zenwave360.sdk.plugins.SpringCloudStreams3Plugin --help | `exposeMessage` | Whether to expose underlying spring Message to consumers or not. | boolean | false | | | `apiPackage` | Java API package name for producerApiPackage and consumerApiPackage if not specified. | String | | | | `modelPackage` | Java Models package name | String | | | +| `modelNamePrefix` | Sets the prefix for model classes and enums | String | | | +| `modelNameSuffix` | Sets the suffix for model classes and enums | String | | | | `producerApiPackage` | Java API package name for outbound (producer) services. It can override apiPackage for producers. | String | {{apiPackage}} | | | `consumerApiPackage` | Java API package name for inbound (consumer) services. It can override apiPackage for consumer. | String | {{apiPackage}} | | | `bindingTypes` | Binding names to include in code generation. Generates code for ALL bindings if left empty | List | | | diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java index 5741a43d..3c40ccd3 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java @@ -72,6 +72,12 @@ public String getSchemaFormat(String asyncApiVersion) { } + @DocumentedOption(description = "Sets the prefix for model classes and enums") + public String modelNamePrefix; + + @DocumentedOption(description = "Sets the suffix for model classes and enums") + public String modelNameSuffix; + @DocumentedOption(description = "AsyncAPI extension property name for runtime autoconfiguration of headers.") public String runtimeHeadersProperty = "x-runtime-expression"; @@ -226,7 +232,7 @@ public void calculateMessageParamType(Map apiModel, Map Date: Sun, 1 Sep 2024 11:49:35 +0100 Subject: [PATCH 04/11] [plugins/asyncapi-spring-cloud-streams3] adds support for `modelNamePrefix` and `modelNameSuffix` --- .../io/zenwave360/sdk/processors/AsyncApiProcessor.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java index 3c40ccd3..b9118217 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/processors/AsyncApiProcessor.java @@ -73,10 +73,10 @@ public String getSchemaFormat(String asyncApiVersion) { } @DocumentedOption(description = "Sets the prefix for model classes and enums") - public String modelNamePrefix; + public String modelNamePrefix = ""; @DocumentedOption(description = "Sets the suffix for model classes and enums") - public String modelNameSuffix; + public String modelNameSuffix = ""; @DocumentedOption(description = "AsyncAPI extension property name for runtime autoconfiguration of headers.") public String runtimeHeadersProperty = "x-runtime-expression"; @@ -232,8 +232,9 @@ public void calculateMessageParamType(Map apiModel, Map Date: Tue, 17 Sep 2024 12:30:25 +0200 Subject: [PATCH 05/11] [plugins/backend-application-default] improves DockerComposeInitializer and TestDataLoader --- .../config/DockerComposeInitializer-jpa.java.hbs | 13 +++++-------- .../DockerComposeInitializer-mongodb.java.hbs | 14 +++++--------- .../test/java/config/TestDataLoader-jpa.java.hbs | 5 ++++- 3 files changed, 14 insertions(+), 18 deletions(-) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-jpa.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-jpa.java.hbs index 03883eb8..df083df9 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-jpa.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-jpa.java.hbs @@ -88,7 +88,7 @@ public class DockerComposeInitializer implements ApplicationContextInitializer { try { - return getDockerComposeRunningServices(cmd, "-f", DOCKER_COMPOSE_FILE, "ps").containsAll(serviceNames); + return getDockerComposeRunningServices(cmd, "-f", DOCKER_COMPOSE_FILE, "ps", "--services").containsAll(serviceNames); } catch (IOException | InterruptedException e) { return false; @@ -104,16 +104,13 @@ public class DockerComposeInitializer implements ApplicationContextInitializer SERVICE_COLUMN) { - services.add(columns[SERVICE_COLUMN]); - } - } + if (!line.isEmpty()) { + services.add(line); + } } process.waitFor(); - return services.size() > 1? services.subList(1, services.size()) : services; + return services; } boolean isPortOpen(String host, int port) { diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-mongodb.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-mongodb.java.hbs index a53a8882..122c276f 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-mongodb.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/DockerComposeInitializer-mongodb.java.hbs @@ -88,7 +88,7 @@ public class DockerComposeInitializer implements ApplicationContextInitializer { try { - return getDockerComposeRunningServices(cmd, "-f", DOCKER_COMPOSE_FILE, "ps").containsAll(serviceNames); + return getDockerComposeRunningServices(cmd, "-f", DOCKER_COMPOSE_FILE, "ps", "--services").containsAll(serviceNames); } catch (IOException | InterruptedException e) { return false; @@ -96,7 +96,6 @@ public class DockerComposeInitializer implements ApplicationContextInitializer getDockerComposeRunningServices(String... command) throws IOException, InterruptedException { List services = new ArrayList<>(); var process = new ProcessBuilder(command).start(); @@ -104,16 +103,13 @@ public class DockerComposeInitializer implements ApplicationContextInitializer SERVICE_COLUMN) { - services.add(columns[SERVICE_COLUMN]); - } - } + if (!line.isEmpty()) { + services.add(line); + } } process.waitFor(); - return services.size() > 1? services.subList(1, services.size()) : services; + return services; } boolean isPortOpen(String host, int port) { diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs index 09994b47..2e6b43df 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs @@ -15,7 +15,10 @@ public class TestDataLoader { private List> jpaManagedTypes; - private ObjectMapper objectMapper = new ObjectMapper(); + private final ObjectMapper objectMapper = new ObjectMapper(); + { + objectMapper.registerModule(new JavaTimeModule()); + } public TestDataLoader(List> jpaManagedTypes) { this.jpaManagedTypes = jpaManagedTypes; From c9c51b233b229ec409bb7ea1cf101bd3769b4756 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Tue, 17 Sep 2024 12:31:57 +0200 Subject: [PATCH 06/11] [plugins/backend-application-default] postgres: remove @SequenceGenerator "name" for using hibernate 6 default. --- .../src/main/java/core/domain/jpa/partials/id/postgresql.hbs | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/postgresql.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/postgresql.hbs index 1517a8ed..10f4d16b 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/postgresql.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/postgresql.hbs @@ -1,3 +1,2 @@ @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) - @SequenceGenerator(name = "sequenceGenerator") From 6eb20e42563293dad5a8ee7906e9f5ab3a5a4d2a Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Tue, 17 Sep 2024 12:33:18 +0200 Subject: [PATCH 07/11] [plugins/openapi-controllers] remove `@Override` in generated code to avoid conflicts with openapi-generator settings. --- .../src/main/java/web/mvc/ServiceApiController.java.hbs | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs index df7f3c9d..7cd79abe 100644 --- a/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs +++ b/plugins/openapi-controllers/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIControllersGenerator/src/main/java/web/mvc/ServiceApiController.java.hbs @@ -57,7 +57,6 @@ public class {{serviceName}}ApiController implements {{serviceName}}Api { {{/joinWithTemplate}} } - @Override public Optional getRequest() { return Optional.ofNullable(request); } From 8c2d0cb45e7bc20eb538d67bc63b5cc6766448ba Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Tue, 17 Sep 2024 12:34:36 +0200 Subject: [PATCH 08/11] [plugins/zdl-to-openapi] makes requestBody required true (compatiblity with latest openapi generator 7.x) --- .../sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs | 1 + 1 file changed, 1 insertion(+) diff --git a/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs b/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs index 4ba0d684..72cf1e76 100644 --- a/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs +++ b/plugins/zdl-to-openapi/src/main/resources/io/zenwave360/sdk/plugins/ZDLToOpenAPIGenerator/ZDLToOpenAPI.yml.hbs @@ -66,6 +66,7 @@ paths: {{~/if}} {{~#if (and operation.requestBody (or (eq operation.httpMethod 'post') (eq operation.httpMethod 'put') (eq operation.httpMethod 'patch') ))}} requestBody: + required: true content: application/json: schema: From a05872f372595b4bc00df90f05e757db7b21a329 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Tue, 17 Sep 2024 12:44:53 +0200 Subject: [PATCH 09/11] [plugins/backend-application-default] adds spring-boot-starter-json in testing projects --- .../resources/projects/customer-address-postgres-json/pom.xml | 4 ++++ .../resources/projects/customer-address-relational/pom.xml | 4 ++++ .../resources/projects/online-food-delivery-mongo/pom.xml | 4 ++++ .../test/resources/projects/simple-domain-packaging/pom.xml | 4 ++++ .../src/test/resources/jpa-elasticsearch-scs3-pom.xml | 4 ++++ .../src/test/resources/mongodb-elasticsearch-scs3-pom.xml | 4 ++++ 6 files changed, 24 insertions(+) diff --git a/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml b/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml index aa935be6..eba38074 100644 --- a/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml +++ b/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml @@ -47,6 +47,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-json + org.springframework.boot spring-boot-starter-security diff --git a/e2e/src/test/resources/projects/customer-address-relational/pom.xml b/e2e/src/test/resources/projects/customer-address-relational/pom.xml index 7c01b5e6..678293e0 100644 --- a/e2e/src/test/resources/projects/customer-address-relational/pom.xml +++ b/e2e/src/test/resources/projects/customer-address-relational/pom.xml @@ -47,6 +47,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-json + org.springframework.boot spring-boot-starter-security diff --git a/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml b/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml index 9cce69c2..4d396abc 100644 --- a/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml +++ b/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml @@ -182,6 +182,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-json + org.springframework.boot spring-boot-starter-security diff --git a/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml b/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml index be9fb79f..c47b3384 100644 --- a/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml +++ b/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml @@ -47,6 +47,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-json + org.springframework.boot spring-boot-starter-security diff --git a/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml b/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml index 375a6c51..47d5453a 100644 --- a/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml +++ b/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml @@ -76,6 +76,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-json + org.springframework.cloud spring-cloud-starter-stream-kafka diff --git a/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml b/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml index 79887e20..99f7bc5d 100644 --- a/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml +++ b/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml @@ -76,6 +76,10 @@ org.springframework.boot spring-boot-starter-web + + org.springframework.boot + spring-boot-starter-json + org.springframework.cloud spring-cloud-starter-stream-kafka From 7dfdab8b16143de7413cec9dc186b366c96639b9 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Tue, 17 Sep 2024 13:13:36 +0200 Subject: [PATCH 10/11] [plugins/backend-application-default] adds spring-boot-starter-json in testing projects --- .../src/test/java/config/TestDataLoader-jpa.java.hbs | 1 + .../src/test/resources/jpa-elasticsearch-scs3-pom.xml | 2 +- .../src/test/resources/mongodb-elasticsearch-scs3-pom.xml | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs index 2e6b43df..6a266c86 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/test/java/config/TestDataLoader-jpa.java.hbs @@ -1,6 +1,7 @@ package {{basePackage}}.config; import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import com.fasterxml.jackson.databind.ObjectMapper; import jakarta.persistence.Table; diff --git a/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml b/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml index 47d5453a..1c792924 100644 --- a/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml +++ b/plugins/backend-application-default/src/test/resources/jpa-elasticsearch-scs3-pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.3.1 tests diff --git a/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml b/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml index 99f7bc5d..c425f409 100644 --- a/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml +++ b/plugins/backend-application-default/src/test/resources/mongodb-elasticsearch-scs3-pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.3.1 tests From b996e0b169fd924c6be8810531190e5ac7112a96 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 18 Sep 2024 10:20:36 +0200 Subject: [PATCH 11/11] [e2e] fixes e2e tests and ads documentation for [plugins/openapi-controllers] --- .../customer-address-postgres-json/pom.xml | 10 ++-- .../customer-address-relational/pom.xml | 10 ++-- .../online-food-delivery-mongo/pom.xml | 10 ++-- .../projects/simple-domain-packaging/pom.xml | 10 ++-- plugins/openapi-controllers/README.md | 58 ++++++++++++++++++- 5 files changed, 76 insertions(+), 22 deletions(-) diff --git a/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml b/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml index eba38074..7e2fd502 100644 --- a/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml +++ b/e2e/src/test/resources/projects/customer-address-postgres-json/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.3.1 io.zenwave360.example @@ -148,7 +148,7 @@ org.openapitools openapi-generator-maven-plugin - 6.6.0 + 7.8.0 @@ -162,9 +162,7 @@ io.zenwave360.example.adapters.web.model DTO true - - ApiUtil.java - + false Double=java.math.BigDecimal @@ -175,7 +173,9 @@ true true true + true false + false diff --git a/e2e/src/test/resources/projects/customer-address-relational/pom.xml b/e2e/src/test/resources/projects/customer-address-relational/pom.xml index 678293e0..5db5954c 100644 --- a/e2e/src/test/resources/projects/customer-address-relational/pom.xml +++ b/e2e/src/test/resources/projects/customer-address-relational/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.3.1 io.zenwave360.example @@ -144,7 +144,7 @@ org.openapitools openapi-generator-maven-plugin - 6.6.0 + 7.8.0 @@ -158,9 +158,7 @@ io.zenwave360.example.adapters.web.model DTO true - - ApiUtil.java - + false Double=java.math.BigDecimal @@ -171,7 +169,9 @@ true true true + true false + false diff --git a/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml b/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml index 4d396abc..b8e50f63 100644 --- a/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml +++ b/e2e/src/test/resources/projects/online-food-delivery-mongo/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.2.1 + 3.3.1 pom @@ -134,7 +134,7 @@ org.openapitools openapi-generator-maven-plugin - 6.6.0 + 7.8.0 openapi-generator-server @@ -149,9 +149,7 @@ ${basePackage}.adapters.web.model DTO true - - ApiUtil.java - + false Double=java.math.BigDecimal @@ -162,7 +160,9 @@ true true true + true false + false diff --git a/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml b/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml index c47b3384..2ccb37cd 100644 --- a/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml +++ b/e2e/src/test/resources/projects/simple-domain-packaging/pom.xml @@ -5,7 +5,7 @@ org.springframework.boot spring-boot-starter-parent - 3.1.4 + 3.3.1 io.zenwave360.example @@ -144,7 +144,7 @@ org.openapitools openapi-generator-maven-plugin - 6.6.0 + 7.8.0 @@ -158,9 +158,7 @@ io.zenwave360.example.customer.dtos DTO true - - ApiUtil.java - + false Double=java.math.BigDecimal @@ -171,7 +169,9 @@ true true true + true false + false diff --git a/plugins/openapi-controllers/README.md b/plugins/openapi-controllers/README.md index 012db7fa..d707d0b7 100644 --- a/plugins/openapi-controllers/README.md +++ b/plugins/openapi-controllers/README.md @@ -16,7 +16,62 @@ jbang zw -p io.zenwave360.sdk.plugins.OpenAPIControllersPlugin targetFolder=. ``` -## Options +## Configuring OpenAPI Generator for Compatibility + +Default options for https://openapi-generator.tech/docs/generators/spring/ have changes over time and different versions. Here is a sample configuration that works with this version of ZenWave360 SDK. + +```xml + + org.openapitools + openapi-generator-maven-plugin + 7.8.0 + + + + generate + + generate-sources + + ${project.basedir}/src/main/resources/public/apis/openapi.yml + true + spring + ${openApiApiPackage} + ${openApiModelPackage} + DTO + true + false + + Double=java.math.BigDecimal + + + true + none + false + true + true + true + true + false + false + + + + + +``` + +Also, make sure you set `required: true` for `requestBody` in your OpenAPI definition for post, put, patch... + +```yaml +requestBody: + required: true # this is important + content: + application/json: + schema: + $ref: "#/components/schemas/Customer" +``` + +## Plugin Options | **Option** | **Description** | **Type** | **Default** | **Values** | |-----------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|------------------|---------------------------------------|-----------------------------------| @@ -42,7 +97,6 @@ jbang zw -p io.zenwave360.sdk.plugins.OpenAPIControllersPlugin | `haltOnFailFormatting` | Halt on formatting errors | boolean | true | | | `continueOnZdlError` | Continue even when ZDL contains fatal errors | boolean | true | | - ## Getting Help ```shell