Skip to content

Commit 2b42dea

Browse files
Merge branch 'release-2.1'
2 parents 2532ecf + edb3391 commit 2b42dea

15 files changed

+78
-14
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Swagger Confluence
22

3+
[ ![Build Status](https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/badges/develop/build.svg) ](https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/builds)
4+
[ ![Quality Gate](https://cloud.slkdev.net/sonar/api/badges/gate?key=30)](https://cloud.slkdev.net/sonar/overview?id=30)
5+
[ ![Download](https://api.bintray.com/packages/starlightknight/maven/swagger-confluence-cli-all/images/download.svg) ](https://bintray.com/starlightknight/maven/swagger-confluence-cli-all/_latestVersion)
6+
37
## Overview
48

59
The primary goal of this project is to simplify publishing Swagger API documentation to an Atlassian Confluence server. Ideally, this plugin would be activated on the build of a schema jar, which would contain your contract-first Swagger JSON or YAML file
@@ -79,10 +83,12 @@ A special thanks for the following projects, who make this project possible:
7983

8084
* [Swagger2Markup](https://github.com/Swagger2Markup/swagger2markup)
8185
* [AsciiDoctorJ](https://github.com/asciidoctor/asciidoctorj)
86+
* [JSoup](http://jsoup.org/)
8287
* [Confluence REST API](https://developer.atlassian.com/confdev/confluence-rest-api)
8388

8489

8590

91+
8692
Additional shout-outs to the following two projects - whom I tried using manually in
8793
conjunction with the above projects and their respective gradle plugins before starting this project:
8894

build.gradle

+10-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ allprojects {
3737
subprojects {
3838
group 'net.slkdev.swagger.confluence'
3939

40-
version '2.0'
40+
version '2.1'
4141

4242
if (project.hasProperty("release")) {
4343
version += '-RELEASE'
@@ -80,6 +80,15 @@ subprojects {
8080
gradleVersion = 2.12
8181
}
8282

83+
task sourceJar(type: Jar, dependsOn: classes) {
84+
classifier = 'sources'
85+
from sourceSets.main.allSource
86+
}
87+
88+
artifacts {
89+
archives sourceJar
90+
}
91+
8392
test {
8493
jacoco {
8594
enabled true

swagger-confluence-cli/build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,18 @@ publishing {
6666
myPublication(MavenPublication) {
6767
from components.java
6868
artifactId = 'swagger-confluence-cli'
69+
70+
artifact sourceJar {
71+
classifier "sources"
72+
}
6973
}
7074
myShadowPublication(MavenPublication) {
7175
from components.shadow
7276
artifactId = 'swagger-confluence-cli-all'
77+
78+
artifact sourceJar {
79+
classifier "sources"
80+
}
7381
}
7482
}
7583
}

swagger-confluence-cli/src/main/java/net/slkdev/swagger/confluence/cli/SwaggerConfluence.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,14 @@ public static void main(final String[] args){
4242
private static SwaggerToConfluenceService bootSwaggerConfluence(){
4343
final AnnotationConfigApplicationContext annotationConfigApplicationContext =
4444
new AnnotationConfigApplicationContext(SwaggerConfluenceContextConfig.class);
45-
return annotationConfigApplicationContext.getBean(SwaggerToConfluenceService.class);
45+
final SwaggerToConfluenceService swaggerToConfluenceService =
46+
annotationConfigApplicationContext.getBean(SwaggerToConfluenceService.class);
47+
annotationConfigApplicationContext.close();
48+
49+
return swaggerToConfluenceService;
4650
}
4751

48-
public void runCLI(final String args[]){
52+
public void runCLI(final String[] args){
4953
final Options options = buildOptions();
5054
final CommandLine commandLine = parseCommandLineOptions(options, args);
5155

swagger-confluence-core/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ publishing {
5555
publications {
5656
myPublication(MavenPublication) {
5757
from components.java
58+
59+
artifact sourceJar {
60+
classifier "sources"
61+
}
5862
}
5963
}
6064
}

swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/config/SwaggerConfluenceConfig.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import net.slkdev.swagger.confluence.constants.PaginationMode;
1919
import net.slkdev.swagger.confluence.exception.SwaggerConfluenceConfigurationException;
20+
import org.apache.commons.lang3.StringUtils;
2021

2122
public class SwaggerConfluenceConfig {
2223

@@ -110,8 +111,10 @@ public String getPrefix() {
110111
public void setPrefix(final String prefix) {
111112
if (prefix.endsWith(" ")) {
112113
this.prefix = prefix;
113-
} else {
114+
} else if (StringUtils.isNotEmpty(prefix)){
114115
this.prefix = prefix + ' ';
116+
} else {
117+
this.prefix = prefix;
115118
}
116119
}
117120

swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/impl/SwaggerToAsciiDocServiceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public String convertSwaggerToAsciiDoc(final String swaggerSchemaPath) {
6262
return swaggerAsciiDoc;
6363
}
6464

65-
private File getSchemaFile(final String swaggerSchemaPath) throws FileNotFoundException, URISyntaxException {
65+
private static File getSchemaFile(final String swaggerSchemaPath) throws FileNotFoundException, URISyntaxException {
6666
// First we'll try to find the file directly
6767
File swaggerFile = new File(swaggerSchemaPath);
6868

swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/impl/XHtmlToConfluenceServiceImpl.java

+29-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import net.slkdev.swagger.confluence.model.ConfluencePage;
3232
import net.slkdev.swagger.confluence.model.ConfluencePageBuilder;
3333
import net.slkdev.swagger.confluence.service.XHtmlToConfluenceService;
34+
import org.apache.commons.lang3.StringUtils;
3435
import org.jsoup.Jsoup;
3536
import org.jsoup.nodes.Document;
3637
import org.jsoup.nodes.Element;
@@ -322,7 +323,13 @@ private static List<ConfluencePage> handlePagination() {
322323
for (final Element innerTocElement : innerTocElements) {
323324
// If we're in individual page mode, then we collect the inner ToCs
324325
if (individualPages) {
325-
innerTocXHtmlList.add(innerTocElement.html());
326+
final StringBuilder tocHtml = new StringBuilder();
327+
tocHtml.append("<div id=\"toc\" class=\"toc\">");
328+
tocHtml.append("<h4 id=\"toctitle\">Table of Contents</h4>");
329+
tocHtml.append("<div><ul class=\"sectlevel1\">");
330+
tocHtml.append(innerTocElement.html());
331+
tocHtml.append("</ul></div></div>");
332+
innerTocXHtmlList.add(tocHtml.toString());
326333
}
327334
// If we're in category page mode, then we strip out the inner table of contents.
328335
else {
@@ -408,7 +415,12 @@ private static String buildConfluenceTitle(final String originalTitle, final Int
408415
confluenceTitleBuilder.append(". ");
409416
}
410417

411-
confluenceTitleBuilder.append(swaggerConfluenceConfig.getPrefix());
418+
final String prefix = swaggerConfluenceConfig.getPrefix();
419+
420+
if(StringUtils.isNotEmpty(prefix)) {
421+
confluenceTitleBuilder.append(swaggerConfluenceConfig.getPrefix());
422+
}
423+
412424
confluenceTitleBuilder.append(originalTitle);
413425

414426
return confluenceTitleBuilder.toString();
@@ -491,7 +503,7 @@ private static HttpHeaders buildHttpHeaders(final String confluenceAuthenticatio
491503
return headers;
492504
}
493505

494-
private Integer getPageIdFromResponse(final HttpEntity<String> responseEntity) {
506+
private static Integer getPageIdFromResponse(final HttpEntity<String> responseEntity) {
495507
final String responseJson = responseEntity.getBody();
496508
final JSONParser jsonParser = new JSONParser(DEFAULT_PERMISSIVE_MODE);
497509

@@ -691,6 +703,16 @@ private static String reformatXHtml(final String inputXhtml, final Map<String, C
691703
reformatXHtmlHeadings(document, "h3");
692704
reformatXHtmlHeadings(document, "#toctitle");
693705

706+
final SwaggerConfluenceConfig swaggerConfluenceConfig = SWAGGER_CONFLUENCE_CONFIG.get();
707+
708+
if(swaggerConfluenceConfig.getPaginationMode()==PaginationMode.SINGLE_PAGE){
709+
if(swaggerConfluenceConfig.isIncludeTableOfContentsOnSinglePage()) {
710+
reformatXHtmlBreakAfterElements(document, "#toc");
711+
}
712+
713+
reformatXHtmlBreakAfterElements(document, ".sect1");
714+
}
715+
694716
reformatXHtmlSpacing(document.select(".sect2"));
695717
reformatXHtmlSpacing(document.select(".sect3"));
696718

@@ -707,6 +729,10 @@ private static void reformatXHtmlHeadings(final Document document, final String
707729
}
708730
}
709731

732+
private static void reformatXHtmlBreakAfterElements(final Document document, final String elements){
733+
document.select(elements).after("<br />");
734+
}
735+
710736
private static void reformatXHtmlSpacing(final Elements elements){
711737
for(final Element element : elements){
712738
element.before("<br />");

0 commit comments

Comments
 (0)