diff --git a/docs/generators/asciidoc.md b/docs/generators/asciidoc.md index ed61ca4c77a..d69dbacdb76 100644 --- a/docs/generators/asciidoc.md +++ b/docs/generators/asciidoc.md @@ -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| diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java index 23fa88fb05e..0a29173079f 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AsciidocDocumentationCodegen.java @@ -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 diff --git a/modules/openapi-generator/src/main/resources/asciidoc-documentation/index.mustache b/modules/openapi-generator/src/main/resources/asciidoc-documentation/index.mustache index f3783348c04..910b46266aa 100644 --- a/modules/openapi-generator/src/main/resources/asciidoc-documentation/index.mustache +++ b/modules/openapi-generator/src/main/resources/asciidoc-documentation/index.mustache @@ -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 diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java index 746a5bd87af..a685a47e428 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/asciidoc/AsciidocGeneratorTest.java @@ -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 props = new TreeMap(); + 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 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!"); + } } diff --git a/samples/documentation/asciidoc/.openapi-generator/VERSION b/samples/documentation/asciidoc/.openapi-generator/VERSION index e4955748d3e..58592f031f6 100644 --- a/samples/documentation/asciidoc/.openapi-generator/VERSION +++ b/samples/documentation/asciidoc/.openapi-generator/VERSION @@ -1 +1 @@ -4.2.2-SNAPSHOT \ No newline at end of file +4.2.3-SNAPSHOT \ No newline at end of file diff --git a/samples/documentation/asciidoc/index.adoc b/samples/documentation/asciidoc/index.adoc index 295ff335844..d29824f6dc6 100644 --- a/samples/documentation/asciidoc/index.adoc +++ b/samples/documentation/asciidoc/index.adoc @@ -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