Skip to content

Commit c6f7bae

Browse files
authored
fix: Improved naming enums (#37)
* Removed some verbose debug logging. * Issue 36: Improved enum type naming.
1 parent e9d0198 commit c6f7bae

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

filters/all.js

+19-10
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,20 @@ function fixType([name, javaName, property]) {
234234
type = property.type();
235235
}
236236

237+
//console.log(`fixType: type: ${type} javaNamne ${javaName}` );
238+
//console.log(property);
237239
// If a schema has a property that is a ref to another schema,
238240
// the type is undefined, and the title gives the title of the referenced schema.
239-
let ret;
241+
let typeName;
240242
if (type === undefined) {
241243
if (property.enum()) {
242-
ret = _.upperFirst(javaName);
244+
//console.log("It's an enum.");
245+
typeName = _.upperFirst(javaName);
243246
} else {
244247
// check to see if it's a ref to another schema.
245-
ret = property.ext('x-parser-schema-id');
248+
typeName = property.ext('x-parser-schema-id');
246249

247-
if (!ret) {
250+
if (!typeName) {
248251
throw new Error("Can't determine the type of property " + name);
249252
}
250253
}
@@ -270,16 +273,22 @@ function fixType([name, javaName, property]) {
270273
throw new Error("Array named " + name + ": can't determine the type of the items.");
271274
}
272275
}
273-
ret = _.upperFirst(itemsType) + "[]";
276+
typeName = _.upperFirst(itemsType) + "[]";
274277
} else if (type === 'object') {
275-
ret = _.upperFirst(javaName);
278+
typeName = _.upperFirst(javaName);
276279
} else {
277-
ret = typeMap.get(type);
278-
if (!ret) {
279-
ret = type;
280+
if (property.enum()) {
281+
//console.log("It's an enum.");
282+
typeName = _.upperFirst(javaName);
283+
} else {
284+
285+
typeName = typeMap.get(type);
286+
if (!typeName) {
287+
typeName = type;
288+
}
280289
}
281290
}
282-
return [ret, isArrayOfObjects];
291+
return [typeName, isArrayOfObjects];
283292
}
284293
filter.fixType = fixType;
285294

template/src/main/java/Application.java

-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@
3737
import java.util.function.Supplier;
3838
{%- endif %}
3939

40-
{% if not params.generateMessagingClass %}
41-
// MESSAGING!
42-
{% endif %}
4340
{% set className = [asyncapi.info(), params] | mainClassName %}
4441
@SpringBootApplication
4542
public class {{ className }} {

0 commit comments

Comments
 (0)