Skip to content

Commit 1eda625

Browse files
fix: inner Java classes weren't getting rendered (#110)
* Changed inner class logic, added logging filter. Fixes: #103 * Added check for objects with no properties. * Removed unnecessary logIt filter, and unused code in java-class.
1 parent 44d203f commit 1eda625

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

filters/all.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,16 @@ function functionSpecs([asyncapi, params]) {
304304
}
305305
filter.functionSpecs = functionSpecs;
306306

307+
// This returns the list of methods belonging to an object, just to help debugging.
308+
const getMethods = (obj) => {
309+
const properties = new Set();
310+
let currentObj = obj;
311+
do {
312+
Object.getOwnPropertyNames(currentObj).forEach(item => properties.add(item));
313+
} while ((currentObj = Object.getPrototypeOf(currentObj)));
314+
return [...properties.keys()].filter(item => typeof obj[item] === 'function');
315+
};
316+
307317
function getRealPublisher([info, params, channel]) {
308318
const pub = scsLib.getRealPublisher(info, params, channel);
309319
return pub;
@@ -321,15 +331,13 @@ function groupId([info, params]) {
321331
}
322332
filter.groupId = groupId;
323333

324-
// This returns the list of methods belonging to an object, just to help debugging.
325-
const getMethods = (obj) => {
326-
const properties = new Set();
327-
let currentObj = obj;
328-
do {
329-
Object.getOwnPropertyNames(currentObj).forEach(item => properties.add(item));
330-
} while ((currentObj = Object.getPrototypeOf(currentObj)));
331-
return [...properties.keys()].filter(item => typeof obj[item] === 'function');
332-
};
334+
function isEmpty(obj) {
335+
if (!obj) {
336+
return true;
337+
}
338+
return obj && Object.keys(obj).length === 0 && obj.constructor === Object;
339+
}
340+
filter.isEmpty = isEmpty;
333341

334342
function logFull(obj) {
335343
console.log(obj);

partials/java-class

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
{%- else -%} {# not an array at the top level. #}
2626
{%- set first = true -%}
2727
{#- Constructor with all properties -#}
28+
{%- set hasNoProperties = properties | isEmpty -%}
29+
{%- if not hasNoProperties -%}
2830
{{ indent2 }}public {{ className }} (
2931
{%- for name, prop in properties -%}
3032
{%- set javaName = name | identifierName -%}
@@ -43,6 +45,7 @@
4345
{% endfor -%}
4446
{{ indent2 }}}
4547
{% endif -%}
48+
{% endif -%}
4649

4750
{# Members #}
4851
{% for name, prop in properties -%}
@@ -70,12 +73,9 @@
7073
{{ indent3 }}return this;
7174
{{ indent2 }}}
7275
{# Inner classes #}
73-
{%- if indentLevel == 0 and prop.type() === 'object' %}
76+
{%- if prop.type() === 'object' %}
7477
{{ javaClass(javaName, null, prop.properties(), prop.required(), indentLevel+1, true) }}
7578
{% endif -%}
76-
{%- if indentLevel > 0 and prop.type === 'object' %}
77-
{{ javaClass(javaName, null, prop.properties, prop.required, indentLevel+1, true) }}
78-
{% endif -%}
7979
{%- if isArrayOfObjects %}
8080
{{ javaClass(javaName, null, prop.items().properties(), prop.items().required(), indentLevel+1, true) }}
8181
{% endif -%}

0 commit comments

Comments
 (0)