Repository: joelittlejohn/jsonschema2pojo
Pull request #1442 (2022-10-17 12:55:18)

correct gradle default values for includeGetters/includeSetters
The default for both values is `true`, according to
 https://github.com/joelittlejohn/jsonschema2pojo/blob/2d55620ac925ff7406f2982a2c37d49a6697cd20/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy#L146-L147

unkish: Hi

I'm not sure whether the intent was to express that:

_default values will be used if not set (following "example" configuration)_
or
_below is list of default configuration values_

If it's former - perhaps the wording of it could/should be changed (native English speakers input would be nice in such case).
If it's the latter, then there are more "invalid" values than the ones proposed to be fixed, listing some of them:

- `source`
- `targetDirectory`
- `includeAdditionalProperties`
- `propertyWordDelimiters`
- `customAnnotator`
- ...

Patch:
diff --git a/jsonschema2pojo-cli/pom.xml b/jsonschema2pojo-cli/pom.xml
index fd3391e2..8e0dd091 100644
--- a/jsonschema2pojo-cli/pom.xml
+++ b/jsonschema2pojo-cli/pom.xml
@@ -22,6 +22,10 @@
                 </includes>
                 <targetPath>${project.build.directory}</targetPath>
             </resource>
+            <resource>
+                <filtering>true</filtering>
+                <directory>${basedir}/src/main/resources</directory>
+            </resource>
         </resources>
         <plugins>
             <plugin>
diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
index d7a2891b..893efa61 100644
--- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
+++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java
@@ -20,11 +20,13 @@ import static org.apache.commons.lang3.StringUtils.*;
 
 import java.io.File;
 import java.io.FileFilter;
+import java.io.IOException;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.stream.Collectors;
 
 import org.jsonschema2pojo.AllFileFilter;
@@ -249,6 +251,9 @@ public class Arguments implements GenerationConfig {
     @Parameter(names = { "--useJakartaValidation" }, description = "Whether to use annotations from jakarta.validation package instead of javax.validation package when adding JSR-303/349 annotations to generated Java types")
     private boolean useJakartaValidation = false;
 
+    @Parameter(names = { "-v", "--version"}, description = "Print version information", help = true)
+    private boolean printVersion = false;
+
     private static final int EXIT_OKAY = 0;
     private static final int EXIT_ERROR = 1;
 
@@ -274,8 +279,13 @@ public class Arguments implements GenerationConfig {
             if (this.showHelp) {
                 jCommander.usage();
                 exit(EXIT_OKAY);
+            } else if (printVersion) {
+                Properties properties = new Properties();
+                properties.load(getClass().getResourceAsStream("version.properties"));
+                jCommander.getConsole().println(jCommander.getProgramName() + " version " + properties.getProperty("version"));
+                exit(EXIT_OKAY);
             }
-        } catch (ParameterException e) {
+        } catch (IOException | ParameterException e) {
             System.err.println(e.getMessage());
             jCommander.usage();
             exit(EXIT_ERROR);
diff --git a/jsonschema2pojo-cli/src/main/resources/org/jsonschema2pojo/cli/version.properties b/jsonschema2pojo-cli/src/main/resources/org/jsonschema2pojo/cli/version.properties
new file mode 100644
index 00000000..e5683df8
--- /dev/null
+++ b/jsonschema2pojo-cli/src/main/resources/org/jsonschema2pojo/cli/version.properties
@@ -0,0 +1,1 @@
+version=${project.version}
\ No newline at end of file
diff --git a/jsonschema2pojo-gradle-plugin/README.md b/jsonschema2pojo-gradle-plugin/README.md
index 0e07a01c..c0d8aa89 100644
--- a/jsonschema2pojo-gradle-plugin/README.md
+++ b/jsonschema2pojo-gradle-plugin/README.md
@@ -218,10 +218,10 @@ jsonSchema2Pojo {
   serializable = false
 
   // Whether to include getters or to omit these accessor methods and create public fields instead.
-  includeGetters = false
+  includeGetters = true
 
   // Whether to include setters or to omit these accessor methods and create public fields instead.
-  includeSetters = false
+  includeSetters = true
 
   // Whether to include dynamic getters, setters, and builders or to omit these methods.
   includeDynamicAccessors = false
diff --git a/pom.xml b/pom.xml
index b6d396ec..ae68bea6 100644
--- a/pom.xml
+++ b/pom.xml
@@ -301,7 +301,7 @@
             <dependency>
                 <groupId>com.beust</groupId>
                 <artifactId>jcommander</artifactId>
-                <version>1.30</version>
+                <version>1.82</version>
             </dependency>
             <dependency>
                 <groupId>com.fasterxml.jackson.core</groupId>


Test patch:
diff --git a/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java b/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java
index cf06c9e9..8e88565b 100644
--- a/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java
+++ b/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java
@@ -21,7 +21,6 @@ import static org.hamcrest.Matchers.*;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
-import java.io.IOException;
 import java.io.PrintStream;
 import java.nio.charset.StandardCharsets;
 
@@ -127,7 +126,7 @@ public class ArgumentsTest {
     }
 
     @Test
-    public void missingArgsCausesHelp() throws IOException {
+    public void missingArgsCausesHelp() {
         ArgsForTest args = (ArgsForTest) new ArgsForTest().parse(new String[] {});
 
         assertThat(args.status, is(1));
@@ -137,13 +136,21 @@ public class ArgumentsTest {
     }
 
     @Test
-    public void requestingHelpCausesHelp() throws IOException {
+    public void requestingHelpCausesHelp() {
         ArgsForTest args = (ArgsForTest) new ArgsForTest().parse(new String[] { "--help" });
 
         assertThat(args.status, is(notNullValue()));
         assertThat(new String(systemOutCapture.toByteArray(), StandardCharsets.UTF_8), is(containsString("Usage: jsonschema2pojo")));
     }
 
+    @Test
+    public void requestingVersionCausesVersion() {
+        ArgsForTest args = (ArgsForTest) new ArgsForTest().parse(new String[] { "--version" });
+
+        assertThat(args.didExit(), is(true));
+        assertThat(new String(systemOutCapture.toByteArray(), StandardCharsets.UTF_8).matches("(?s)jsonschema2pojo version \\d.*"), is(true));
+    }
+
     private File theFile(String path) {
         return new File(path);
     }