Skip to content

Commit

Permalink
fix NPE when no CODEGEN_CONFIG in additionalProperties
Browse files Browse the repository at this point in the history
  • Loading branch information
jpfinne committed Jun 1, 2024
1 parent 0a9d892 commit 5107121
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
public static final String SKIP_EXAMPLES_FLAG = "skipExamples";
public static final String USE_METHOD_AND_PATH_FLAG = "useMethodAndPath";
public static final String USE_TABLE_TITLES_FLAG = "useTableTitles";
private String specDir;
private String snippetDir;

/**
* Lambda emitting an asciidoc "include::filename.adoc[]" if file is found in
Expand Down Expand Up @@ -193,11 +195,11 @@ public String getHelp() {
}

public String getSpecDir() {
return additionalProperties.get("specDir").toString();
return specDir;
}

public String getSnippetDir() {
return additionalProperties.get("snippetDir").toString();
return snippetDir;
}

public AsciidocDocumentationCodegen() {
Expand Down Expand Up @@ -325,15 +327,15 @@ public void setUseTableTitles(boolean useTableTitles) {
public void processOpts() {
super.processOpts();

String specDir = String.valueOf(this.additionalProperties.get(SPEC_DIR));
this.specDir = String.valueOf(this.additionalProperties.get(SPEC_DIR));
if (!Files.isDirectory(Paths.get(specDir))) {
LOGGER.warn("base part for include markup lambda not found: {} as {}", specDir, Paths.get(specDir).toAbsolutePath());
}

this.includeSpecMarkupLambda = new IncludeMarkupLambda(SPEC_DIR,specDir);
additionalProperties.put("specinclude", this.includeSpecMarkupLambda);

String snippetDir = String.valueOf(this.additionalProperties.get(SNIPPET_DIR));
this.snippetDir = String.valueOf(this.additionalProperties.get(SNIPPET_DIR));
if (!Files.isDirectory(Paths.get(snippetDir))) {
LOGGER.warn("base part for include markup lambda not found: {} as {}", snippetDir, Paths.get(snippetDir).toAbsolutePath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import com.samskivert.mustache.Mustache;
import com.samskivert.mustache.Template;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.api.TemplatingEngineAdapter;
import org.openapitools.codegen.api.TemplatingExecutor;
import org.slf4j.Logger;
Expand Down Expand Up @@ -64,8 +65,13 @@ public String compileTemplate(TemplatingExecutor executor, Map<String, Object> b
.compile(executor.getFullTemplateContents(templateFile));
StringWriter out = new StringWriter();

Object parent = bundle.get("CONFIG");
tmpl.execute(bundle,parent, out);
Object parent = bundle.get(CodegenConstants.CONFIG);
if (parent == null) {
LOGGER.warn("{} not found. super.processOpts needs to be called in processOpts()", CodegenConstants.CONFIG);
// avoid NPE
parent = new Object();
}
tmpl.execute(bundle, parent, out);
return out.toString();
}

Expand Down

0 comments on commit 5107121

Please sign in to comment.