Skip to content

Commit

Permalink
Merge pull request #33 from JordenReuter/swagger-generation
Browse files Browse the repository at this point in the history
Swagger generation
  • Loading branch information
andrejpetras authored Jul 10, 2024
2 parents efdb2ef + 896f6d3 commit 4cdc57b
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/main/java/org/tkit/maven/docs/quarkus/AbstractDocsMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand All @@ -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;
}
}
26 changes: 25 additions & 1 deletion src/main/java/org/tkit/maven/docs/quarkus/DocumentationMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
Expand All @@ -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() {
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/tkit/maven/docs/quarkus/docs/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,9 +22,11 @@ public class Configuration {
private String indexHeaderFile;
private String helmValuesFile;
private String propertiesFile;
private String[] openApiFiles;
private List<String> dependenciesIncludeGroups;
private List<String> dependenciesExcludeScopes;
private String dependenciesMappingFile;
private String currentOpenApiFile;

public String getExtensionsFile() {
return extensionsFile;
Expand Down Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/templates/openApi.qute
Original file line number Diff line number Diff line change
@@ -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}

0 comments on commit 4cdc57b

Please sign in to comment.