Skip to content

Commit

Permalink
Make boat-maven-plugin goal doc to run in Java 17. (#938)
Browse files Browse the repository at this point in the history
* GENERATE_ALIAS_AS_MODEL as true to generate information about array types.

* Make it work in Java 17 version and forward.
  • Loading branch information
fredysierra authored Oct 17, 2024
1 parent 46abf1c commit 791dbf4
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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/");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -35,11 +42,34 @@ public TemplateSource sourceAt(String location) {
}
};

var MY_FIELD_VALUE_RESOLVER = new FieldValueResolver() {
@Override
protected Set<FieldWrapper> 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);
Expand All @@ -58,4 +88,5 @@ public TemplateSource sourceAt(String location) {
Template tmpl = handlebars.compile(templateFile);
return tmpl.apply(context);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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/");
Expand All @@ -31,6 +31,7 @@ public BoatMarinaGenerator() {
typeAliases = new HashMap<>();
HandlebarsEngineAdapter templatingEngine = new BoatHandlebarsEngineAdapter();
setTemplatingEngine(templatingEngine);

}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
com.backbase.oss.codegen.marina.BoatHandlebarsEngineAdapter

0 comments on commit 791dbf4

Please sign in to comment.