[johnzon] branch master updated: ensure sub pojogenerators can have the schema they relate to
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new 19764534 ensure sub pojogenerators can have the schema they relate to 19764534 is described below commit 197645342ff8d844765886dd15a0f2b69a3111ff Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 19:19:07 2022 +0200 ensure sub pojogenerators can have the schema they relate to --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 5b02aed8..00989c38 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -425,7 +425,7 @@ public class PojoGenerator { .setClassName(className) .setAddJsonbProperty(configuration.isAddJsonbProperty()) .setAddAllArgsConstructor(configuration.isAddAllArgsConstructor()) -.setOnRef(configuration.getOnRef())) +.setOnRef(configuration.getOnRef()), schema) .visitSchema(schema) .generate()); return className; @@ -435,7 +435,7 @@ public class PojoGenerator { return JsonObject.class.getSimpleName(); } -protected PojoGenerator newSubPojoGenerator(final PojoConfiguration pojoConfiguration) { +protected PojoGenerator newSubPojoGenerator(final PojoConfiguration pojoConfiguration, final JsonObject schema) { return new PojoGenerator(pojoConfiguration); } @@ -467,7 +467,7 @@ public class PojoGenerator { .setClassName(className) .setAddJsonbProperty(configuration.isAddJsonbProperty()) .setAddAllArgsConstructor(configuration.isAddAllArgsConstructor()) -.setOnRef(configuration.getOnRef())) +.setOnRef(configuration.getOnRef()), schema) .visitSchema(schema) .generate()); return className;
[johnzon] branch master updated: Expose PojoGenerator#Attribute attributesfields to subclasses
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new cfdf37a5 Expose PojoGenerator#Attribute attributesfields to subclasses cfdf37a5 is described below commit cfdf37a5d16a42a0e8e254d61af7e5628cad82a2 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 19:17:23 2022 +0200 Expose PojoGenerator#Attribute attributesfields to subclasses --- .../johnzon/jsonschema/generator/PojoGenerator.java| 18 +++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index f63761ba..5b02aed8 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -670,15 +670,27 @@ public class PojoGenerator { } protected static class Attribute { -private final String javaName; -private final String jsonName; -private final String type; +protected final String javaName; +protected final String jsonName; +protected final String type; protected Attribute(final String javaName, final String jsonName, final String type) { this.javaName = javaName; this.jsonName = jsonName; this.type = type; } + +public String getJavaName() { +return javaName; +} + +public String getJsonName() { +return jsonName; +} + +public String getType() { +return type; +} } public static class Ref {
[johnzon] branch master updated: fixing field name in PojoGenerator (starting uppercase)
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new dde6cd7d fixing field name in PojoGenerator (starting uppercase) dde6cd7d is described below commit dde6cd7df6f1bbecb5bf8b3ac8f29121e1e003ac Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 17:47:40 2022 +0200 fixing field name in PojoGenerator (starting uppercase) --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 9fd9f4c4..f63761ba 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -560,7 +560,7 @@ public class PojoGenerator { protected String toCamelCase(final String name) { final StringBuilder out = new StringBuilder(name.length()); -boolean up = true; +boolean up = false; for (final char c : name.toCharArray()) { if (up) { out.append(Character.toUpperCase(c));
[johnzon] branch master updated: try to have more java friendly names in PojoGenerator - bad completion
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new 62dbff7b try to have more java friendly names in PojoGenerator - bad completion 62dbff7b is described below commit 62dbff7b08764c98bf7b1dff8e437322d073a51d Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 17:33:26 2022 +0200 try to have more java friendly names in PojoGenerator - bad completion --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 29316bec..9fd9f4c4 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -563,7 +563,7 @@ public class PojoGenerator { boolean up = true; for (final char c : name.toCharArray()) { if (up) { -out.append(Character.isUpperCase(c)); +out.append(Character.toUpperCase(c)); up = false; } else if (c == '_') { up = true;
[johnzon] branch master updated: try to have more java friendly names in PojoGenerator
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new 544311af try to have more java friendly names in PojoGenerator 544311af is described below commit 544311af11052adaa686368c8cf8b1a57935c024 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 17:31:53 2022 +0200 try to have more java friendly names in PojoGenerator --- .../johnzon/jsonschema/generator/PojoGenerator.java | 20 1 file changed, 20 insertions(+) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 62bb2ccb..29316bec 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -548,12 +548,32 @@ public class PojoGenerator { name += "Value"; } +if (name.contains("_")) { +name = toCamelCase(name); +} + if (!Objects.equals(key, name) && configuration.isAddJsonbProperty()) { imports.add(JsonbProperty.class.getName()); } return name; } +protected String toCamelCase(final String name) { +final StringBuilder out = new StringBuilder(name.length()); +boolean up = true; +for (final char c : name.toCharArray()) { +if (up) { +out.append(Character.isUpperCase(c)); +up = false; +} else if (c == '_') { +up = true; +} else { +out.append(c); +} +} +return out.toString(); +} + protected boolean isReserved(final String name) { return "continue".equals(name) || "break".equals(name) || "default".equals(name) || "do".equals(name) || "while".equals(name) ||
[johnzon] branch master updated: adding enum to reserved words for pojo generator and being stricter on forbidden starting chars for fields
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new af7a399c adding enum to reserved words for pojo generator and being stricter on forbidden starting chars for fields af7a399c is described below commit af7a399ce876d98be44f60d7834c0e47f0d07530 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 16:48:38 2022 +0200 adding enum to reserved words for pojo generator and being stricter on forbidden starting chars for fields --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java| 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 28dbd705..62bb2ccb 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -537,7 +537,7 @@ public class PojoGenerator { if (Character.isDigit(name.charAt(0))) { name = "a" + name; } -while (name.startsWith("_")) { +while (!name.isEmpty() && (!Character.isJavaIdentifierStart(name.charAt(0)) || name.charAt(0) == '_' || name.charAt(0) == '$')) { name = name.substring(1); } if (name.isEmpty()) { @@ -559,6 +559,7 @@ public class PojoGenerator { "do".equals(name) || "while".equals(name) || "for".equals(name) || "if".equals(name) || "else".equals(name) || +"enum".equals(name) || "int".equals(name) || "long".equals(name) || "float".equals(name) ||
[johnzon] branch master updated: [JOHNZON-387] ensure ref has enclosing name - wrong param order
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new f908ae55 [JOHNZON-387] ensure ref has enclosing name - wrong param order f908ae55 is described below commit f908ae55b818f7c231a36e7bf3931773016f7900 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 16:16:13 2022 +0200 [JOHNZON-387] ensure ref has enclosing name - wrong param order --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 7f058ad9..28dbd705 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -443,8 +443,8 @@ public class PojoGenerator { final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { final String name = onRef(new Ref( -configuration.getClassName(), -JsonString.class.cast(ref).getString(), imports, attributes, nested)); +JsonString.class.cast(ref).getString(), configuration.getClassName(), +imports, attributes, nested)); if (name != null) { return name; }
[johnzon] 02/02: [JOHNZON-387] ensure ref has enclosing name
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git commit e70c27e5c0f0b8cb93a2cf3b64ecdb790c625686 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 16:12:41 2022 +0200 [JOHNZON-387] ensure ref has enclosing name --- .../johnzon/jsonschema/generator/PojoGenerator.java | 15 --- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 7625a2fb..7f058ad9 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -209,7 +209,8 @@ public class PojoGenerator { protected String asType(final String javaName, final JsonObject schema, final boolean required) { final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { -final String name = onRef(new Ref(JsonString.class.cast(ref).getString(), imports, attributes, nested)); +final String name = onRef(new Ref( +JsonString.class.cast(ref).getString(), configuration.getClassName(), imports, attributes, nested)); if (name != null) { return name; } @@ -441,7 +442,9 @@ public class PojoGenerator { protected String onItemSchema(final String javaName, final JsonObject schema) { final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { -final String name = onRef(new Ref(JsonString.class.cast(ref).getString(), imports, attributes, nested)); +final String name = onRef(new Ref( +configuration.getClassName(), +JsonString.class.cast(ref).getString(), imports, attributes, nested)); if (name != null) { return name; } @@ -659,18 +662,24 @@ public class PojoGenerator { public static class Ref { private final String ref; +private final String enclosingClass; private final Set imports; private final List attributes; private final Map nested; -private Ref(final String ref, final Set imports, +private Ref(final String ref, final String enclosingClass, final Set imports, final List attributes, final Map nested) { this.ref = ref; +this.enclosingClass = enclosingClass; this.imports = imports; this.attributes = attributes; this.nested = nested; } +public String getEnclosingClass() { +return enclosingClass; +} + public String getRef() { return ref; }
[johnzon] 01/02: adding int64 and int32 format support
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git commit 2dfde39e5421a3719d0a90f76f92d92df6d415ef Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 15:10:48 2022 +0200 adding int64 and int32 format support --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 6 ++ 1 file changed, 6 insertions(+) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 7c3a9a63..7625a2fb 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -258,8 +258,10 @@ public class PojoGenerator { return required ? "double" : "Double"; // openapi types case "int": +case "int32": case "integer": return required ? "int" : "Integer"; +case "int64": case "long": return required ? "long" : "Long"; case "float": @@ -383,9 +385,11 @@ public class PojoGenerator { imports.add(Map.class.getName()); return "Map"; case "int": +case "int32": case "integer": imports.add(Map.class.getName()); return "Map"; +case "int64": case "long": imports.add(Map.class.getName()); return "Map"; @@ -492,8 +496,10 @@ public class PojoGenerator { case "double": return "Double"; case "int": +case "int32": case "integer": return "Integer"; +case "int64": case "long": return "Long"; case "float":
[johnzon] branch master updated (e6316ce9 -> e70c27e5)
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a change to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git from e6316ce9 [JOHNZON-387] better modelisation of ref in pojo generator new 2dfde39e adding int64 and int32 format support new e70c27e5 [JOHNZON-387] ensure ref has enclosing name The 2 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: .../johnzon/jsonschema/generator/PojoGenerator.java | 21 ++--- 1 file changed, 18 insertions(+), 3 deletions(-)
[johnzon] branch master updated: [JOHNZON-387] better modelisation of ref in pojo generator
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new e6316ce9 [JOHNZON-387] better modelisation of ref in pojo generator e6316ce9 is described below commit e6316ce90b60e6c9e5f79b6d6dc390aa718e6512 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 15:01:53 2022 +0200 [JOHNZON-387] better modelisation of ref in pojo generator --- .../jsonschema/generator/PojoGenerator.java| 65 +++--- 1 file changed, 58 insertions(+), 7 deletions(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index d7b161ad..7c3a9a63 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -35,6 +35,7 @@ import java.util.Objects; import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; +import java.util.function.Function; import java.util.stream.IntStream; import java.util.stream.Stream; @@ -190,7 +191,10 @@ public class PojoGenerator { * @param ref the reference to resolve. * @return the reference class name if resolved else null. */ -protected String onRef(final String ref) { +protected String onRef(final Ref ref) { +if (configuration.getOnRef() != null) { +return configuration.getOnRef().apply(ref); +} return null; // todo: check if already in nested for ex } @@ -205,7 +209,7 @@ public class PojoGenerator { protected String asType(final String javaName, final JsonObject schema, final boolean required) { final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { -final String name = onRef(JsonString.class.cast(ref).getString()); +final String name = onRef(new Ref(JsonString.class.cast(ref).getString(), imports, attributes, nested)); if (name != null) { return name; } @@ -411,11 +415,12 @@ public class PojoGenerator { } } else if (hasProperties) { final String className = configuration.getClassName() + Character.toUpperCase(javaName.charAt(0)) + javaName.substring(1); -nested.putAll(new PojoGenerator(new PojoConfiguration() +nested.putAll(newSubPojoGenerator(new PojoConfiguration() .setPackageName(configuration.getPackageName()) .setClassName(className) .setAddJsonbProperty(configuration.isAddJsonbProperty()) - .setAddAllArgsConstructor(configuration.isAddAllArgsConstructor())) + .setAddAllArgsConstructor(configuration.isAddAllArgsConstructor()) +.setOnRef(configuration.getOnRef())) .visitSchema(schema) .generate()); return className; @@ -425,10 +430,14 @@ public class PojoGenerator { return JsonObject.class.getSimpleName(); } +protected PojoGenerator newSubPojoGenerator(final PojoConfiguration pojoConfiguration) { +return new PojoGenerator(pojoConfiguration); +} + protected String onItemSchema(final String javaName, final JsonObject schema) { final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { -final String name = onRef(JsonString.class.cast(ref).getString()); +final String name = onRef(new Ref(JsonString.class.cast(ref).getString(), imports, attributes, nested)); if (name != null) { return name; } @@ -446,11 +455,12 @@ public class PojoGenerator { throw new IllegalStateException("Array of array unsupported"); case "object": final String className = configuration.getClassName() + Character.toUpperCase(javaName.charAt(0)) + javaName.substring(1); -nested.putAll(new PojoGenerator(new PojoConfiguration() +nested.putAll(newSubPojoGenerator(new PojoConfiguration() .setPackageName(configuration.getPackageName()) .setClassName(className) .setAddJsonbProperty(configuration.isAddJsonbProperty()) - .setAddAllArgsConstructor(configuration.isAddAllArgsConstructor())) + .setAddAllArgsConstructor(configuration.isAddAllArgsConstructor()) +.setOnRef(configuration.getOnRef()))
[johnzon] branch master updated: [JOHNZON-387] fixing ref name in jsonschema
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new 58fd2082 [JOHNZON-387] fixing ref name in jsonschema 58fd2082 is described below commit 58fd208253d555e67bb2a867153a5aa9c12ca132 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 14:46:03 2022 +0200 [JOHNZON-387] fixing ref name in jsonschema --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index 1cb7193c..d7b161ad 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -203,7 +203,7 @@ public class PojoGenerator { } protected String asType(final String javaName, final JsonObject schema, final boolean required) { -final JsonValue ref = schema.get("ref"); +final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { final String name = onRef(JsonString.class.cast(ref).getString()); if (name != null) { @@ -426,7 +426,7 @@ public class PojoGenerator { } protected String onItemSchema(final String javaName, final JsonObject schema) { -final JsonValue ref = schema.get("ref"); +final JsonValue ref = schema.get("$ref"); if (ref != null && ref.getValueType() == JsonValue.ValueType.STRING) { final String name = onRef(JsonString.class.cast(ref).getString()); if (name != null) {
[johnzon] branch master updated: adding default to reserved keywords
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new 7295128a adding default to reserved keywords 7295128a is described below commit 7295128a94fd0b4cc829c22353c42e5db0bc19e1 Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 12:12:15 2022 +0200 adding default to reserved keywords --- .../java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java index b410e848..1cb7193c 100644 --- a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -536,7 +536,7 @@ public class PojoGenerator { } protected boolean isReserved(final String name) { -return "continue".equals(name) || "break".equals(name) || +return "continue".equals(name) || "break".equals(name) || "default".equals(name) || "do".equals(name) || "while".equals(name) || "for".equals(name) || "if".equals(name) || "else".equals(name) ||
[johnzon] branch master updated: [JOHNZON-387] basic jsonschema to pojo generation logic
This is an automated email from the ASF dual-hosted git repository. rmannibucau pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/johnzon.git The following commit(s) were added to refs/heads/master by this push: new 5ca42f7f [JOHNZON-387] basic jsonschema to pojo generation logic 5ca42f7f is described below commit 5ca42f7f9013b5aaf31ec66803929be35f98152d Author: Romain Manni-Bucau AuthorDate: Mon Aug 8 11:56:06 2022 +0200 [JOHNZON-387] basic jsonschema to pojo generation logic --- johnzon-jsonschema/pom.xml | 2 +- .../jsonschema/generator/PojoGenerator.java| 633 .../jsonschema/generator/PojoGeneratorTest.java| 624 .../src/test/resources/ConfigMap.json | 193 +++ johnzon-jsonschema/src/test/resources/Node.json| 634 + .../johnzon/maven/plugin/JsonSchemaToPojoMojo.java | 129 + pom.xml| 4 +- 7 files changed, 2216 insertions(+), 3 deletions(-) diff --git a/johnzon-jsonschema/pom.xml b/johnzon-jsonschema/pom.xml index a03ba174..38464977 100644 --- a/johnzon-jsonschema/pom.xml +++ b/johnzon-jsonschema/pom.xml @@ -32,7 +32,7 @@ org.jruby.joni joni - 2.1.16 + 2.1.41 provided true diff --git a/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java new file mode 100644 index ..b410e848 --- /dev/null +++ b/johnzon-jsonschema/src/main/java/org/apache/johnzon/jsonschema/generator/PojoGenerator.java @@ -0,0 +1,633 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.johnzon.jsonschema.generator; + +import javax.json.JsonObject; +import javax.json.JsonString; +import javax.json.JsonValue; +import javax.json.bind.annotation.JsonbProperty; +import java.time.Duration; +import java.time.LocalDate; +import java.time.LocalTime; +import java.time.OffsetDateTime; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; +import java.util.stream.IntStream; +import java.util.stream.Stream; + +import static java.util.Collections.singletonMap; +import static java.util.Comparator.comparing; +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.joining; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; + +// todo: support ref resolution for schema and avoid to generate as much classes as attributes +public class PojoGenerator { +private final PojoConfiguration configuration; + +protected final Set imports = new TreeSet<>(String::compareTo); +protected final List attributes = new ArrayList<>(); +protected final Map nested = new TreeMap<>(String::compareTo); + +public PojoGenerator(final PojoConfiguration configuration) { +this.configuration = configuration; +} + +public PojoGenerator setNested(final Map nested) { +this.nested.putAll(nested); +return this; +} + +public Map generate() { +final String name = configuration.getPackageName() + '.' + configuration.getClassName(); +final String path = name.replace('.', '/') + ".java"; +attributes.sort(comparing(a -> a.javaName)); +if (!attributes.isEmpty()) { +imports.add(Objects.class.getName()); +} +final String content = "" + +"package " + configuration.getPackageName() + ";\n" + +"\n" + +(imports.isEmpty() ? "" : imports.stream() +.sorted() +.map(it -> "import " + it + ";") +.collect(joining("\n", "", "\n\n"))) + +"public class " + configuration.getClassName() + afterClassName() + " {\n" + +(attributes.isEmpty() ? +("" + +