forked from loafle/openapi-generator-original
* #4848 [asciidoc] add option to not generate metadata (asciidoc attributes) cli / additionalParameters: generateHeaders=true|false * #4848 [asciidoc] new options ascidoc generator * #4848 [asciidoc] add option to not generate metadata (asciidoc attributes) cli / additionalParameters: generateHeaders=true|false
This commit is contained in:
parent
ca4f718748
commit
c0994c479d
@ -20,5 +20,6 @@ sidebar_label: asciidoc
|
||||
|groupId|groupId in generated pom.xml| |null|
|
||||
|artifactId|artifactId in generated pom.xml. This also becomes part of the generated library's filename| |null|
|
||||
|artifactVersion|artifact version in generated pom.xml. This also becomes part of the generated library's filename| |null|
|
||||
|snippetDir|path with includable markup snippets (e.g. test output generated by restdoc, default: .| |.|
|
||||
|specDir|path with includable markup spec files (e.g. handwritten additional docs, default: .| |..|
|
||||
|snippetDir|path with includable markup snippets (e.g. test output generated by restdoc, default: .)| |.|
|
||||
|specDir|path with includable markup spec files (e.g. handwritten additional docs, default: ..)| |..|
|
||||
|headerAttributes|generation of asciidoc header meta data attributes (set to false to suppress, default: true)| |true|
|
||||
|
@ -46,6 +46,7 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
|
||||
|
||||
public static final String SPEC_DIR = "specDir";
|
||||
public static final String SNIPPET_DIR = "snippetDir";
|
||||
public static final String HEADER_ATTRIBUTES_FLAG = "headerAttributes";
|
||||
|
||||
/**
|
||||
* Lambda emitting an asciidoc "include::filename.adoc[]" if file is found in
|
||||
@ -201,11 +202,14 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
|
||||
cliOptions.add(new CliOption(CodegenConstants.ARTIFACT_VERSION, CodegenConstants.ARTIFACT_VERSION_DESC));
|
||||
|
||||
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("."));
|
||||
cliOptions.add(new CliOption(SPEC_DIR,
|
||||
"path with includable markup spec files (e.g. handwritten additional docs, default: .")
|
||||
.defaultValue(".."));
|
||||
"path with includable markup spec files (e.g. handwritten additional docs, default: ..)")
|
||||
.defaultValue(".."));
|
||||
cliOptions.add(CliOption.newBoolean(HEADER_ATTRIBUTES_FLAG,
|
||||
"generation of asciidoc header meta data attributes (set to false to suppress, default: true)",
|
||||
true));
|
||||
|
||||
additionalProperties.put("appName", "OpenAPI Sample description");
|
||||
additionalProperties.put("appDescription", "A sample OpenAPI documentation");
|
||||
@ -260,6 +264,17 @@ public class AsciidocDocumentationCodegen extends DefaultCodegen implements Code
|
||||
|
||||
this.linkSnippetMarkupLambda = new LinkMarkupLambda(snippetDir);
|
||||
additionalProperties.put("snippetlink", this.linkSnippetMarkupLambda);
|
||||
|
||||
if(this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG) == null ||
|
||||
! (this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG) instanceof String) ) {
|
||||
{
|
||||
this.additionalProperties.put(HEADER_ATTRIBUTES_FLAG, true);
|
||||
}
|
||||
} else {
|
||||
String headerAttributesFlagValue = (String) this.additionalProperties.get(HEADER_ATTRIBUTES_FLAG);
|
||||
LOGGER.debug("asciidoc: header attributes flag..: " + headerAttributesFlagValue);
|
||||
this.additionalProperties.put(HEADER_ATTRIBUTES_FLAG, "TRUE".equalsIgnoreCase(headerAttributesFlagValue)); // change attribute in map to type boolean.
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,5 @@
|
||||
= {{{appName}}}
|
||||
= {{{appName}}}
|
||||
{{#headerAttributes}}
|
||||
{{infoEmail}}
|
||||
{{#version}}{{{version}}}{{/version}}
|
||||
:toc: left
|
||||
@ -8,9 +9,10 @@
|
||||
:keywords: openapi, rest, {{appName}}
|
||||
:specDir: {{specDir}}
|
||||
:snippetDir: {{snippetDir}}
|
||||
:generator-template: v1 2019-11-19
|
||||
:generator-template: v1 2019-12-20
|
||||
:info-url: {{infoUrl}}
|
||||
:app-name: {{appName}}
|
||||
{{/headerAttributes}}
|
||||
|
||||
[abstract]
|
||||
.Abstract
|
||||
|
@ -22,7 +22,7 @@ import org.testng.annotations.Test;
|
||||
|
||||
import io.swagger.v3.oas.models.OpenAPI;
|
||||
|
||||
/** check against ping.yaml spec. */
|
||||
/** unit test asciidoc markup generation against ping.yaml openapi spec. */
|
||||
public class AsciidocGeneratorTest {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(AsciidocGeneratorTest.class);
|
||||
@ -113,5 +113,41 @@ public class AsciidocGeneratorTest {
|
||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHeaderAttributesFlagRemovesAttributesFromMarkupHeaderSection() throws Exception {
|
||||
File output = Files.createTempDirectory("test").toFile();
|
||||
|
||||
LOGGER.info("test: generating sample markup " + output.getAbsolutePath());
|
||||
|
||||
Map<String, Object> props = new TreeMap<String, Object>();
|
||||
props.put("specDir", "spec");
|
||||
|
||||
final CodegenConfigurator configurator = new CodegenConfigurator()
|
||||
.setGeneratorName("asciidoc")
|
||||
.setInputSpec("src/test/resources/3_0/ping.yaml")
|
||||
.setOutputDir(output.getAbsolutePath())
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.HEADER_ATTRIBUTES_FLAG, "false") // option avoids generation of attributes
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SPEC_DIR, "SPEC-DIR")
|
||||
.addAdditionalProperty(AsciidocDocumentationCodegen.SNIPPET_DIR, "MY/SNIPPET/DIR");
|
||||
|
||||
DefaultGenerator generator = new DefaultGenerator();
|
||||
boolean markupFileGenerated = false;
|
||||
List<File> files = generator.opts(configurator.toClientOptInput()).generate();
|
||||
for (File file : files) {
|
||||
if (file.getName().equals("index.adoc")) {
|
||||
markupFileGenerated = true;
|
||||
String markupContent = FileUtils.readFileToString(file, StandardCharsets.UTF_8);
|
||||
Assert.assertFalse(markupContent.contains(":specDir: SPEC-DIR"),
|
||||
"not expected :specDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertFalse(markupContent.contains(":snippetDir: MY/SNIPPET/DIR"),
|
||||
"not expected :snippetDir: in: " + markupContent.substring(0, 250));
|
||||
Assert.assertFalse(markupContent.contains(":toc:"),
|
||||
"not expected :toc: in: " + markupContent.substring(0, 250)); // typical attributes not found in markup.
|
||||
}
|
||||
}
|
||||
Assert.assertTrue(markupFileGenerated, "index.adoc is not generated!");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
4.2.2-SNAPSHOT
|
||||
4.2.3-SNAPSHOT
|
@ -1,4 +1,4 @@
|
||||
= OpenAPI Petstore
|
||||
= OpenAPI Petstore
|
||||
team@openapitools.org
|
||||
1.0.0
|
||||
:toc: left
|
||||
@ -8,7 +8,7 @@ team@openapitools.org
|
||||
:keywords: openapi, rest, OpenAPI Petstore
|
||||
:specDir: modules\openapi-generator\src\main\resources\asciidoc-documentation
|
||||
:snippetDir: .
|
||||
:generator-template: v1 2019-11-19
|
||||
:generator-template: v1 2019-12-20
|
||||
:info-url: https://openapi-generator.tech
|
||||
:app-name: OpenAPI Petstore
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user