Skip to content

Commit

Permalink
generating enums only on demand (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
musketyr authored Jul 29, 2021
1 parent d019def commit 7641ec4
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ abstract class MicronautDataGenerator {
}

@SuppressWarnings('NestedForLoop')
int generate(File root, String packageSuffix = '.model') {
int generate(File root, String packageSuffix = '.model', boolean generateEnums = false) {
Collection<PersistentEntity> entities = datastore.mappingContext.persistentEntities
Collection<Class> entityClasses = entities*.javaClass
entities.each { PersistentEntity entity ->
Expand All @@ -78,17 +78,19 @@ abstract class MicronautDataGenerator {
repositoryFile.text = generateRepository(entity, packageSuffix)
}

List<Class> requiredEnums = []
for (PersistentEntity entity in datastore.mappingContext.persistentEntities) {
for (PersistentProperty property in entity.persistentProperties) {
if (property.type.enum) {
requiredEnums.add(property.type)
if (generateEnums) {
List<Class> requiredEnums = []
for (PersistentEntity entity in datastore.mappingContext.persistentEntities) {
for (PersistentProperty property in entity.persistentProperties) {
if (property.type.enum) {
requiredEnums.add(property.type)
}
}
}
}

requiredEnums.each { Class enumType ->
copyEnum(root, enumType)
requiredEnums.each { Class enumType ->
copyEnum(root, enumType)
}
}

return entities.size()
Expand Down

0 comments on commit 7641ec4

Please sign in to comment.