From fb36702bb1a02271115bdd990265e24d779822aa Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:49:11 +0100 Subject: [PATCH 1/8] upgrades upstream libs json-schema-ref-parser-jvm and zdl-jvm --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ca5bacf1..86997b8c 100644 --- a/pom.xml +++ b/pom.xml @@ -69,8 +69,8 @@ 0.10.2 4.3.1 2.9.0 - 0.8.6 - 1.2.1 + 0.8.7 + 1.2.2 19.2 1.7 2.38.0 From 26a1669ffa96817a80d8c5d5bb74c65a8e3a5f3c Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:52:12 +0100 Subject: [PATCH 2/8] [backend-application-default] makes `createdBy`, `createdDate` read-only --- .../src/main/java/core/domain/jpa/Entity.java.hbs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs index b4d846a1..5a7e9461 100644 --- a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/Entity.java.hbs @@ -99,10 +99,10 @@ public {{abstractClass entity}} class {{entity.className}} {{addExtends entity}} {{~#if entity.options.auditing}} @CreatedBy - @Column(name = "created_by") + @Column(name = "created_by", updatable = false) protected String createdBy; @CreatedDate - @Column(name = "created_date", columnDefinition = "TIMESTAMP") + @Column(name = "created_date", columnDefinition = "TIMESTAMP", updatable = false) protected LocalDateTime createdDate; @LastModifiedBy @Column(name = "last_modified_by") From 0918a0c7f71e95bfece7e3b067aa6f113b7e820c Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:52:40 +0100 Subject: [PATCH 3/8] [backend-application-default] fixes relationship management in test --- .../jpa/imperative/EntityRepositoryIntegrationTest.java.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 a674c150..5bc27d47 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 @@ -66,7 +66,7 @@ class {{entity.className}}RepositoryIntegrationTest extends BaseRepositoryIntegr {{entity.instanceName}}.set{{capitalize relationship.fieldName}}({{relationship.fieldName}}); {{~else}} {{entity.instanceName}}.set{{capitalize relationship.fieldName}}(new HashSet<>()); - {{entity.instanceName}}.get{{capitalize relationship.fieldName}}().add({{relationship.fieldName}}); + {{entity.instanceName}}.add{{capitalize relationship.fieldName}}({{relationship.fieldName}}); {{~/if}} {{~/if}} {{~/if}} From a894d25b03936033f761a6284de8c616d704ae3e Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:53:42 +0100 Subject: [PATCH 4/8] [backend-application-default] adds support for oracle, mysql and generic DatabaseType --- .../jpa/partials/id/{default.hbs => generic.hbs} | 0 .../java/core/domain/jpa/partials/id/mysql.hbs | 2 ++ .../java/core/domain/jpa/partials/id/oracle.hbs | 2 ++ .../io/zenwave360/sdk/options/DatabaseType.java | 15 +++++++++++++++ 4 files changed, 19 insertions(+) rename plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/{default.hbs => generic.hbs} (100%) create mode 100644 plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/mysql.hbs create mode 100644 plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/oracle.hbs diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/default.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/generic.hbs similarity index 100% rename from plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/default.hbs rename to plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/generic.hbs diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/mysql.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/mysql.hbs new file mode 100644 index 00000000..1c39f939 --- /dev/null +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/mysql.hbs @@ -0,0 +1,2 @@ + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) diff --git a/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/oracle.hbs b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/oracle.hbs new file mode 100644 index 00000000..10f4d16b --- /dev/null +++ b/plugins/backend-application-default/src/main/resources/io/zenwave360/sdk/plugins/BackendApplicationDefaultGenerator/src/main/java/core/domain/jpa/partials/id/oracle.hbs @@ -0,0 +1,2 @@ + @Id + @GeneratedValue(strategy = GenerationType.SEQUENCE) diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/options/DatabaseType.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/options/DatabaseType.java index 7fe46ec2..9375fff8 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/options/DatabaseType.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/options/DatabaseType.java @@ -1,6 +1,21 @@ package io.zenwave360.sdk.options; +import com.fasterxml.jackson.annotation.JsonCreator; + public enum DatabaseType { + generic, postgresql, + mysql, mariadb, + oracle; + + @JsonCreator + public static DatabaseType fromValue(String value) { + for (DatabaseType type : DatabaseType.values()) { + if (type.name().equalsIgnoreCase(value)) { + return type; + } + } + return generic; + } } From 5ca039bad89db1b5836e57a0084b4e744837ceb0 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:55:19 +0100 Subject: [PATCH 5/8] [openapi-spring-webtestclient] changes default `testSuffix = "IntegrationTest"` --- .../io/zenwave360/sdk/plugins/SpringWebTestClientGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/openapi-spring-webtestclient/src/main/java/io/zenwave360/sdk/plugins/SpringWebTestClientGenerator.java b/plugins/openapi-spring-webtestclient/src/main/java/io/zenwave360/sdk/plugins/SpringWebTestClientGenerator.java index 0b992835..a5194d58 100644 --- a/plugins/openapi-spring-webtestclient/src/main/java/io/zenwave360/sdk/plugins/SpringWebTestClientGenerator.java +++ b/plugins/openapi-spring-webtestclient/src/main/java/io/zenwave360/sdk/plugins/SpringWebTestClientGenerator.java @@ -58,7 +58,7 @@ enum RequestPayloadType { public String baseTestClassPackage = "{{testsPackage}}"; @DocumentedOption(description = "Class name suffix for generated test classes") - public String testSuffix = "IT"; + public String testSuffix = "IntegrationTest"; @DocumentedOption(description = "Business Flow Test name") public String businessFlowTestName; From a431cef5024b812b3424debb20b3875b3ef8e188 Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:57:02 +0100 Subject: [PATCH 6/8] [zenwave-sdk-cli] JsonSchemaToJsonFaker now includes `sort: "id:asc"` for sort property --- .../sdk/generators/JsonSchemaToJsonFaker.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/JsonSchemaToJsonFaker.java b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/JsonSchemaToJsonFaker.java index 81aa3aec..c3956273 100644 --- a/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/JsonSchemaToJsonFaker.java +++ b/zenwave-sdk-cli/src/main/java/io/zenwave360/sdk/generators/JsonSchemaToJsonFaker.java @@ -39,6 +39,16 @@ public Object generateExample(Map schema) { return generateObject(null, schema); } + /** + * Returns either a Map or a List of Maps that represents a JSON object. + * + * @param schema + * @return + */ + public Object generateExample(String propertyName, Map schema) { + return generateObject(propertyName, schema); + } + public String generateExampleAsJson(Map schema) { var jsonExample = generateExample(schema); try { @@ -96,6 +106,11 @@ protected String generateString(String propertyName, Map schemaN int index = random.nextInt(enums.size()); return enums.get(index); } + + if ("sort".equals(propertyName)) { + return "id:asc"; + } + Integer min = asInteger(schemaNode.get("min-length")); Integer max = asInteger(schemaNode.get("max-length")); From fc12ecfecf4d9fefdb4b801b94e2601ead111aad Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 12:59:18 +0100 Subject: [PATCH 7/8] [openapi-karate] fixes generated `queryParams` object --- .../java/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator.java | 2 +- .../OpenAPIKarateGenerator/partials/Operation.feature.hbs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/openapi-karate/src/main/java/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator.java b/plugins/openapi-karate/src/main/java/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator.java index 93e16915..5c2bf4c1 100644 --- a/plugins/openapi-karate/src/main/java/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator.java +++ b/plugins/openapi-karate/src/main/java/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator.java @@ -127,7 +127,7 @@ public List generate(Map contextModel) { handlebarsEngine.getHandlebars().registerHelper("paramsExample", (params, options) -> { return ((Collection) params).stream() - .map(p -> p.get("name") + ": " + firstNonNull(p.get("example"), jsonSchemaToJsonFaker.generateExample((Map) p.get("schema")))) + .map(p -> p.get("name") + ": " + firstNonNull(p.get("example"), jsonSchemaToJsonFaker.generateExample((String) p.get("name"), (Map) p.get("schema")))) .collect(Collectors.joining(", ")); }); diff --git a/plugins/openapi-karate/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator/partials/Operation.feature.hbs b/plugins/openapi-karate/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator/partials/Operation.feature.hbs index 8c30ece5..14b24716 100644 --- a/plugins/openapi-karate/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator/partials/Operation.feature.hbs +++ b/plugins/openapi-karate/src/main/resources/io/zenwave360/sdk/plugins/OpenAPIKarateGenerator/partials/Operation.feature.hbs @@ -3,7 +3,7 @@ {{~/if}} Given path {{{karatePath operation}}} {{~#if (queryParams operation)}} -And def queryParams = {{{paramsExample (queryParams operation)}}} +And def queryParams = { {{{paramsExample (queryParams operation)}}} } {{~/if}} {{~#if operation.x--request-dto}} And request From 9b62d519523ba259d2478747cbe0b45b523bc4bf Mon Sep 17 00:00:00 2001 From: Ivan Garcia Sainz-Aja Date: Wed, 6 Nov 2024 13:32:27 +0100 Subject: [PATCH 8/8] [openapi-spring-webtestclient] changes default `testSuffix = "IntegrationTest"` --- .../SpringWebTestClientGeneratorTest.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/openapi-spring-webtestclient/src/test/java/io/zenwave360/sdk/plugins/SpringWebTestClientGeneratorTest.java b/plugins/openapi-spring-webtestclient/src/test/java/io/zenwave360/sdk/plugins/SpringWebTestClientGeneratorTest.java index f078d470..fbfdcc7f 100644 --- a/plugins/openapi-spring-webtestclient/src/test/java/io/zenwave360/sdk/plugins/SpringWebTestClientGeneratorTest.java +++ b/plugins/openapi-spring-webtestclient/src/test/java/io/zenwave360/sdk/plugins/SpringWebTestClientGeneratorTest.java @@ -94,8 +94,8 @@ public void test_output_business_flow(String openapi, String operationIds, Strin @ParameterizedTest(name = "[{index}] {displayName} {0}") @CsvSource({ - "openapi-petstore.yml, addPet, 'PetApiIT'", - "openapi-orders.yml, createCustomer, 'CustomerApiIT'" + "openapi-petstore.yml, addPet, 'PetApiIntegrationTest'", + "openapi-orders.yml, createCustomer, 'CustomerApiIntegrationTest'" }) public void test_output_by_one_service(String openapi, String operationId, String controllers) throws Exception { String targetFolder = "target/test_output_by_one_service_" + openapi.replaceAll("\\.", "_"); @@ -123,8 +123,8 @@ public void test_output_by_one_service(String openapi, String operationId, Strin @ParameterizedTest(name = "[{index}] {displayName} {0}") @CsvSource({ - "openapi-petstore.yml, addPet, 'PetApiIT'", - "openapi-orders.yml, createCustomer, 'CustomerApiIT'" + "openapi-petstore.yml, addPet, 'PetApiIntegrationTest'", + "openapi-orders.yml, createCustomer, 'CustomerApiIntegrationTest'" }) public void test_output_by_one_service_simple_domain_packaging(String openapi, String operationId, String controllers) throws Exception { String targetFolder = "target/test_output_by_one_service_simple_domain_packaging_" + openapi.replaceAll("\\.", "_"); @@ -153,8 +153,8 @@ public void test_output_by_one_service_simple_domain_packaging(String openapi, S @ParameterizedTest(name = "[{index}] {displayName} {0}") @CsvSource({ - "openapi-petstore.yml, 'PetApiIT'", - "openapi-orders.yml, 'CustomerApiIT'" + "openapi-petstore.yml, 'PetApiIntegrationTest'", + "openapi-orders.yml, 'CustomerApiIntegrationTest'" }) public void test_output_by_service(String openapi, String controllers) throws Exception { String targetFolder = "target/test_output_by_service_" + openapi.replaceAll("\\.", "_"); @@ -181,8 +181,8 @@ public void test_output_by_service(String openapi, String controllers) throws Ex @ParameterizedTest(name = "[{index}] {displayName} {0}") @CsvSource({ - "openapi-petstore.yml, 'PetApi/AddPetIT'", - "openapi-orders.yml, 'CustomerOrderApi/CreateCustomerOrderIT'" + "openapi-petstore.yml, 'PetApi/AddPetIntegrationTest'", + "openapi-orders.yml, 'CustomerOrderApi/CreateCustomerOrderIntegrationTest'" }) public void test_output_by_operation(String openapi, String controllers) throws Exception { String targetFolder = "target/test_output_by_operation_" + openapi.replaceAll("\\.", "_");