Skip to content

Commit

Permalink
fix: Improved naming enums (#37)
Browse files Browse the repository at this point in the history
* Removed some verbose debug logging.

* Issue 36: Improved enum type naming.
  • Loading branch information
damaru-inc authored May 19, 2020
1 parent e9d0198 commit c6f7bae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
29 changes: 19 additions & 10 deletions filters/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,20 @@ function fixType([name, javaName, property]) {
type = property.type();
}

//console.log(`fixType: type: ${type} javaNamne ${javaName}` );
//console.log(property);
// If a schema has a property that is a ref to another schema,
// the type is undefined, and the title gives the title of the referenced schema.
let ret;
let typeName;
if (type === undefined) {
if (property.enum()) {
ret = _.upperFirst(javaName);
//console.log("It's an enum.");
typeName = _.upperFirst(javaName);
} else {
// check to see if it's a ref to another schema.
ret = property.ext('x-parser-schema-id');
typeName = property.ext('x-parser-schema-id');

if (!ret) {
if (!typeName) {
throw new Error("Can't determine the type of property " + name);
}
}
Expand All @@ -270,16 +273,22 @@ function fixType([name, javaName, property]) {
throw new Error("Array named " + name + ": can't determine the type of the items.");
}
}
ret = _.upperFirst(itemsType) + "[]";
typeName = _.upperFirst(itemsType) + "[]";
} else if (type === 'object') {
ret = _.upperFirst(javaName);
typeName = _.upperFirst(javaName);
} else {
ret = typeMap.get(type);
if (!ret) {
ret = type;
if (property.enum()) {
//console.log("It's an enum.");
typeName = _.upperFirst(javaName);
} else {

typeName = typeMap.get(type);
if (!typeName) {
typeName = type;
}
}
}
return [ret, isArrayOfObjects];
return [typeName, isArrayOfObjects];
}
filter.fixType = fixType;

Expand Down
3 changes: 0 additions & 3 deletions template/src/main/java/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@
import java.util.function.Supplier;
{%- endif %}

{% if not params.generateMessagingClass %}
// MESSAGING!
{% endif %}
{% set className = [asyncapi.info(), params] | mainClassName %}
@SpringBootApplication
public class {{ className }} {
Expand Down

0 comments on commit c6f7bae

Please sign in to comment.