Skip to content

Commit a95e3e3

Browse files
authored
Fix boolean option in asciidoc generator (#4856)
* fix boolean option in asciidoc generator * minor code format chagne
1 parent e90fa5c commit a95e3e3

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

bin/asciidoc-documentation-petstore.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ fi
2626

2727
# if you've executed sbt assembly previously it will use that instead.
2828
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
29-
ags="$@ generate -t modules/openapi-generator/src/main/resources/asciidoc-documentation --additional-properties=specDir=modules/openapi-generator/src/main/resources/asciidoc-documentation,snippetDir=. -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g asciidoc -o samples/documentation/asciidoc"
29+
ags="generate -t modules/openapi-generator/src/main/resources/asciidoc-documentation --additional-properties=specDir=modules/openapi-generator/src/main/resources/asciidoc-documentation,snippetDir=. -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g asciidoc -o samples/documentation/asciidoc $@"
3030

3131
java ${JAVA_OPTS} -jar ${executable} ${ags}

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ public void execute(final Template.Fragment frag, final Writer out) throws IOExc
141141
protected String groupId = "org.openapitools";
142142
protected String artifactId = "openapi-client";
143143
protected String artifactVersion = "1.0.0";
144+
protected boolean headerAttributes = true;
144145

145146
private IncludeMarkupLambda includeSpecMarkupLambda;
146147
private IncludeMarkupLambda includeSnippetMarkupLambda;
@@ -160,7 +161,7 @@ public CodegenType getTag() {
160161
static String sanitize(final String name) {
161162
String sanitized = name == null ? "" : name.trim();
162163
sanitized = sanitized.replace("//", "/"); // rest paths may or may not end with slashes, leading to redundant
163-
// path separators.
164+
// path separators.
164165
return sanitized.startsWith(File.separator) || sanitized.startsWith("/") ? sanitized.substring(1) : sanitized;
165166
}
166167

@@ -203,13 +204,13 @@ public AsciidocDocumentationCodegen() {
203204

204205
cliOptions.add(new CliOption(SNIPPET_DIR,
205206
"path with includable markup snippets (e.g. test output generated by restdoc, default: .)")
206-
.defaultValue("."));
207+
.defaultValue("."));
207208
cliOptions.add(new CliOption(SPEC_DIR,
208209
"path with includable markup spec files (e.g. handwritten additional docs, default: ..)")
209-
.defaultValue(".."));
210+
.defaultValue(".."));
210211
cliOptions.add(CliOption.newBoolean(HEADER_ATTRIBUTES_FLAG,
211212
"generation of asciidoc header meta data attributes (set to false to suppress, default: true)",
212-
true));
213+
true));
213214

214215
additionalProperties.put("appName", "OpenAPI Sample description");
215216
additionalProperties.put("appDescription", "A sample OpenAPI documentation");
@@ -240,6 +241,14 @@ public String escapeUnsafeCharacters(String input) {
240241
return input; // just return the original string
241242
}
242243

244+
public boolean isHeaderAttributes() {
245+
return headerAttributes;
246+
}
247+
248+
public void setHeaderAttributes(boolean headerAttributes) {
249+
this.headerAttributes = headerAttributes;
250+
}
251+
243252
@Override
244253
public void processOpts() {
245254
super.processOpts();
@@ -264,16 +273,12 @@ public void processOpts() {
264273

265274
this.linkSnippetMarkupLambda = new LinkMarkupLambda(snippetDir);
266275
additionalProperties.put("snippetlink", this.linkSnippetMarkupLambda);
267-
268-
if(this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG) == null ||
269-
! (this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG) instanceof String) ) {
270-
{
271-
this.additionalProperties.put(HEADER_ATTRIBUTES_FLAG, true);
272-
}
276+
277+
278+
if (additionalProperties.containsKey(HEADER_ATTRIBUTES_FLAG)) {
279+
this.setHeaderAttributes(convertPropertyToBooleanAndWriteBack(HEADER_ATTRIBUTES_FLAG));
273280
} else {
274-
String headerAttributesFlagValue = (String) this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG);
275-
LOGGER.debug("asciidoc: header attributes flag..: " + headerAttributesFlagValue);
276-
this.additionalProperties.put(HEADER_ATTRIBUTES_FLAG, "TRUE".equalsIgnoreCase(headerAttributesFlagValue)); // change attribute in map to type boolean.
281+
additionalProperties.put(HEADER_ATTRIBUTES_FLAG, headerAttributes);
277282
}
278283
}
279284

samples/documentation/asciidoc/index.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ [email protected]
66
:toclevels: 3
77
:source-highlighter: highlightjs
88
:keywords: openapi, rest, OpenAPI Petstore
9-
:specDir: modules\openapi-generator\src\main\resources\asciidoc-documentation
9+
:specDir: modules/openapi-generator/src/main/resources/asciidoc-documentation
1010
:snippetDir: .
1111
:generator-template: v1 2019-12-20
1212
:info-url: https://openapi-generator.tech

0 commit comments

Comments
 (0)