From 68116f9f8097bdd771b45de30749ed4f8462b249 Mon Sep 17 00:00:00 2001 From: ccantill Date: Fri, 15 Jul 2022 18:03:33 +0200 Subject: [PATCH 1/5] add builder-style setters --- .../java/com/asyncapi/model/$$objectSchema$$.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java index 623391b4b..e7f81d705 100644 --- a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java +++ b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java @@ -105,6 +105,11 @@ public class {{allName}} { public void set{{className}}({{propType}} {{varName}}) { this.{{varName}} = {{varName}}; } + + public {{allName}} {{varName}}({{propType}} {{varName}}) { + this.{{varName}} = {{varName}}; + return this; + } {%- endfor %} } @@ -133,7 +138,7 @@ public class {{allName}} { */{% endif %} @JsonProperty("{{propName}}") {%- if propName | isRequired(schema.required()) %}@NotNull{% endif %} - {%- if prop.minLength() or prop.maxLength() or prop.maxItems() or prop.minItems() %}@Size({% if prop.minLength() or prop.minItems() %}min = {{prop.minLength()}}{{prop.minItems()}}{% endif %}{% if prop.maxLength() or prop.maxItems() %}{% if prop.minLength() or prop.minItems() %},{% endif %}max = {{prop.maxLength()}}{{prop.maxItems()}}{% endif %}){% endif %} + {%- if prop.minLength() or prop.maxLength() or prop.maxItems() or prop.minItems() %}@Size({% if prop.minLength() or prop.minItems() %}min = {{prop.minLength()}}{{prop.minItems()}}{% endif %}{% if prop.maxLength() or prop.maxItems() %}{% if prop.minLength() or prop.minItems() %},{% endif %}max = {{prop.maxLength()}}{{prop.maxItems()}}{% endif %}){% endif %} {%- if prop.pattern() %}@Pattern(regexp="{{prop.pattern() | addBackSlashToPattern}}"){% endif %} {%- if prop.minimum() %}@Min({{prop.minimum()}}){% endif %}{% if prop.exclusiveMinimum() %}@Min({{prop.exclusiveMinimum() + 1}}){% endif %} {%- if prop.maximum() %}@Max({{prop.maximum()}}){% endif %}{% if prop.exclusiveMaximum() %}@Max({{prop.exclusiveMaximum() + 1}}){% endif %} @@ -144,6 +149,11 @@ public class {{allName}} { public void set{{className}}({{propType}} {{varName}}) { this.{{varName}} = {{varName}}; } + + public {{schemaName | camelCase | upperFirst}} {{varName}}({{propType}} {{varName}}) { + this.{{varName}} = {{varName}}; + return this; + } {% endfor %} {% if params.disableEqualsHashCode === 'false' %}@Override public boolean equals(Object o) { @@ -180,4 +190,4 @@ private String toIndentedString(Object o) { } return o.toString().replace("\n", "\n "); } -} \ No newline at end of file +} From 4d9f86d12bae81b61df073f094147ca80b4669be Mon Sep 17 00:00:00 2001 From: ccantill Date: Tue, 19 Jul 2022 14:13:56 +0200 Subject: [PATCH 2/5] fixup java reserved words in properties --- filters/all.js | 66 ++++++++++++++++++- .../com/asyncapi/model/$$objectSchema$$.java | 14 ++-- 2 files changed, 72 insertions(+), 8 deletions(-) diff --git a/filters/all.js b/filters/all.js index 55ef4d59a..e0802e908 100644 --- a/filters/all.js +++ b/filters/all.js @@ -172,8 +172,72 @@ function createEnum(val){ }; filter.createEnum = createEnum; -function addBackSlashToPattern(val) { +function addBackSlashToPattern(val) { let result = val.replace(/\\/g, "\\\\"); return result; } filter.addBackSlashToPattern = addBackSlashToPattern; + +const javaUnsafe = [ + 'abstract', + 'assert', + 'boolean', + 'break', + 'byte', + 'case', + 'catch', + 'char', + 'class', + 'const', + 'continue', + 'default', + 'double', + 'do', + 'else', + 'enum', + 'extends', + 'false', + 'final', + 'finally', + 'float', + 'for', + 'goto', + 'if', + 'implements', + 'import', + 'instanceof', + 'int', + 'interface', + 'long', + 'native', + 'new', + 'null', + 'package', + 'private', + 'protected', + 'public', + 'return', + 'short', + 'static', + 'strictfp', + 'super', + 'switch', + 'synchronized', + 'this', + 'throw', + 'throws', + 'transient', + 'true', + 'try', + 'void', + 'volatile', + 'while' +] + +function javaSafe(val) { + if(javaUnsafe.includes(val)) { + return val + "_"; + } + return val; +} +filter.javaSafe = javaSafe; diff --git a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java index e7f81d705..617c0aaa1 100644 --- a/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java +++ b/template/src/main/java/com/asyncapi/model/$$objectSchema$$.java @@ -18,7 +18,7 @@ public class {{schemaName | camelCase | upperFirst}} { {% for propName, prop in schema.properties() %} {%- set isRequired = propName | isRequired(schema.required()) %} {%- if prop.type() === 'object' %} - private @Valid {{prop.uid() | camelCase | upperFirst}} {{propName | camelCase}}; + private @Valid {{prop.uid() | camelCase | upperFirst}} {{propName | camelCase | javaSafe}}; {%- elif prop.type() === 'array' %} {%- if prop.items().type() === 'object' %} private @Valid List<{{prop.items().uid() | camelCase | upperFirst}}> {{propName | camelCase}}List; @@ -63,7 +63,7 @@ public String toString() { } } - private @Valid {{propName | camelCase | upperFirst}}Enum {{propName | camelCase}}; + private @Valid {{propName | camelCase | upperFirst}}Enum {{propName | camelCase | javaSafe}}; {%- elif prop.anyOf() or prop.oneOf() %} {%- set propType = 'OneOf' %}{%- set hasPrimitive = false %} {%- for obj in prop.anyOf() %} @@ -81,7 +81,7 @@ public interface {{propType}} { } {%- endif %} - private @Valid {{propType}} {{propName | camelCase}}; + private @Valid {{propType}} {{propName | camelCase | javaSafe}}; {%- elif prop.allOf() %} {%- set allName = 'AllOf' %} {%- for obj in prop.allOf() %} @@ -113,18 +113,18 @@ public class {{allName}} { {%- endfor %} } - private @Valid {{allName}} {{propName | camelCase}}; + private @Valid {{allName}} {{propName | camelCase | javaSafe}}; {%- else %} {%- if prop.format() %} - private @Valid {{prop.format() | toJavaType(isRequired)}} {{propName | camelCase}}; + private @Valid {{prop.format() | toJavaType(isRequired)}} {{propName | camelCase | javaSafe}}; {%- else %} - private @Valid {{prop.type() | toJavaType(isRequired)}} {{propName | camelCase}}; + private @Valid {{prop.type() | toJavaType(isRequired)}} {{propName | camelCase | javaSafe}}; {%- endif %} {%- endif %} {% endfor %} {% for propName, prop in schema.properties() %} - {%- set varName = propName | camelCase %} + {%- set varName = propName | camelCase | javaSafe %} {%- set className = propName | camelCase | upperFirst %} {%- set propType = prop | defineType(propName) | safe %} From 861fad02d52236a5ac92cfcde437e042f877fa3d Mon Sep 17 00:00:00 2001 From: Timo Du Four Date: Fri, 9 Feb 2024 09:11:05 +0100 Subject: [PATCH 3/5] Upgrade gradle version UP-8127 --- template/gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/gradle/wrapper/gradle-wrapper.properties b/template/gradle/wrapper/gradle-wrapper.properties index 25913e0ac..1ae89befc 100644 --- a/template/gradle/wrapper/gradle-wrapper.properties +++ b/template/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip From 39d515e2b84cdd02de28e4e31fe038f7af4950fb Mon Sep 17 00:00:00 2001 From: Timo Du Four Date: Fri, 9 Feb 2024 13:36:13 +0100 Subject: [PATCH 4/5] Revert "Upgrade gradle version" This reverts commit 861fad02d52236a5ac92cfcde437e042f877fa3d. --- template/gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/template/gradle/wrapper/gradle-wrapper.properties b/template/gradle/wrapper/gradle-wrapper.properties index 1ae89befc..25913e0ac 100644 --- a/template/gradle/wrapper/gradle-wrapper.properties +++ b/template/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip From 904cf537be4917612e8732efd7b1cca9cacea627 Mon Sep 17 00:00:00 2001 From: Timo Du Four Date: Fri, 9 Feb 2024 15:21:58 +0100 Subject: [PATCH 5/5] Change generator for onlyModels parameter UP-8127 --- hooks/02_removeNotRelevantParts.js | 2 +- package.json | 5 +++++ .../src/main/java/com/asyncapi/infrastructure/Config.java | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hooks/02_removeNotRelevantParts.js b/hooks/02_removeNotRelevantParts.js index 54d0b9e90..4aba32dff 100644 --- a/hooks/02_removeNotRelevantParts.js +++ b/hooks/02_removeNotRelevantParts.js @@ -18,7 +18,7 @@ module.exports = { if (!hasAmqp) { // remove filers from template related only to amqp } - if (!hasMqtt) { + if (!hasMqtt || generator.templateParams.onlyModels) { // remove filers from template related only to mqtt fs.unlinkSync(path.resolve(generator.targetDir, 'src/test/java/com/asyncapi/TestcontainerMqttTest.java')); } diff --git a/package.json b/package.json index 41394e40e..b12ddb401 100644 --- a/package.json +++ b/package.json @@ -113,6 +113,11 @@ "default": false, "required": false }, + "onlyModels": { + "description": "Only generate the models for mqtt, not the config and test. This was added by Unifly because the generated config and test don't support custom converters", + "default": false, + "required": false + }, "maven": { "description": "Generate pom.xml Maven build file instead of Gradle build", "default": false, diff --git a/template/src/main/java/com/asyncapi/infrastructure/Config.java b/template/src/main/java/com/asyncapi/infrastructure/Config.java index 3f530fec8..26d8e438d 100644 --- a/template/src/main/java/com/asyncapi/infrastructure/Config.java +++ b/template/src/main/java/com/asyncapi/infrastructure/Config.java @@ -8,8 +8,10 @@ {{- amqpConfig(asyncapi, params) -}} {%- endif -%} {%- if asyncapi | isProtocol('mqtt') -%} +{%- if params.onlyModels !== true %} {{- mqttConfig(asyncapi, params) -}} {%- endif -%} +{%- endif -%} {%- if (asyncapi | isProtocol('kafka')) or (asyncapi | isProtocol('kafka-secure')) -%} {{- kafkaConfig(asyncapi, params) -}} {%- endif -%} \ No newline at end of file