diff --git a/src/main/java/org/tkit/maven/docs/quarkus/AbstractDocsMojo.java b/src/main/java/org/tkit/maven/docs/quarkus/AbstractDocsMojo.java index 6afcae9..22dbe75 100644 --- a/src/main/java/org/tkit/maven/docs/quarkus/AbstractDocsMojo.java +++ b/src/main/java/org/tkit/maven/docs/quarkus/AbstractDocsMojo.java @@ -30,6 +30,10 @@ protected void writeToFile(String data, String file) throws MojoExecutionExcepti Path out1 = getOutputFile(file); writeTo(out1, data); } + protected void writeToFile(String data, String file, String subDir) throws MojoExecutionException { + Path out1 = getOutputFile(file, subDir); + writeTo(out1, data); + } protected void writeTo(Path out1, String data) throws MojoExecutionException { try { @@ -49,6 +53,10 @@ protected Path getOutputFile(String name) { Path dir = getOutputDir(); return dir.resolve(name); } + protected Path getOutputFile(String name, String subDir) { + Path dir = getOutputDir(subDir); + return dir.resolve(name); + } protected Path getOutputDir() { Path parent = Paths.get(outputDir); @@ -62,4 +70,17 @@ protected Path getOutputDir() { } return parent; } + + protected Path getOutputDir(String subDir) { + Path parent = Paths.get(outputDir + subDir); + File dir = parent.toFile(); + + if (!dir.exists()) { + var r = dir.mkdirs(); + if (r) { + getLog().debug("Create output directory " + outputDir); + } + } + return parent; + } } diff --git a/src/main/java/org/tkit/maven/docs/quarkus/DocumentationMojo.java b/src/main/java/org/tkit/maven/docs/quarkus/DocumentationMojo.java index faf3f98..cfb0eaf 100644 --- a/src/main/java/org/tkit/maven/docs/quarkus/DocumentationMojo.java +++ b/src/main/java/org/tkit/maven/docs/quarkus/DocumentationMojo.java @@ -96,11 +96,18 @@ public class DocumentationMojo extends AbstractDocsMojo { @Parameter(name = "indexIncludeConfig", property = "tkit.docs.index.include.config", defaultValue = "true") protected boolean indexIncludeConfig; + @Parameter(name = "openApiFiles", property = "tkit.docs.generate.openApi.file") + protected String[] openApiFiles; + + @Parameter(name = "openApiBasePath", property = "tkit.docs.generate.openApi.path", defaultValue = "src/main/openapi/") + protected String openApiBasePath; + + @Parameter(name = "openApi", property = "tkit.docs.generate.openApi", defaultValue = "true") + protected boolean openApi; @Override public void execute() throws MojoExecutionException { - if (skipDocs) { getLog().info("1000kit quarkus documentation plugin is disabled"); return; @@ -132,6 +139,16 @@ public void execute() throws MojoExecutionException { if (config.isExtensions()) { renderTemplate(engine, container, "extensions.qute", config.getExtensionsFile()); } + if(config.isOpenApi()) { + for(int i=0; config.getOpenApiFiles().length > i; i++) { + try { + config.setCurrentOpenApiFile(config.getOpenApiFiles()[i]); + renderTemplate(engine, container, "openApi.qute", config.getCurrentOpenApiFile().substring(0, config.getCurrentOpenApiFile().lastIndexOf('.')) + ".adoc", "/openapi"); + } catch (MojoExecutionException e) { + throw new RuntimeException(e); + } + } + } // generated index if (config.isIndex()) { @@ -145,11 +162,13 @@ private Configuration getConfiguration(boolean indexConfig) { config.setIndexDocsFile(indexDocsFile); config.setAttributesFile(attributesFile); config.setExtensionsFile(extensionsFile); + config.setOpenApiFiles(openApiFiles); config.setDocker(docker); config.setExtensions(extensions); config.setProperties(properties); config.setHelm(helm); config.setIndex(index); + config.setOpenApi(openApi); config.setDocs(docs); config.setAttributes(attributes); config.setHelmValuesFile(helmValuesFile); @@ -170,6 +189,11 @@ private void renderTemplate(Engine engine, Object container, String template, St Template tmp = engine.getTemplate(template); writeToFile(tmp.data(TEMPLATE_CONTAINER, container).render(), name); } + private void renderTemplate(Engine engine, Object container, String template, String name, String subDir) throws MojoExecutionException { + Template tmp = engine.getTemplate(template); + writeToFile(tmp.data(TEMPLATE_CONTAINER, container).render(), name, subDir); + } + private File copyConfigFile() { diff --git a/src/main/java/org/tkit/maven/docs/quarkus/docs/Configuration.java b/src/main/java/org/tkit/maven/docs/quarkus/docs/Configuration.java index 9ab267f..d9f7377 100644 --- a/src/main/java/org/tkit/maven/docs/quarkus/docs/Configuration.java +++ b/src/main/java/org/tkit/maven/docs/quarkus/docs/Configuration.java @@ -12,6 +12,7 @@ public class Configuration { private boolean helm; private boolean index; private boolean docs; + private boolean openApi; private boolean attributes; private boolean indexConfig; private boolean indexHeader; @@ -21,9 +22,11 @@ public class Configuration { private String indexHeaderFile; private String helmValuesFile; private String propertiesFile; + private String[] openApiFiles; private List dependenciesIncludeGroups; private List dependenciesExcludeScopes; private String dependenciesMappingFile; + private String currentOpenApiFile; public String getExtensionsFile() { return extensionsFile; @@ -184,4 +187,26 @@ public String getPropertiesFile() { public void setPropertiesFile(String propertiesFile) { this.propertiesFile = propertiesFile; } + + public String[] getOpenApiFiles() { + return openApiFiles; + } + public boolean isOpenApi() { + return openApi; + } + + public void setOpenApi(boolean openApi) { + this.openApi = openApi; + } + + public void setOpenApiFiles(String[] openApiFiles) { + this.openApiFiles = openApiFiles; + } + + public void setCurrentOpenApiFile(String openApiFile) { + this.currentOpenApiFile = openApiFile; + } + public String getCurrentOpenApiFile() { + return currentOpenApiFile; + } } diff --git a/src/main/resources/templates/openApi.qute b/src/main/resources/templates/openApi.qute new file mode 100644 index 0000000..954570e --- /dev/null +++ b/src/main/resources/templates/openApi.qute @@ -0,0 +1,4 @@ +{#if container.config.isOpenApi} +:page-layout: swagger +:page-swagger-url: https://raw.githubusercontent.com/onecx/{container.project.name}/{container.config.currentOpenApiFile} +{/if} \ No newline at end of file