diff --git a/boat-scaffold/src/main/java/com/backbase/oss/codegen/doc/BoatDocsGenerator.java b/boat-scaffold/src/main/java/com/backbase/oss/codegen/doc/BoatDocsGenerator.java index 0ccedda0b..e94a6e251 100644 --- a/boat-scaffold/src/main/java/com/backbase/oss/codegen/doc/BoatDocsGenerator.java +++ b/boat-scaffold/src/main/java/com/backbase/oss/codegen/doc/BoatDocsGenerator.java @@ -20,7 +20,7 @@ public BoatDocsGenerator() { super(); embeddedTemplateDir = templateDir = NAME; cliOptions.add(new CliOption(CodegenConstants.GENERATE_ALIAS_AS_MODEL, CodegenConstants.GENERATE_ALIAS_AS_MODEL)); - additionalProperties.put(CodegenConstants.GENERATE_ALIAS_AS_MODEL, false); + additionalProperties.put(CodegenConstants.GENERATE_ALIAS_AS_MODEL, true); additionalProperties.put("appName", "OpenAPI Sample"); additionalProperties.put("appDescription", "A sample OpenAPI server"); additionalProperties.put("infoUrl", "https://backbase.github.io/backbase-openapi-tools/"); diff --git a/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatHandlebarsEngineAdapter.java b/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatHandlebarsEngineAdapter.java index 16e7b38ac..72b63d369 100644 --- a/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatHandlebarsEngineAdapter.java +++ b/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatHandlebarsEngineAdapter.java @@ -8,16 +8,23 @@ import com.github.jknack.handlebars.Helper; import com.github.jknack.handlebars.Jackson2Helper; import com.github.jknack.handlebars.Template; +import com.github.jknack.handlebars.context.FieldValueResolver; +import com.github.jknack.handlebars.context.FieldValueResolver.FieldWrapper; import com.github.jknack.handlebars.context.JavaBeanValueResolver; import com.github.jknack.handlebars.context.MapValueResolver; +import com.github.jknack.handlebars.context.MethodValueResolver; import com.github.jknack.handlebars.helper.ConditionalHelpers; import com.github.jknack.handlebars.helper.StringHelpers; import com.github.jknack.handlebars.io.AbstractTemplateLoader; import com.github.jknack.handlebars.io.TemplateLoader; import com.github.jknack.handlebars.io.TemplateSource; import java.io.IOException; +import java.lang.reflect.AccessibleObject; +import java.lang.reflect.Modifier; import java.util.Locale; import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.openapitools.codegen.api.TemplatingExecutor; import org.openapitools.codegen.templating.HandlebarsEngineAdapter; @@ -35,11 +42,34 @@ public TemplateSource sourceAt(String location) { } }; + var MY_FIELD_VALUE_RESOLVER = new FieldValueResolver() { + @Override + protected Set members( + Class clazz) { + var members = super.members(clazz); + return members.stream() + .filter(fw -> isValidField(fw)) + .collect(Collectors.toSet()); + } + + boolean isValidField( + FieldWrapper fw) { + if (fw instanceof AccessibleObject) { + if (isUseSetAccessible(fw)) { + return true; + } + return false; + } + return true; + } + }; Context context = Context .newBuilder(bundle) .resolver( MapValueResolver.INSTANCE, - JavaBeanValueResolver.INSTANCE) + JavaBeanValueResolver.INSTANCE, + MethodValueResolver.INSTANCE, + MY_FIELD_VALUE_RESOLVER) .build(); Handlebars handlebars = new Handlebars(loader); @@ -58,4 +88,5 @@ public TemplateSource sourceAt(String location) { Template tmpl = handlebars.compile(templateFile); return tmpl.apply(context); } + } diff --git a/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatMarinaGenerator.java b/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatMarinaGenerator.java index 7f3708e5e..8681a4f84 100644 --- a/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatMarinaGenerator.java +++ b/boat-scaffold/src/main/java/com/backbase/oss/codegen/marina/BoatMarinaGenerator.java @@ -21,7 +21,7 @@ public BoatMarinaGenerator() { embeddedTemplateDir = templateDir = NAME; cliOptions.add(new CliOption(CodegenConstants.GENERATE_ALIAS_AS_MODEL, CodegenConstants.GENERATE_ALIAS_AS_MODEL)); - additionalProperties.put(CodegenConstants.GENERATE_ALIAS_AS_MODEL, false); + additionalProperties.put(CodegenConstants.GENERATE_ALIAS_AS_MODEL, true); additionalProperties.put("appName", "BOAT Marina Documentation"); additionalProperties.put("appDescription", "For a collection of doc(k)s"); additionalProperties.put("infoUrl", "https://backbase.github.io/backbase-openapi-tools/"); @@ -31,6 +31,7 @@ public BoatMarinaGenerator() { typeAliases = new HashMap<>(); HandlebarsEngineAdapter templatingEngine = new BoatHandlebarsEngineAdapter(); setTemplatingEngine(templatingEngine); + } diff --git a/boat-scaffold/src/main/resources/META-INF/services/org.openapitools.codegen.api.TemplatingEngineAdapter b/boat-scaffold/src/main/resources/META-INF/services/org.openapitools.codegen.api.TemplatingEngineAdapter new file mode 100644 index 000000000..4eb68a05f --- /dev/null +++ b/boat-scaffold/src/main/resources/META-INF/services/org.openapitools.codegen.api.TemplatingEngineAdapter @@ -0,0 +1 @@ +com.backbase.oss.codegen.marina.BoatHandlebarsEngineAdapter \ No newline at end of file