Skip to content

Commit

Permalink
Fix variable names - add _ to names starting with a numeric (#320)
Browse files Browse the repository at this point in the history
* Fix variable names - add _ to names starting with a numeric

* Bump version to 5.3.4

* Fixed templates for enum generation
  • Loading branch information
neinoi committed Feb 8, 2024
1 parent c77ffa6 commit 957b822
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 14 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ As commented above, they both could be used at the same time, setting a double
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
<executions>
<execution>
<id>asyncapi</id>
Expand Down Expand Up @@ -114,7 +114,7 @@ Apply the plugin in the `build.gradle` file and invoke the task.
```groovy
plugins {
id "java"
id "com.sngular.scs-multiapi-gradle-plugin' version '5.3.3"
id "com.sngular.scs-multiapi-gradle-plugin' version '5.3.4"
openapimodel {
Expand Down Expand Up @@ -153,7 +153,7 @@ which the plugin is designed.
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
<executions>
<execution>
<phase>generate-sources</phase>
Expand Down Expand Up @@ -584,7 +584,7 @@ file. Here is an example of a basic configuration:
<plugin>
<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
<executions>
<execution>
<goals>
Expand Down
4 changes: 2 additions & 2 deletions multiapi-engine/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
<packaging>jar</packaging>

<properties>
Expand All @@ -20,7 +20,7 @@
<junit-jupiter-engine.version>5.9.2</junit-jupiter-engine.version>
<swagger-core.version>2.2.9</swagger-core.version>
<maven-surefire-plugin.version>3.0.0</maven-surefire-plugin.version>

<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#assign words = ["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 calculateSafeName propertyName ender>
<#if words?seq_contains(propertyName?uncap_first)>
<#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")>
<#return "_"+propertyName+ender/>
<#else >
<#return propertyName+ender/>
Expand Down Expand Up @@ -182,7 +182,11 @@ public class ${schema.className} {
private ${requireFinal (field)}${field.baseName?cap_first} ${calculateSafeName (field.baseName, hasConstValue(field.constValue))}
public enum ${field.baseName?cap_first} {
<#list field.enumValues as value>
<#if value?matches("[0-9].*")>
${"_"+value?upper_case?replace('[\\W]','_','r')}("${value?no_esc}")<#sep>,
<#else>
${value?upper_case?replace('[\\W]','_','r')}("${value?no_esc}")<#sep>,
</#if>
</#list>;

private ${field.dataType?cap_first} value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<#assign words = ["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 calculateSafeName propertyName ender>
<#if words?seq_contains(propertyName?uncap_first)>
<#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")>
<#return "_"+propertyName+ender/>
<#else >
<#return propertyName+ender/>
Expand Down Expand Up @@ -146,7 +146,11 @@ public class ${schema.className} {

public enum ${field.baseName?cap_first} {
<#list field.enumValues as key, value>
<#if key?matches("[0-9].*")>
${"_"+key}(${value?no_esc})<#sep>,
<#else>
${key}(${value?no_esc})<#sep>,
</#if>
</#list>;

private ${field.dataType?cap_first} value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import com.fasterxml.jackson.annotation.JsonValue;

public enum ${schema.className} {
<#list field.enumValues as key, value>
<#if key?matches("[0-9].*")>
${"_"+key}(${value})<#sep>,
<#else>
${key}(${value})<#sep>,
</#if>
</#list>;

private ${field.dataType.innerType?cap_first} value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<#ftl output_format="plainText">
<#assign words = ["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 calculateSafeName propertyName ender>
<#if words?seq_contains(propertyName?uncap_first)>
<#if words?seq_contains(propertyName?uncap_first) || propertyName?matches("[0-9].*")>
<#return "_"+propertyName+ender/>
<#else >
<#return propertyName+ender/>
Expand Down Expand Up @@ -156,7 +156,11 @@ public class ${schema.className} {
</#if>
public enum ${field.baseName?cap_first} {
<#list field.enumValues as key, value>
<#if key?matches("[0-9].*")>
${"_"+key}(${value})<#sep>,
<#else>
${key}(${value})<#sep>,
</#if>
</#list>;

private ${field.dataType.innerType?cap_first} value;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ public class ${schema.className} {

public enum ${field.baseName?cap_first} {
<#list field.enumValues as key, value>
<#if key?matches("[0-9].*")>
${"_"+key}(${value})<#sep>,
<#else>
${key}(${value})<#sep>,
</#if>
</#list>;

private ${field.dataType.innerType?cap_first} value;
Expand Down
6 changes: 3 additions & 3 deletions scs-multiapi-gradle-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repositories {
}

group = 'com.sngular'
version = '5.3.3'
version = '5.3.4'

def SCSMultiApiPluginGroupId = group
def SCSMultiApiPluginVersion = version
Expand All @@ -30,7 +30,7 @@ dependencies {
shadow localGroovy()
shadow gradleApi()

implementation 'com.sngular:multiapi-engine:5.3.3'
implementation 'com.sngular:multiapi-engine:5.3.4'
testImplementation 'org.assertj:assertj-core:3.24.2'
testImplementation 'com.puppycrawl.tools:checkstyle:10.12.3'
}
Expand Down Expand Up @@ -98,7 +98,7 @@ testing {

integrationTest(JvmTestSuite) {
dependencies {
implementation 'com.sngular:scs-multiapi-gradle-plugin:5.3.3'
implementation 'com.sngular:scs-multiapi-gradle-plugin:5.3.4'
implementation 'org.assertj:assertj-core:3.24.2'
}

Expand Down
4 changes: 2 additions & 2 deletions scs-multiapi-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sngular</groupId>
<artifactId>scs-multiapi-maven-plugin</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
<packaging>maven-plugin</packaging>

<name>AsyncApi - OpenApi Code Generator Maven Plugin</name>
Expand Down Expand Up @@ -243,7 +243,7 @@
<dependency>
<groupId>com.sngular</groupId>
<artifactId>multiapi-engine</artifactId>
<version>5.3.3</version>
<version>5.3.4</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
Expand Down

0 comments on commit 957b822

Please sign in to comment.