Skip to content

Commit

Permalink
Generate code for enums in definition blocks (#31)
Browse files Browse the repository at this point in the history
* Allow definition-level enum creation

* Update template generator to ignore enums

* Emit enum event type
  • Loading branch information
Eric-Warehime authored May 24, 2022
1 parent 8e0bf36 commit d8fbe4e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,13 +524,19 @@ public void generateAlgodIndexerObjects (JsonNode root) throws IOException {
null ? root.get("components").get("schemas") : root.get("definitions");
for (Map.Entry<String, JsonNode> cls : getSortedSchema(schemas).entrySet()) {
String desc = null;
if (cls.getValue().get("description") != null) {
desc = cls.getValue().get("description").asText();
}

TypeDef clsType = getType(cls.getValue(), true, cls.getKey(), false, false);
if (clsType.isOfType("enum")) {
publisher.publish(Events.ENUM_DEFINITION, clsType);
}

if (!hasProperties(cls.getValue())) {
// If it has no properties, no class is needed for this type.
continue;
}
if (cls.getValue().get("description") != null) {
desc = cls.getValue().get("description").asText();
}
String className = Tools.getCamelCase(cls.getKey(), true);
if (!filterList.isEmpty() && filterList.contains(className)) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public void onEvent(Events event, TypeDef type) {
case BODY_CONTENT:
javaQueryWriter.addQueryProperty(type, false, false, true);
break;
case ENUM_DEFINITION:
this.storeEnumDefinition(type);
break;
default:
throw new RuntimeException("Unimplemented event for TypeDef! " + event);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/algorand/sdkutils/listeners/Publisher.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class Publisher {
public enum Events {
ALL,

// Store an enum definition--some languages will just treat enums as strings.
ENUM_DEFINITION,

// Define a model object.
NEW_MODEL,
NEW_PROPERTY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,9 @@ public void onEvent(Publisher.Events event, TypeDef type) {
case BODY_CONTENT:
activeQuery.bodyParameters.add(type);
break;
case ENUM_DEFINITION:
// do nothing for enum definitions
break;
default:
logger.info("unhandled event (Events, TypeDef): {}", event);
}
Expand Down

0 comments on commit d8fbe4e

Please sign in to comment.