Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make boat-maven-plugin goal doc to run in Java 17. #938

Merged
merged 2 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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