Fix boolean option in asciidoc generator (#4856)

* fix boolean option in asciidoc generator

* minor code format chagne
This commit is contained in:
William Cheng 2019-12-22 18:18:16 +08:00 committed by GitHub
parent e90fa5c4df
commit a95e3e3684
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 15 deletions

View File

@ -26,6 +26,6 @@ fi
# if you've executed sbt assembly previously it will use that instead. # if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"
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" 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 $@"
java ${JAVA_OPTS} -jar ${executable} ${ags} java ${JAVA_OPTS} -jar ${executable} ${ags}

View File

@ -141,6 +141,7 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
protected String groupId = "org.openapitools"; protected String groupId = "org.openapitools";
protected String artifactId = "openapi-client"; protected String artifactId = "openapi-client";
protected String artifactVersion = "1.0.0"; protected String artifactVersion = "1.0.0";
protected boolean headerAttributes = true;
private IncludeMarkupLambda includeSpecMarkupLambda; private IncludeMarkupLambda includeSpecMarkupLambda;
private IncludeMarkupLambda includeSnippetMarkupLambda; private IncludeMarkupLambda includeSnippetMarkupLambda;
@ -160,7 +161,7 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
static String sanitize(final String name) { static String sanitize(final String name) {
String sanitized = name == null ? "" : name.trim(); String sanitized = name == null ? "" : name.trim();
sanitized = sanitized.replace("//", "/"); // rest paths may or may not end with slashes, leading to redundant sanitized = sanitized.replace("//", "/"); // rest paths may or may not end with slashes, leading to redundant
// path separators. // path separators.
return sanitized.startsWith(File.separator) || sanitized.startsWith("/") ? sanitized.substring(1) : sanitized; return sanitized.startsWith(File.separator) || sanitized.startsWith("/") ? sanitized.substring(1) : sanitized;
} }
@ -203,13 +204,13 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
cliOptions.add(new CliOption(SNIPPET_DIR, cliOptions.add(new CliOption(SNIPPET_DIR,
"path with includable markup snippets (e.g. test output generated by restdoc, default: .)") "path with includable markup snippets (e.g. test output generated by restdoc, default: .)")
.defaultValue(".")); .defaultValue("."));
cliOptions.add(new CliOption(SPEC_DIR, cliOptions.add(new CliOption(SPEC_DIR,
"path with includable markup spec files (e.g. handwritten additional docs, default: ..)") "path with includable markup spec files (e.g. handwritten additional docs, default: ..)")
.defaultValue("..")); .defaultValue(".."));
cliOptions.add(CliOption.newBoolean(HEADER_ATTRIBUTES_FLAG, cliOptions.add(CliOption.newBoolean(HEADER_ATTRIBUTES_FLAG,
"generation of asciidoc header meta data attributes (set to false to suppress, default: true)", "generation of asciidoc header meta data attributes (set to false to suppress, default: true)",
true)); true));
additionalProperties.put("appName", "OpenAPI Sample description"); additionalProperties.put("appName", "OpenAPI Sample description");
additionalProperties.put("appDescription", "A sample OpenAPI documentation"); additionalProperties.put("appDescription", "A sample OpenAPI documentation");
@ -240,6 +241,14 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
return input; // just return the original string return input; // just return the original string
} }
public boolean isHeaderAttributes() {
return headerAttributes;
}
public void setHeaderAttributes(boolean headerAttributes) {
this.headerAttributes = headerAttributes;
}
@Override @Override
public void processOpts() { public void processOpts() {
super.processOpts(); super.processOpts();
@ -264,16 +273,12 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
this.linkSnippetMarkupLambda = new LinkMarkupLambda(snippetDir); this.linkSnippetMarkupLambda = new LinkMarkupLambda(snippetDir);
additionalProperties.put("snippetlink", this.linkSnippetMarkupLambda); additionalProperties.put("snippetlink", this.linkSnippetMarkupLambda);
if(this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG) == null ||
! (this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG) instanceof String) ) { if (additionalProperties.containsKey(HEADER_ATTRIBUTES_FLAG)) {
{ this.setHeaderAttributes(convertPropertyToBooleanAndWriteBack(HEADER_ATTRIBUTES_FLAG));
this.additionalProperties.put(HEADER_ATTRIBUTES_FLAG, true);
}
} else { } else {
String headerAttributesFlagValue = (String) this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG); additionalProperties.put(HEADER_ATTRIBUTES_FLAG, headerAttributes);
LOGGER.debug("asciidoc: header attributes flag..: " + headerAttributesFlagValue);
this.additionalProperties.put(HEADER_ATTRIBUTES_FLAG, "TRUE".equalsIgnoreCase(headerAttributesFlagValue)); // change attribute in map to type boolean.
} }
} }

View File

@ -6,7 +6,7 @@ team@openapitools.org
:toclevels: 3 :toclevels: 3
:source-highlighter: highlightjs :source-highlighter: highlightjs
:keywords: openapi, rest, OpenAPI Petstore :keywords: openapi, rest, OpenAPI Petstore
:specDir: modules\openapi-generator\src\main\resources\asciidoc-documentation :specDir: modules/openapi-generator/src/main/resources/asciidoc-documentation
:snippetDir: . :snippetDir: .
:generator-template: v1 2019-12-20 :generator-template: v1 2019-12-20
:info-url: https://openapi-generator.tech :info-url: https://openapi-generator.tech