├── .gitignore ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── swagger-confluence-core ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ ├── main │ │ ├── resources │ │ │ └── log4j2.xml │ │ └── java │ │ │ └── net │ │ │ └── slkdev │ │ │ └── swagger │ │ │ └── confluence │ │ │ ├── constants │ │ │ ├── PageType.java │ │ │ └── PaginationMode.java │ │ │ ├── service │ │ │ ├── AsciiDocToXHtmlService.java │ │ │ ├── SwaggerToAsciiDocService.java │ │ │ ├── SwaggerToConfluenceService.java │ │ │ ├── XHtmlToConfluenceService.java │ │ │ └── impl │ │ │ │ ├── AsciiDocToXHtmlServiceImpl.java │ │ │ │ ├── SwaggerToConfluenceServiceImpl.java │ │ │ │ └── SwaggerToAsciiDocServiceImpl.java │ │ │ ├── exception │ │ │ ├── SwaggerConfluenceInternalSystemException.java │ │ │ ├── ConfluenceAPIException.java │ │ │ └── SwaggerConfluenceConfigurationException.java │ │ │ ├── model │ │ │ ├── ConfluenceLink.java │ │ │ ├── ConfluenceLinkBuilder.java │ │ │ ├── ConfluencePage.java │ │ │ └── ConfluencePageBuilder.java │ │ │ ├── context │ │ │ └── SwaggerConfluenceContextConfig.java │ │ │ └── config │ │ │ └── SwaggerConfluenceConfig.java │ └── test │ │ ├── java │ │ └── net │ │ │ └── slkdev │ │ │ └── swagger │ │ │ └── confluence │ │ │ ├── context │ │ │ └── SwaggerConfluenceContextConfigITCase.java │ │ │ ├── exception │ │ │ ├── SwaggerConfluenceInternalSystemExceptionTest.java │ │ │ ├── ConfluenceAPIExceptionTest.java │ │ │ └── SwaggerConfluenceConfigurationExceptionTest.java │ │ │ ├── service │ │ │ └── impl │ │ │ │ ├── AsciiDocToXHtmlServiceImplTest.java │ │ │ │ ├── SwaggerToAsciiDocServiceImplTest.java │ │ │ │ ├── SwaggerToConfluenceImplTest.java │ │ │ │ └── XHtmlToConfluenceServiceImplTest.java │ │ │ ├── model │ │ │ ├── ConfluenceLinkBuilderTest.java │ │ │ └── ConfluencePageBuilderTest.java │ │ │ └── config │ │ │ └── SwaggerConfluenceConfigTest.java │ │ └── resources │ │ ├── swagger-confluence-create-json-body-user-example.json │ │ ├── swagger-confluence-update-json-body-user-example.json │ │ ├── swagger-confluence-create-json-body-definitions-example.json │ │ ├── swagger-confluence-update-json-body-definitions-example.json │ │ ├── swagger-petstore-example.yaml │ │ └── swagger-petstore-asciidoc-example.adoc ├── build.gradle ├── gradlew.bat └── gradlew ├── swagger-confluence-gradle-plugin ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── src │ └── main │ │ ├── resources │ │ └── META-INF │ │ │ └── gradle-plugins │ │ │ └── net.slkdev.swagger-confluence.properties │ │ └── java │ │ └── net │ │ └── slkdev │ │ └── swagger │ │ └── confluence │ │ └── gradle │ │ └── plugin │ │ ├── SwaggerConfluenceGradlePlugin.java │ │ └── SwaggerConfluenceGradleTask.java ├── gradlew.bat ├── build.gradle └── gradlew ├── gradle.properties ├── .gitlab-ci.yml ├── swagger-confluence-cli ├── build.gradle └── src │ ├── test │ └── java │ │ └── net │ │ └── slkdev │ │ └── swagger │ │ └── confluence │ │ └── cli │ │ └── SwaggerConfluenceTest.java │ └── main │ └── java │ └── net │ └── slkdev │ └── swagger │ └── confluence │ └── cli │ └── SwaggerConfluence.java ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .gradle 2 | .idea 3 | .iml 4 | .project 5 | .classpath 6 | bin 7 | build 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starlightknight/swagger-confluence/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'swagger-confluence' 2 | include 'swagger-confluence-core', 'swagger-confluence-gradle-plugin', 'swagger-confluence-cli' 3 | 4 | -------------------------------------------------------------------------------- /swagger-confluence-core/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starlightknight/swagger-confluence/HEAD/swagger-confluence-core/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/starlightknight/swagger-confluence/HEAD/swagger-confluence-gradle-plugin/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/src/main/resources/META-INF/gradle-plugins/net.slkdev.swagger-confluence.properties: -------------------------------------------------------------------------------- 1 | implementation-class=net.slkdev.swagger.confluence.gradle.plugin.SwaggerConfluenceGradlePlugin 2 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | ASCIIDOCTORJ_VERSION=1.5.4 2 | COMMONS_CLI=1.3.1 3 | JSONPATH_VERSION=2.2.0 4 | JSOUP_VERSION=1.8.3 5 | JUNIT_VERSION=4.12 6 | LOG4J2_VERSION=2.5 7 | MOCKITO_VERSION=1.10.19 8 | SLF4J_VERSION=1.7.19 9 | SPRING_VERSION=4.2.5.RELEASE 10 | SWAGGER2MARKUP_VERSION=1.0.0 -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 26 10:18:11 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-all.zip 7 | -------------------------------------------------------------------------------- /swagger-confluence-core/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 26 09:50:27 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip 7 | -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Sat Mar 26 09:50:27 EDT 2016 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.12-bin.zip 7 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | %5p 5 | %d{yyyy-MM-dd HH:mm:ss.SSS} ${LOG_LEVEL_PATTERN} - [%t] %-40.40c{1.} : %m%n 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/constants/PageType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.constants; 17 | 18 | public enum PageType { 19 | ROOT, CATEGORY, INDIVIDUAL 20 | } 21 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/constants/PaginationMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.constants; 17 | 18 | public enum PaginationMode { 19 | SINGLE_PAGE, CATEGORY_PAGES, INDIVIDUAL_PAGES 20 | } 21 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/AsciiDocToXHtmlService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service; 17 | 18 | public interface AsciiDocToXHtmlService { 19 | String convertAsciiDocToXHtml(String asciiDoc); 20 | } 21 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/SwaggerToAsciiDocService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service; 17 | 18 | public interface SwaggerToAsciiDocService { 19 | String convertSwaggerToAsciiDoc(String swaggerSchemaPath); 20 | } 21 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/SwaggerToConfluenceService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | 20 | public interface SwaggerToConfluenceService { 21 | void convertSwaggerToConfluence(SwaggerConfluenceConfig swaggerConfluenceConfig); 22 | } 23 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/XHtmlToConfluenceService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | 20 | public interface XHtmlToConfluenceService { 21 | void postXHtmlToConfluence(final SwaggerConfluenceConfig swaggerConfluenceConfig, final String xhtml); 22 | } 23 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/exception/SwaggerConfluenceInternalSystemException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.exception; 17 | 18 | public class SwaggerConfluenceInternalSystemException extends RuntimeException { 19 | 20 | public SwaggerConfluenceInternalSystemException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/exception/ConfluenceAPIException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.exception; 17 | 18 | public class ConfluenceAPIException extends RuntimeException { 19 | 20 | public ConfluenceAPIException(String message) { 21 | super(message); 22 | } 23 | 24 | public ConfluenceAPIException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/exception/SwaggerConfluenceConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.exception; 17 | 18 | public class SwaggerConfluenceConfigurationException extends RuntimeException { 19 | 20 | public SwaggerConfluenceConfigurationException(String message) { 21 | super(message); 22 | } 23 | 24 | public SwaggerConfluenceConfigurationException(String message, Throwable cause) { 25 | super(message, cause); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/src/main/java/net/slkdev/swagger/confluence/gradle/plugin/SwaggerConfluenceGradlePlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.gradle.plugin; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import org.gradle.api.Plugin; 20 | import org.gradle.api.Project; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | public class SwaggerConfluenceGradlePlugin implements Plugin { 26 | 27 | @Override 28 | public void apply(final Project project) { 29 | project.getExtensions().create("swaggerConfluence", SwaggerConfluenceConfig.class); 30 | 31 | final Map options = new HashMap<>(); 32 | options.put("type", SwaggerConfluenceGradleTask.class); 33 | 34 | project.task(options, "swaggerConfluence"); 35 | } 36 | 37 | } -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/context/SwaggerConfluenceContextConfigITCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.context; 17 | 18 | import org.junit.Test; 19 | import org.junit.runner.RunWith; 20 | import org.springframework.test.context.ContextConfiguration; 21 | import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; 22 | import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 23 | import org.springframework.test.context.support.AnnotationConfigContextLoader; 24 | 25 | @RunWith(SpringJUnit4ClassRunner.class) 26 | @ContextConfiguration(classes = SwaggerConfluenceContextConfig.class, 27 | loader=AnnotationConfigContextLoader.class) 28 | public class SwaggerConfluenceContextConfigITCase extends AbstractJUnit4SpringContextTests { 29 | 30 | @Test 31 | public void contextSmokeTest(){ 32 | applicationContext.getBean("restTemplate"); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/exception/SwaggerConfluenceInternalSystemExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.exception; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.junit.Assert.assertEquals; 21 | 22 | public class SwaggerConfluenceInternalSystemExceptionTest { 23 | 24 | @Test 25 | public void testConfluenceAPIException(){ 26 | final String message = "message"; 27 | final Throwable cause = new Exception(); 28 | 29 | final SwaggerConfluenceInternalSystemException swaggerConfluenceInternalSystemException = 30 | new SwaggerConfluenceInternalSystemException(message, cause); 31 | 32 | assertEquals("Expected Message Doesn't Match", message, 33 | swaggerConfluenceInternalSystemException.getMessage()); 34 | assertEquals("Expected Cause Doesn't Match", cause, 35 | swaggerConfluenceInternalSystemException.getCause()); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/service/impl/AsciiDocToXHtmlServiceImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import net.slkdev.swagger.confluence.service.AsciiDocToXHtmlService; 19 | import org.asciidoctor.internal.IOUtils; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.junit.Assert.assertNotNull; 24 | 25 | public class AsciiDocToXHtmlServiceImplTest { 26 | 27 | private AsciiDocToXHtmlService asciiDocToXHtmlService; 28 | 29 | @Before 30 | public void setUp(){ 31 | asciiDocToXHtmlService = new AsciiDocToXHtmlServiceImpl(); 32 | } 33 | 34 | @Test 35 | public void testAsciiDocToXHtmlConversion(){ 36 | final String asciiDoc = IOUtils.readFull( 37 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 38 | "/swagger-petstore-asciidoc-example.adoc") 39 | ); 40 | 41 | final String xhtml = asciiDocToXHtmlService.convertAsciiDocToXHtml(asciiDoc); 42 | 43 | assertNotNull("XHtml Output Should Not Be Null!", xhtml); 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/model/ConfluenceLink.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.model; 17 | 18 | import net.slkdev.swagger.confluence.constants.PageType; 19 | 20 | public class ConfluenceLink { 21 | private PageType pageType; 22 | private String originalHref; 23 | private String confluenceLinkMarkup; 24 | private String text; 25 | 26 | public PageType getPageType() { 27 | return pageType; 28 | } 29 | 30 | public void setPageType(PageType pageType) { 31 | this.pageType = pageType; 32 | } 33 | 34 | public String getOriginalHref() { 35 | return originalHref; 36 | } 37 | 38 | public void setOriginalHref(String originalHref) { 39 | this.originalHref = originalHref; 40 | } 41 | 42 | public String getConfluenceLinkMarkup() { 43 | return confluenceLinkMarkup; 44 | } 45 | 46 | public void setConfluenceLinkMarkup(String confluenceLinkMarkup) { 47 | this.confluenceLinkMarkup = confluenceLinkMarkup; 48 | } 49 | 50 | public String getText() { 51 | return text; 52 | } 53 | 54 | public void setText(String text) { 55 | this.text = text; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/exception/ConfluenceAPIExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.exception; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.junit.Assert.assertEquals; 21 | 22 | public class ConfluenceAPIExceptionTest { 23 | 24 | @Test 25 | public void testSwaggerConfluenceConfigurationExceptionWithNoCause(){ 26 | final String message = "message"; 27 | 28 | final ConfluenceAPIException confluenceAPIException = 29 | new ConfluenceAPIException(message); 30 | 31 | assertEquals("Expected Message Doesn't Match", message, 32 | confluenceAPIException.getMessage()); 33 | } 34 | 35 | @Test 36 | public void testConfluenceAPIExceptionWithCause(){ 37 | final String message = "message"; 38 | final Throwable cause = new Exception(); 39 | 40 | final ConfluenceAPIException confluenceAPIException = 41 | new ConfluenceAPIException(message, cause); 42 | 43 | assertEquals("Expected Message Doesn't Match", message, 44 | confluenceAPIException.getMessage()); 45 | assertEquals("Expected Cause Doesn't Match", cause, 46 | confluenceAPIException.getCause()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: java:8-jdk 2 | 3 | before_script: 4 | - export GRADLE_USER_HOME=`pwd`/.gradle 5 | 6 | stages: 7 | - build 8 | - analyze 9 | - publish 10 | 11 | cache: 12 | group: swagger_confluence 13 | key: "$CI_BUILD_REF_NAME" 14 | paths: 15 | - .gradle/wrapper 16 | - .gradle/caches 17 | 18 | job_build: 19 | stage: build 20 | script: 21 | - ./gradlew clean build shadowJar 22 | except: 23 | - master 24 | tags: 25 | - docker 26 | 27 | job_build_master: 28 | stage: build 29 | script: 30 | - ./gradlew clean build shadowJar -Prelease=true 31 | only: 32 | - master 33 | tags: 34 | - docker 35 | 36 | job_analyze_develop: 37 | stage: analyze 38 | script: 39 | - ./gradlew jacocoTestReport sonarqube -Dsonar.issuesReport.console.enable=true -Dsonar.gitlab.commit_sha=$CI_BUILD_REF -Dsonar.gitlab.ref=$CI_BUILD_REF_NAME 40 | only: 41 | - develop 42 | tags: 43 | - docker 44 | 45 | job_analyze_pull: 46 | stage: analyze 47 | script: 48 | - ./gradlew jacocoTestReport sonarqube -Dsonar.analysis.mode=preview -Dsonar.issuesReport.console.enable=true -Dsonar.gitlab.commit_sha=$CI_BUILD_REF -Dsonar.gitlab.ref=$CI_BUILD_REF_NAME 49 | except: 50 | - develop 51 | - master 52 | tags: 53 | - docker 54 | 55 | job_publish_develop: 56 | stage: publish 57 | only: 58 | - develop 59 | script: 60 | - ./gradlew publish 61 | artifacts: 62 | paths: 63 | - swagger-confluence-cli/build/libs/*.jar 64 | - swagger-confluence-core/build/libs/*.jar 65 | - swagger-confluence-gradle-plugin/build/libs/*.jar 66 | tags: 67 | - docker 68 | 69 | job_publish_master: 70 | stage: publish 71 | only: 72 | - master 73 | script: 74 | - ./gradlew publish -Prelease=true 75 | artifacts: 76 | paths: 77 | - swagger-confluence-cli/build/libs/*.jar 78 | - swagger-confluence-core/build/libs/*.jar 79 | - swagger-confluence-gradle-plugin/build/libs/*.jar 80 | tags: 81 | - docker -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/src/main/java/net/slkdev/swagger/confluence/gradle/plugin/SwaggerConfluenceGradleTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.gradle.plugin; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import net.slkdev.swagger.confluence.context.SwaggerConfluenceContextConfig; 20 | import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService; 21 | import org.gradle.api.DefaultTask; 22 | import org.gradle.api.tasks.TaskAction; 23 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 24 | 25 | public class SwaggerConfluenceGradleTask extends DefaultTask { 26 | 27 | @TaskAction 28 | public void swaggerConfluence() { 29 | final AnnotationConfigApplicationContext annotationConfigApplicationContext = 30 | new AnnotationConfigApplicationContext(SwaggerConfluenceContextConfig.class); 31 | final SwaggerToConfluenceService swaggerToConfluenceService = 32 | annotationConfigApplicationContext.getBean(SwaggerToConfluenceService.class); 33 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getProject().getExtensions().findByType(SwaggerConfluenceConfig.class); 34 | swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig); 35 | annotationConfigApplicationContext.close(); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/exception/SwaggerConfluenceConfigurationExceptionTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.exception; 17 | 18 | import org.junit.Test; 19 | 20 | import static org.junit.Assert.assertEquals; 21 | 22 | public class SwaggerConfluenceConfigurationExceptionTest { 23 | 24 | @Test 25 | public void testSwaggerConfluenceConfigurationExceptionWithNoCause(){ 26 | final String message = "message"; 27 | 28 | final SwaggerConfluenceConfigurationException swaggerConfluenceConfigurationException = 29 | new SwaggerConfluenceConfigurationException(message); 30 | 31 | assertEquals("Expected Message Doesn't Match", message, 32 | swaggerConfluenceConfigurationException.getMessage()); 33 | } 34 | 35 | @Test 36 | public void testSwaggerConfluenceConfigurationExceptionWithCause(){ 37 | final String message = "message"; 38 | final Throwable cause = new Exception(); 39 | 40 | final SwaggerConfluenceConfigurationException swaggerConfluenceConfigurationException = 41 | new SwaggerConfluenceConfigurationException(message, cause); 42 | 43 | assertEquals("Expected Message Doesn't Match", message, 44 | swaggerConfluenceConfigurationException.getMessage()); 45 | assertEquals("Expected Cause Doesn't Match", cause, 46 | swaggerConfluenceConfigurationException.getCause()); 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/service/impl/SwaggerToAsciiDocServiceImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import net.slkdev.swagger.confluence.service.SwaggerToAsciiDocService; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | import java.io.IOException; 23 | 24 | import static org.junit.Assert.assertNotNull; 25 | 26 | public class SwaggerToAsciiDocServiceImplTest { 27 | 28 | private SwaggerToAsciiDocService swaggerToAsciiDocService; 29 | 30 | @Before 31 | public void setUp(){ 32 | swaggerToAsciiDocService = new SwaggerToAsciiDocServiceImpl(); 33 | } 34 | 35 | @Test 36 | public void testSwaggerToAsciiDocConversionWithValidYamlIsSuccessful() throws IOException { 37 | final String asciiDoc = swaggerToAsciiDocService.convertSwaggerToAsciiDoc("/swagger-petstore-example.yaml"); 38 | 39 | // Note: Can't compare against the resource file as the upstream library 40 | // is not order deterministic - it will intermittently fail. Since this 41 | // initial stage is wrapping an upstream library in a fairly basic manner, 42 | // I will assume that its doing its job if I get an response for now. 43 | assertNotNull("Swagger Ascii Doc Should Not Be Null!", asciiDoc); 44 | } 45 | 46 | @Test(expected=RuntimeException.class) 47 | public void testSwaggerToAsciiDocConversionWithInvalidFileThrowsException(){ 48 | swaggerToAsciiDocService.convertSwaggerToAsciiDoc("/non-existant.yaml"); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/impl/AsciiDocToXHtmlServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import net.slkdev.swagger.confluence.service.AsciiDocToXHtmlService; 19 | import org.asciidoctor.Asciidoctor; 20 | import org.asciidoctor.AttributesBuilder; 21 | import org.asciidoctor.OptionsBuilder; 22 | import org.asciidoctor.Placement; 23 | import org.slf4j.Logger; 24 | import org.slf4j.LoggerFactory; 25 | 26 | import java.util.Map; 27 | 28 | import static org.asciidoctor.Asciidoctor.Factory.create; 29 | 30 | public class AsciiDocToXHtmlServiceImpl implements AsciiDocToXHtmlService { 31 | 32 | private static final Logger LOG = LoggerFactory.getLogger(AsciiDocToXHtmlServiceImpl.class); 33 | 34 | @Override 35 | public String convertAsciiDocToXHtml(final String asciiDoc) { 36 | LOG.info("Converting AsciiDoc to XHTML5..."); 37 | 38 | final Asciidoctor asciidoctor = create(); 39 | 40 | final Map attributes = AttributesBuilder.attributes() 41 | .unsetStyleSheet() 42 | .tableOfContents(Placement.TOP) 43 | .asMap(); 44 | 45 | final Map options = OptionsBuilder.options() 46 | .attributes(attributes) 47 | .backend("xhtml5") 48 | .asMap(); 49 | 50 | LOG.info("XHTML5 Conversion Complete!"); 51 | 52 | return asciidoctor.render(asciiDoc, options); 53 | } 54 | 55 | } 56 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/model/ConfluenceLinkBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.model; 17 | 18 | import net.slkdev.swagger.confluence.constants.PageType; 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | public class ConfluenceLinkBuilderTest { 24 | 25 | private static final String CONFLUENCE_LINK_MARKUP = ""; 26 | private static final String ORIGINAL_HREF = "#Root"; 27 | private static final PageType PAGE_TYPE = PageType.ROOT; 28 | private static final String TEXT = "Root"; 29 | 30 | @Test 31 | public void testBuilderWithAllFields(){ 32 | final ConfluenceLink confluenceLink = ConfluenceLinkBuilder.aConfluenceLink() 33 | .withConfluenceLinkMarkup(CONFLUENCE_LINK_MARKUP) 34 | .withOriginalHref(ORIGINAL_HREF) 35 | .withPageType(PAGE_TYPE) 36 | .withText(TEXT) 37 | .build(); 38 | 39 | assertEquals("Confluence Link Markup Doesn't Match!", CONFLUENCE_LINK_MARKUP, 40 | confluenceLink.getConfluenceLinkMarkup()); 41 | assertEquals("Original Href Doesn't Match!", ORIGINAL_HREF, 42 | confluenceLink.getOriginalHref()); 43 | assertEquals("Page Type Doesn't Match!", PAGE_TYPE, 44 | confluenceLink.getPageType()); 45 | assertEquals("Text Doesn't Match!", TEXT, 46 | confluenceLink.getText()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swagger-confluence-core/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | maven { 5 | url "https://plugins.gradle.org/m2/" 6 | } 7 | jcenter() 8 | mavenCentral() 9 | } 10 | dependencies { 11 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' 12 | } 13 | } 14 | 15 | apply plugin: 'com.jfrog.bintray' 16 | 17 | bintray { 18 | user = "$System.env.BINTRAY_USER" 19 | key = "$System.env.BINTRAY_PASS" 20 | publications = ['myPublication'] 21 | pkg { 22 | version { 23 | name = project.version 24 | } 25 | repo = "$System.env.BINTRAY_REPO" 26 | name = 'swagger-confluence-core' 27 | userOrg = "$System.env.BINTRAY_USER" 28 | licenses = ['Apache-2.0'] 29 | vcsUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence' 30 | websiteUrl = 'https://cloud.slkdev.net/swagger-confluence' 31 | issueTrackerUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/issues' 32 | labels = ['swagger','confluence'] 33 | } 34 | } 35 | 36 | dependencies { 37 | compile "org.slf4j:slf4j-api:$SLF4J_VERSION" 38 | 39 | compile "io.github.swagger2markup:swagger2markup:$SWAGGER2MARKUP_VERSION" 40 | compile "org.springframework:spring-core:$SPRING_VERSION" 41 | compile "org.springframework:spring-web:$SPRING_VERSION" 42 | compile "org.asciidoctor:asciidoctorj:$ASCIIDOCTORJ_VERSION" 43 | compile "com.jayway.jsonpath:json-path:$JSONPATH_VERSION" 44 | compile "org.jsoup:jsoup:$JSOUP_VERSION" 45 | 46 | compile "org.apache.logging.log4j:log4j-core:$LOG4J2_VERSION" 47 | compile "org.apache.logging.log4j:log4j-slf4j-impl:$LOG4J2_VERSION" 48 | 49 | testCompile "junit:junit:$JUNIT_VERSION" 50 | testCompile "org.mockito:mockito-core:$MOCKITO_VERSION" 51 | testCompile "org.springframework:spring-test:$SPRING_VERSION" 52 | } 53 | 54 | publishing { 55 | publications { 56 | myPublication(MavenPublication) { 57 | from components.java 58 | 59 | artifact sourceJar { 60 | classifier "sources" 61 | } 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/model/ConfluenceLinkBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.model; 17 | 18 | import net.slkdev.swagger.confluence.constants.PageType; 19 | 20 | public class ConfluenceLinkBuilder { 21 | private PageType pageType; 22 | private String originalHref; 23 | private String confluenceLinkMarkup; 24 | private String text; 25 | 26 | private ConfluenceLinkBuilder() { 27 | } 28 | 29 | public static ConfluenceLinkBuilder aConfluenceLink() { 30 | return new ConfluenceLinkBuilder(); 31 | } 32 | 33 | public ConfluenceLinkBuilder withPageType(PageType pageType) { 34 | this.pageType = pageType; 35 | return this; 36 | } 37 | 38 | public ConfluenceLinkBuilder withOriginalHref(String originalHref) { 39 | this.originalHref = originalHref; 40 | return this; 41 | } 42 | 43 | public ConfluenceLinkBuilder withConfluenceLinkMarkup(String confluenceLinkMarkup) { 44 | this.confluenceLinkMarkup = confluenceLinkMarkup; 45 | return this; 46 | } 47 | 48 | public ConfluenceLinkBuilder withText(String text) { 49 | this.text = text; 50 | return this; 51 | } 52 | 53 | public ConfluenceLink build() { 54 | ConfluenceLink confluenceLink = new ConfluenceLink(); 55 | confluenceLink.setPageType(pageType); 56 | confluenceLink.setOriginalHref(originalHref); 57 | confluenceLink.setConfluenceLinkMarkup(confluenceLinkMarkup); 58 | confluenceLink.setText(text); 59 | return confluenceLink; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /swagger-confluence-cli/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | maven { 5 | url "https://plugins.gradle.org/m2/" 6 | } 7 | jcenter() 8 | mavenCentral() 9 | } 10 | dependencies { 11 | classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.3' 12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' 13 | } 14 | } 15 | 16 | apply plugin: 'java' 17 | apply plugin: 'com.github.johnrengelman.shadow' 18 | apply plugin: 'com.jfrog.bintray' 19 | 20 | defaultTasks 'shadowJar' 21 | 22 | jar { 23 | manifest { 24 | attributes 'Main-Class': 'net.slkdev.swagger.confluence.cli.SwaggerConfluence' 25 | } 26 | } 27 | 28 | shadowJar { 29 | baseName = 'swagger-confluence-cli-all' 30 | classifier = '' 31 | mergeServiceFiles() 32 | append('NOTICE') 33 | } 34 | 35 | bintray { 36 | user = "$System.env.BINTRAY_USER" 37 | key = "$System.env.BINTRAY_PASS" 38 | publications = ['myPublication'] 39 | pkg { 40 | version { 41 | name = project.version 42 | } 43 | repo = "$System.env.BINTRAY_REPO" 44 | name = 'swagger-confluence-cli' 45 | userOrg = "$System.env.BINTRAY_USER" 46 | licenses = ['Apache-2.0'] 47 | vcsUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence' 48 | websiteUrl = 'https://cloud.slkdev.net/swagger-confluence' 49 | issueTrackerUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/issues' 50 | labels = ['swagger','confluence'] 51 | } 52 | } 53 | 54 | evaluationDependsOn(':swagger-confluence-core') 55 | 56 | dependencies { 57 | compile (project(':swagger-confluence-core')) 58 | compile "commons-cli:commons-cli:$COMMONS_CLI" 59 | 60 | testCompile "junit:junit:$JUNIT_VERSION" 61 | testCompile "org.mockito:mockito-core:$MOCKITO_VERSION" 62 | } 63 | 64 | publishing { 65 | publications { 66 | myPublication(MavenPublication) { 67 | from components.java 68 | artifactId = 'swagger-confluence-cli' 69 | 70 | artifact sourceJar { 71 | classifier "sources" 72 | } 73 | } 74 | myShadowPublication(MavenPublication) { 75 | from components.shadow 76 | artifactId = 'swagger-confluence-cli-all' 77 | 78 | artifact sourceJar { 79 | classifier "sources" 80 | } 81 | } 82 | } 83 | } 84 | 85 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/context/SwaggerConfluenceContextConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.context; 17 | 18 | import net.slkdev.swagger.confluence.service.AsciiDocToXHtmlService; 19 | import net.slkdev.swagger.confluence.service.SwaggerToAsciiDocService; 20 | import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService; 21 | import net.slkdev.swagger.confluence.service.XHtmlToConfluenceService; 22 | import net.slkdev.swagger.confluence.service.impl.AsciiDocToXHtmlServiceImpl; 23 | import net.slkdev.swagger.confluence.service.impl.SwaggerToAsciiDocServiceImpl; 24 | import net.slkdev.swagger.confluence.service.impl.SwaggerToConfluenceServiceImpl; 25 | import net.slkdev.swagger.confluence.service.impl.XHtmlToConfluenceServiceImpl; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | import org.springframework.web.client.RestTemplate; 29 | 30 | @Configuration 31 | public class SwaggerConfluenceContextConfig { 32 | 33 | @Bean 34 | public SwaggerToAsciiDocService swaggerToAsciiDocServiceImpl() { 35 | return new SwaggerToAsciiDocServiceImpl(); 36 | } 37 | 38 | @Bean 39 | public AsciiDocToXHtmlService asciiDocToXHtmlServiceImpl() { 40 | return new AsciiDocToXHtmlServiceImpl(); 41 | } 42 | 43 | @Bean 44 | public RestTemplate restTemplate() { 45 | return new RestTemplate(); 46 | } 47 | 48 | @Bean 49 | public XHtmlToConfluenceService xHtmlToConfluenceServiceImpl() { 50 | return new XHtmlToConfluenceServiceImpl(restTemplate()); 51 | } 52 | 53 | @Bean 54 | public SwaggerToConfluenceService swaggerToConfluenceServiceImpl() { 55 | return new SwaggerToConfluenceServiceImpl(swaggerToAsciiDocServiceImpl(), 56 | asciiDocToXHtmlServiceImpl(), xHtmlToConfluenceServiceImpl()); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/model/ConfluencePage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.model; 17 | 18 | import net.slkdev.swagger.confluence.constants.PageType; 19 | 20 | public class ConfluencePage { 21 | 22 | private Integer ancestorId; 23 | private String confluenceTitle; 24 | private Boolean exists; 25 | private String id; 26 | private String originalTitle; 27 | private PageType pageType; 28 | private Integer version; 29 | private String xhtml; 30 | 31 | public Integer getAncestorId() { 32 | return ancestorId; 33 | } 34 | 35 | public void setAncestorId(Integer ancestorId) { 36 | this.ancestorId = ancestorId; 37 | } 38 | 39 | public String getConfluenceTitle() { 40 | return confluenceTitle; 41 | } 42 | 43 | public void setConfluenceTitle(String confluenceTitle) { 44 | this.confluenceTitle = confluenceTitle; 45 | } 46 | 47 | public Boolean exists() { 48 | return exists; 49 | } 50 | 51 | public void setExists(Boolean exists) { 52 | this.exists = exists; 53 | } 54 | 55 | public String getId() { 56 | return id; 57 | } 58 | 59 | public void setId(String id) { 60 | this.id = id; 61 | } 62 | 63 | public String getOriginalTitle() { 64 | return originalTitle; 65 | } 66 | 67 | public void setOriginalTitle(String originalTitle) { 68 | this.originalTitle = originalTitle; 69 | } 70 | 71 | public PageType getPageType() { 72 | return pageType; 73 | } 74 | 75 | public void setPageType(PageType pageType) { 76 | this.pageType = pageType; 77 | } 78 | 79 | public Integer getVersion() { 80 | return version; 81 | } 82 | 83 | public void setVersion(Integer version) { 84 | this.version = version; 85 | } 86 | 87 | public String getXhtml() { 88 | return xhtml; 89 | } 90 | 91 | public void setXhtml(String xhtml) { 92 | this.xhtml = xhtml; 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /swagger-confluence-core/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/model/ConfluencePageBuilderTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.model; 17 | 18 | import net.slkdev.swagger.confluence.constants.PageType; 19 | import org.junit.Test; 20 | 21 | import static org.junit.Assert.assertEquals; 22 | 23 | public class ConfluencePageBuilderTest { 24 | 25 | private static final Integer ANCESTOR_ID = 1; 26 | private static final String CONFLUENCE_TITLE = "Confluence Title"; 27 | private static final Boolean EXISTS = true; 28 | private static final String ID = "1"; 29 | private static final String ORIGINAL_TITLE = "Original Title"; 30 | private static final PageType PAGE_TYPE = PageType.ROOT; 31 | private static final Integer VERSION = 1; 32 | private static final String XHTML = ""; 33 | 34 | @Test 35 | public void testBuilderWithAllFields(){ 36 | final ConfluencePage confluencePage = ConfluencePageBuilder.aConfluencePage() 37 | .withConfluenceTitle(CONFLUENCE_TITLE) 38 | .withPageType(PAGE_TYPE) 39 | .withAncestorId(ANCESTOR_ID) 40 | .withExists(EXISTS) 41 | .withId(ID) 42 | .withOriginalTitle(ORIGINAL_TITLE) 43 | .withVersion(VERSION) 44 | .withXhtml(XHTML) 45 | .build(); 46 | 47 | assertEquals("Ancestor Id Doesn't Match!", ANCESTOR_ID, 48 | confluencePage.getAncestorId()); 49 | assertEquals("Confluence Title Doesn't Match!", CONFLUENCE_TITLE, 50 | confluencePage.getConfluenceTitle()); 51 | assertEquals("Exists Doesn't Match!", EXISTS, 52 | confluencePage.exists()); 53 | assertEquals("Id Doesn't Match!", ID, confluencePage.getId()); 54 | assertEquals("Original Title Doesn't Match!", ORIGINAL_TITLE, 55 | confluencePage.getOriginalTitle()); 56 | assertEquals("Version Doesn't Match!", VERSION, 57 | confluencePage.getVersion()); 58 | assertEquals("XHTML Doesn't Match!", XHTML, 59 | confluencePage.getXhtml()); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/model/ConfluencePageBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.model; 17 | 18 | import net.slkdev.swagger.confluence.constants.PageType; 19 | 20 | public class ConfluencePageBuilder { 21 | private Integer ancestorId; 22 | private String confluenceTitle; 23 | private Boolean exists; 24 | private String id; 25 | private String originalTitle; 26 | private PageType pageType; 27 | private Integer version; 28 | private String xhtml; 29 | 30 | private ConfluencePageBuilder() { 31 | } 32 | 33 | public static ConfluencePageBuilder aConfluencePage() { 34 | return new ConfluencePageBuilder(); 35 | } 36 | 37 | public ConfluencePageBuilder withAncestorId(Integer ancestorId) { 38 | this.ancestorId = ancestorId; 39 | return this; 40 | } 41 | 42 | public ConfluencePageBuilder withConfluenceTitle(String confluenceTitle) { 43 | this.confluenceTitle = confluenceTitle; 44 | return this; 45 | } 46 | 47 | public ConfluencePageBuilder withExists(Boolean exists) { 48 | this.exists = exists; 49 | return this; 50 | } 51 | 52 | public ConfluencePageBuilder withId(String id) { 53 | this.id = id; 54 | return this; 55 | } 56 | 57 | public ConfluencePageBuilder withOriginalTitle(String originalTitle) { 58 | this.originalTitle = originalTitle; 59 | return this; 60 | } 61 | 62 | public ConfluencePageBuilder withPageType(PageType pageType) { 63 | this.pageType = pageType; 64 | return this; 65 | } 66 | 67 | public ConfluencePageBuilder withVersion(Integer version) { 68 | this.version = version; 69 | return this; 70 | } 71 | 72 | public ConfluencePageBuilder withXhtml(String xhtml) { 73 | this.xhtml = xhtml; 74 | return this; 75 | } 76 | 77 | public ConfluencePage build() { 78 | ConfluencePage confluencePage = new ConfluencePage(); 79 | confluencePage.setAncestorId(ancestorId); 80 | confluencePage.setConfluenceTitle(confluenceTitle); 81 | confluencePage.setExists(exists); 82 | confluencePage.setId(id); 83 | confluencePage.setOriginalTitle(originalTitle); 84 | confluencePage.setPageType(pageType); 85 | confluencePage.setVersion(version); 86 | confluencePage.setXhtml(xhtml); 87 | return confluencePage; 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/resources/swagger-confluence-create-json-body-user-example.json: -------------------------------------------------------------------------------- 1 | {"type":"page","title":"3.5. User","body":{"storage":{"value":"\n

User<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

email<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

firstName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

lastName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

password<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

phone<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

userStatus<\/strong>
\noptional<\/em><\/p><\/td>\n

User Status<\/p><\/td>\n

integer(int32)<\/p><\/td>\n<\/tr>\n

username<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","representation":"storage"}},"ancestors":[{"id":1,"type":"page"}],"space":{"key":"DOC"}} -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/resources/swagger-confluence-update-json-body-user-example.json: -------------------------------------------------------------------------------- 1 | {"id":"1277959","type":"page","title":"3.5. User","body":{"storage":{"value":"\n

User<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

email<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

firstName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

lastName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

password<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

phone<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

userStatus<\/strong>
\noptional<\/em><\/p><\/td>\n

User Status<\/p><\/td>\n

integer(int32)<\/p><\/td>\n<\/tr>\n

username<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","representation":"storage"}},"ancestors":[{"id":1474805,"type":"page"}],"version":{"number":2},"space":{"key":"DOC"}} -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | repositories { 3 | mavenLocal() 4 | maven { 5 | url "https://plugins.gradle.org/m2/" 6 | } 7 | jcenter() 8 | mavenCentral() 9 | } 10 | dependencies { 11 | classpath 'org.apache.maven:maven-model:3.3.9' 12 | classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.6' 13 | classpath "com.gradle.publish:plugin-publish-plugin:0.9.3" 14 | } 15 | } 16 | 17 | apply plugin: 'com.jfrog.bintray' 18 | apply plugin: "com.gradle.plugin-publish" 19 | 20 | bintray { 21 | user = "$System.env.BINTRAY_USER" 22 | key = "$System.env.BINTRAY_PASS" 23 | publications = ['myPublication'] 24 | pkg { 25 | version { 26 | name = project.version 27 | } 28 | repo = "$System.env.BINTRAY_REPO" 29 | name = 'swagger-confluence-gradle-plugin' 30 | userOrg = "$System.env.BINTRAY_USER" 31 | licenses = ['Apache-2.0'] 32 | vcsUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence' 33 | websiteUrl = 'https://cloud.slkdev.net/swagger-confluence' 34 | issueTrackerUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/issues' 35 | labels = ['swagger','confluence'] 36 | } 37 | } 38 | 39 | evaluationDependsOn(':swagger-confluence-core') 40 | 41 | dependencies { 42 | compile (project(':swagger-confluence-core')) 43 | compile gradleApi() 44 | } 45 | 46 | publishing { 47 | def mavenReleaseUrl = "$System.env.MAVEN_PUBLISH_PLUGIN_RELEASE_URL" 48 | def mavenSnapshotUrl = "$System.env.MAVEN_PUBLISH_PLUGIN_SNAPSHOT_URL" 49 | def mavenUser = "$System.env.MAVEN_PUBLISH_USER" 50 | def mavenPass = "$System.env.MAVEN_PUBLISH_PASS" 51 | 52 | repositories { 53 | maven { 54 | if (mavenReleaseUrl != "null" || mavenSnapshotUrl != "null") { 55 | if (mavenSnapshotUrl != "null" && project.version.endsWith('-SNAPSHOT')) { 56 | url mavenSnapshotUrl 57 | } 58 | else { 59 | url mavenReleaseUrl 60 | } 61 | credentials { 62 | username mavenUser 63 | password mavenPass 64 | } 65 | } 66 | else { 67 | url "${System.properties.'user.home'}/.m2/repository" 68 | } 69 | } 70 | } 71 | } 72 | 73 | publishing { 74 | publications { 75 | myPublication(MavenPublication) { 76 | from components.java 77 | 78 | artifact sourceJar { 79 | classifier "sources" 80 | } 81 | } 82 | } 83 | } 84 | 85 | pluginBundle { 86 | website = 'https://cloud.slkdev.net/swagger-confluence/' 87 | vcsUrl = 'https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence' 88 | description = 'A plugin for parsing a Swagger schema and publishing API documentation to an Atlassian Confluence server' 89 | tags = ['swagger', 'confluence'] 90 | 91 | plugins { 92 | swaggerConfluencePlugin { 93 | id = 'net.slkdev.swagger-confluence' 94 | displayName = 'Swagger Confluence' 95 | } 96 | } 97 | 98 | mavenCoordinates { 99 | groupId = "net.slkdev.swagger.confluence" 100 | artifactId = "swagger-confluence-gradle-plugin" 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /swagger-confluence-cli/src/test/java/net/slkdev/swagger/confluence/cli/SwaggerConfluenceTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.cli; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import net.slkdev.swagger.confluence.constants.PaginationMode; 20 | import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService; 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | import org.junit.runner.RunWith; 24 | import org.mockito.ArgumentCaptor; 25 | import org.mockito.Mock; 26 | import org.mockito.runners.MockitoJUnitRunner; 27 | 28 | import static org.junit.Assert.assertEquals; 29 | import static org.mockito.Mockito.verify; 30 | 31 | @RunWith(MockitoJUnitRunner.class) 32 | public class SwaggerConfluenceTest { 33 | 34 | @Mock 35 | private SwaggerToConfluenceService swaggerToConfluenceService; 36 | 37 | private SwaggerConfluence swaggerConfluence; 38 | 39 | @Before 40 | public void setUp(){ 41 | swaggerConfluence = new SwaggerConfluence(swaggerToConfluenceService); 42 | } 43 | 44 | @Test 45 | public void testRunCLI(){ 46 | final String[] args = new String[]{ 47 | "-b", "c3RhcmxpZ2h0a25pZ2h0OnRyb2wsb2NrNw==", 48 | "-g", "false", "-p", "[CLI]", "-i", "false", 49 | "-k", "DOC", "-s", "swagger-petstore-example.yaml", 50 | "-t", "Swagger Pet Store", "-m", "single" 51 | }; 52 | 53 | final ArgumentCaptor swaggerConfluenceConfigArgumentCaptor = 54 | ArgumentCaptor.forClass(SwaggerConfluenceConfig.class); 55 | 56 | swaggerConfluence.runCLI(args); 57 | 58 | verify(swaggerToConfluenceService).convertSwaggerToConfluence( 59 | swaggerConfluenceConfigArgumentCaptor.capture()); 60 | 61 | final SwaggerConfluenceConfig swaggerConfluenceConfig = 62 | swaggerConfluenceConfigArgumentCaptor.getValue(); 63 | 64 | assertEquals("Authentication Parsed Incorrectly!", args[1], 65 | swaggerConfluenceConfig.getAuthentication()); 66 | assertEquals("Generate Numeric Prefixes Parsed Incorrectly!", Boolean.valueOf(args[3]), 67 | swaggerConfluenceConfig.isGenerateNumericPrefixes()); 68 | assertEquals("Prefix Parsed Incorrectly!", args[5]+" ", 69 | swaggerConfluenceConfig.getPrefix()); 70 | assertEquals("Include ToC for Single Parsed Incorrectly!", Boolean.valueOf(args[7]), 71 | swaggerConfluenceConfig.isIncludeTableOfContentsOnSinglePage()); 72 | assertEquals("Space Key Parsed Incorrectly!", args[9], 73 | swaggerConfluenceConfig.getSpaceKey()); 74 | assertEquals("Schema Location Parsed Incorrectly!", args[11], 75 | swaggerConfluenceConfig.getSwaggerSchema()); 76 | assertEquals("Title Parsed Incorrectly!", args[13], 77 | swaggerConfluenceConfig.getTitle()); 78 | assertEquals("Pagination Mode Parsed Incorrectly!", PaginationMode.SINGLE_PAGE, 79 | swaggerConfluenceConfig.getPaginationMode()); 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/service/impl/SwaggerToConfluenceImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import net.slkdev.swagger.confluence.constants.PaginationMode; 20 | import net.slkdev.swagger.confluence.service.AsciiDocToXHtmlService; 21 | import net.slkdev.swagger.confluence.service.SwaggerToAsciiDocService; 22 | import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService; 23 | import net.slkdev.swagger.confluence.service.XHtmlToConfluenceService; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | import org.junit.runner.RunWith; 27 | import org.mockito.Mock; 28 | import org.mockito.runners.MockitoJUnitRunner; 29 | 30 | @RunWith(MockitoJUnitRunner.class) 31 | public class SwaggerToConfluenceImplTest { 32 | 33 | @Mock 34 | private AsciiDocToXHtmlService asciiDocToXHtmlService; 35 | 36 | @Mock 37 | private SwaggerToAsciiDocService swaggerToAsciiDocService; 38 | 39 | @Mock 40 | private XHtmlToConfluenceService xHtmlToConfluenceService; 41 | 42 | private SwaggerConfluenceConfig swaggerConfluenceConfig; 43 | private SwaggerToConfluenceService swaggerToConfluenceService; 44 | 45 | @Before 46 | public void setUp(){ 47 | swaggerToConfluenceService = new SwaggerToConfluenceServiceImpl( 48 | swaggerToAsciiDocService, asciiDocToXHtmlService, xHtmlToConfluenceService); 49 | swaggerConfluenceConfig = new SwaggerConfluenceConfig(); 50 | swaggerConfluenceConfig.setAncestorId(1); 51 | swaggerConfluenceConfig.setIncludeTableOfContentsOnSinglePage(true); 52 | swaggerConfluenceConfig.setSpaceKey("TEST"); 53 | swaggerConfluenceConfig.setSwaggerSchema("test.yaml"); 54 | swaggerConfluenceConfig.setPrefix("[TEST]"); 55 | swaggerConfluenceConfig.setAuthentication("abcdef"); 56 | swaggerConfluenceConfig.setConfluenceRestApiUrl("http://localhost/rest/api"); 57 | swaggerConfluenceConfig.setGenerateNumericPrefixes(true); 58 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.SINGLE_PAGE); 59 | swaggerConfluenceConfig.setTitle("Test"); 60 | } 61 | 62 | @Test(expected=NullPointerException.class) 63 | public void testSwaggerSchemaCannotBeNull(){ 64 | swaggerConfluenceConfig.setSwaggerSchema(null); 65 | swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig); 66 | } 67 | 68 | @Test(expected=NullPointerException.class) 69 | public void testConfluenceRestAPIUrlCannotBeNull(){ 70 | swaggerConfluenceConfig.setConfluenceRestApiUrl(null); 71 | swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig); 72 | } 73 | 74 | @Test(expected=NullPointerException.class) 75 | public void testAuthenticationCannotBeNull(){ 76 | swaggerConfluenceConfig.setAuthentication(null); 77 | swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig); 78 | } 79 | 80 | @Test(expected=NullPointerException.class) 81 | public void testSpaceKeyCannotBeNull(){ 82 | swaggerConfluenceConfig.setSpaceKey(null); 83 | swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/impl/SwaggerToConfluenceServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import net.slkdev.swagger.confluence.constants.PaginationMode; 20 | import net.slkdev.swagger.confluence.service.AsciiDocToXHtmlService; 21 | import net.slkdev.swagger.confluence.service.SwaggerToAsciiDocService; 22 | import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService; 23 | import net.slkdev.swagger.confluence.service.XHtmlToConfluenceService; 24 | import org.slf4j.Logger; 25 | import org.slf4j.LoggerFactory; 26 | 27 | import static org.apache.commons.lang3.Validate.notNull; 28 | 29 | public class SwaggerToConfluenceServiceImpl implements SwaggerToConfluenceService { 30 | 31 | private static final Logger LOG = LoggerFactory.getLogger(SwaggerToConfluenceServiceImpl.class); 32 | 33 | private final SwaggerToAsciiDocService swaggerToAsciiDocService; 34 | private final AsciiDocToXHtmlService asciiDocToXHtmlService; 35 | private final XHtmlToConfluenceService xHtmlToConfluenceService; 36 | 37 | public SwaggerToConfluenceServiceImpl(final SwaggerToAsciiDocService swaggerToAsciiDocService, 38 | final AsciiDocToXHtmlService asciiDocToXHtmlService, 39 | final XHtmlToConfluenceService xHtmlToConfluenceService) { 40 | this.swaggerToAsciiDocService = swaggerToAsciiDocService; 41 | this.asciiDocToXHtmlService = asciiDocToXHtmlService; 42 | this.xHtmlToConfluenceService = xHtmlToConfluenceService; 43 | } 44 | 45 | @Override 46 | public void convertSwaggerToConfluence(final SwaggerConfluenceConfig swaggerConfluenceConfig) { 47 | final String swaggerSchema = swaggerConfluenceConfig.getSwaggerSchema(); 48 | final String confluenceRestApiUrl = swaggerConfluenceConfig.getConfluenceRestApiUrl(); 49 | final String spaceKey = swaggerConfluenceConfig.getSpaceKey(); 50 | final String prefix = swaggerConfluenceConfig.getPrefix(); 51 | final PaginationMode paginationMode = swaggerConfluenceConfig.getPaginationMode(); 52 | 53 | notNull(swaggerSchema, "Swagger Schema Cannot Be Null!"); 54 | notNull(confluenceRestApiUrl, "Confluence REST API URL Cannot Be Null!"); 55 | notNull(swaggerConfluenceConfig.getAuthentication(), "Confluence Authentication Cannot Be Null!"); 56 | notNull(spaceKey, "Confluence Space Key Cannot Be Null!"); 57 | 58 | LOG.info("Publishing Swagger API Documentation to Confluence..."); 59 | LOG.info("Swagger Schema: {}", swaggerSchema); 60 | LOG.info("Confluence REST API URL: {}", confluenceRestApiUrl); 61 | LOG.info("Confluence Space Key: {}", spaceKey); 62 | LOG.info("Confluence PaginationMode: {}", paginationMode); 63 | 64 | if (prefix == null) { 65 | LOG.info("Confluence Title Prefix: No Prefix Supplied"); 66 | } else { 67 | LOG.info("Confluence Title Prefix: {}", prefix); 68 | } 69 | 70 | LOG.info("Confluence Generate Numeric Prefixes: {}", 71 | swaggerConfluenceConfig.isGenerateNumericPrefixes()); 72 | 73 | final String asciiDoc = swaggerToAsciiDocService.convertSwaggerToAsciiDoc(swaggerSchema); 74 | final String xhtml = asciiDocToXHtmlService.convertAsciiDocToXHtml(asciiDoc); 75 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/service/impl/SwaggerToAsciiDocServiceImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import io.github.swagger2markup.*; 19 | import io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder; 20 | import io.github.swagger2markup.markup.builder.MarkupLanguage; 21 | import net.slkdev.swagger.confluence.exception.SwaggerConfluenceConfigurationException; 22 | import net.slkdev.swagger.confluence.exception.SwaggerConfluenceInternalSystemException; 23 | import net.slkdev.swagger.confluence.service.SwaggerToAsciiDocService; 24 | import org.apache.commons.io.FileUtils; 25 | import org.slf4j.Logger; 26 | import org.slf4j.LoggerFactory; 27 | 28 | import java.io.File; 29 | import java.io.FileNotFoundException; 30 | import java.io.IOException; 31 | import java.net.URISyntaxException; 32 | import java.net.URL; 33 | import java.nio.charset.StandardCharsets; 34 | 35 | public class SwaggerToAsciiDocServiceImpl implements SwaggerToAsciiDocService { 36 | 37 | private static final Logger LOG = LoggerFactory.getLogger(SwaggerToAsciiDocServiceImpl.class); 38 | 39 | @Override 40 | public String convertSwaggerToAsciiDoc(final String swaggerSchemaPath) { 41 | final File swaggerSchemaFile; 42 | 43 | LOG.info("Converting Swagger Schema to Ascii Doc..."); 44 | 45 | try { 46 | swaggerSchemaFile = getSchemaFile(swaggerSchemaPath); 47 | } catch (final FileNotFoundException | URISyntaxException e) { 48 | throw new SwaggerConfluenceConfigurationException("Error Locating Swagger Schema", e); 49 | } 50 | 51 | 52 | final String swaggerAsciiDoc; 53 | 54 | try { 55 | final Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() 56 | .withMarkupLanguage(MarkupLanguage.ASCIIDOC) 57 | .withOutputLanguage(Language.EN) 58 | .withPathsGroupedBy(GroupBy.AS_IS) 59 | .withOperationOrdering(OrderBy.AS_IS) 60 | .build(); 61 | 62 | final String swaggerSchema = FileUtils.readFileToString(swaggerSchemaFile, StandardCharsets.UTF_8); 63 | 64 | swaggerAsciiDoc = Swagger2MarkupConverter.from(swaggerSchema) 65 | .withConfig(config) 66 | .build() 67 | .toString(); 68 | 69 | } catch (IOException e) { 70 | throw new SwaggerConfluenceInternalSystemException( 71 | "Error Converting Swagger Schema to AsciiDoc", e); 72 | } 73 | 74 | LOG.info("AsciiDoc Conversion Complete!"); 75 | 76 | return swaggerAsciiDoc; 77 | } 78 | 79 | private static File getSchemaFile(final String swaggerSchemaPath) throws FileNotFoundException, URISyntaxException { 80 | // First we'll try to find the file directly 81 | File swaggerFile = new File(swaggerSchemaPath); 82 | 83 | // If we can't find it, we'll check the classpath 84 | if (!swaggerFile.exists()) { 85 | final URL swaggerSchemaURL = SwaggerToAsciiDocServiceImpl.class.getResource(swaggerSchemaPath); 86 | 87 | if (swaggerSchemaURL == null) { 88 | swaggerFile = null; 89 | } else { 90 | swaggerFile = new File(swaggerSchemaURL.toURI()); 91 | } 92 | } 93 | 94 | if (swaggerFile == null || !swaggerFile.exists() || !swaggerFile.canRead()) { 95 | throw new FileNotFoundException( 96 | String.format("Unable to Locate Swagger Schema at Path <%s>", 97 | swaggerSchemaPath)); 98 | } 99 | 100 | return swaggerFile; 101 | } 102 | 103 | } 104 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/main/java/net/slkdev/swagger/confluence/config/SwaggerConfluenceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.config; 17 | 18 | import net.slkdev.swagger.confluence.constants.PaginationMode; 19 | import net.slkdev.swagger.confluence.exception.SwaggerConfluenceConfigurationException; 20 | import org.apache.commons.lang3.StringUtils; 21 | 22 | public class SwaggerConfluenceConfig { 23 | 24 | private Integer ancestorId; 25 | private String authentication; 26 | private String confluenceRestApiUrl; 27 | private boolean generateNumericPrefixes; 28 | private boolean includeTableOfContentsOnSinglePage; 29 | private PaginationMode paginationMode; 30 | private String prefix; 31 | private String spaceKey; 32 | private String swaggerSchema; 33 | private String title; 34 | 35 | public SwaggerConfluenceConfig() { 36 | generateNumericPrefixes = true; 37 | includeTableOfContentsOnSinglePage = true; 38 | paginationMode = PaginationMode.SINGLE_PAGE; 39 | } 40 | 41 | public Integer getAncestorId() { 42 | return ancestorId; 43 | } 44 | 45 | public void setAncestorId(final Integer ancestorId) { 46 | this.ancestorId = ancestorId; 47 | } 48 | 49 | public String getAuthentication() { 50 | return authentication; 51 | } 52 | 53 | public void setAuthentication(final String authentication) { 54 | this.authentication = authentication; 55 | } 56 | 57 | public String getConfluenceRestApiUrl() { 58 | return confluenceRestApiUrl; 59 | } 60 | 61 | public void setConfluenceRestApiUrl(final String confluenceRestApiUrl) { 62 | this.confluenceRestApiUrl = confluenceRestApiUrl; 63 | } 64 | 65 | public boolean isGenerateNumericPrefixes() { 66 | return generateNumericPrefixes; 67 | } 68 | 69 | public void setGenerateNumericPrefixes(final boolean generateNumericPrefixes) { 70 | this.generateNumericPrefixes = generateNumericPrefixes; 71 | } 72 | 73 | public boolean isIncludeTableOfContentsOnSinglePage() { 74 | return includeTableOfContentsOnSinglePage; 75 | } 76 | 77 | public void setIncludeTableOfContentsOnSinglePage(final boolean includeTableOfContentsOnSinglePage) { 78 | this.includeTableOfContentsOnSinglePage = includeTableOfContentsOnSinglePage; 79 | } 80 | 81 | public PaginationMode getPaginationMode() { 82 | return paginationMode; 83 | } 84 | 85 | public void setPaginationMode(final PaginationMode paginationMode) { 86 | this.paginationMode = paginationMode; 87 | } 88 | 89 | public void setPaginationMode(final String paginationMode) { 90 | switch (paginationMode) { 91 | case "single": 92 | this.paginationMode = PaginationMode.SINGLE_PAGE; 93 | break; 94 | case "category": 95 | this.paginationMode = PaginationMode.CATEGORY_PAGES; 96 | break; 97 | case "individual": 98 | this.paginationMode = PaginationMode.INDIVIDUAL_PAGES; 99 | break; 100 | default: 101 | throw new SwaggerConfluenceConfigurationException( 102 | String.format("Invalid Pagination Mode <%s>", paginationMode) 103 | ); 104 | } 105 | } 106 | 107 | public String getPrefix() { 108 | return prefix; 109 | } 110 | 111 | public void setPrefix(final String prefix) { 112 | if (prefix.endsWith(" ")) { 113 | this.prefix = prefix; 114 | } else if (StringUtils.isNotEmpty(prefix)){ 115 | this.prefix = prefix + ' '; 116 | } else { 117 | this.prefix = prefix; 118 | } 119 | } 120 | 121 | public String getSpaceKey() { 122 | return spaceKey; 123 | } 124 | 125 | public void setSpaceKey(final String spaceKey) { 126 | this.spaceKey = spaceKey; 127 | } 128 | 129 | public String getSwaggerSchema() { 130 | return swaggerSchema; 131 | } 132 | 133 | public void setSwaggerSchema(final String swaggerSchema) { 134 | this.swaggerSchema = swaggerSchema; 135 | } 136 | 137 | public String getTitle() { 138 | return title; 139 | } 140 | 141 | public void setTitle(final String title) { 142 | this.title = title; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Swagger Confluence 2 | 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 | 7 | ## Overview 8 | 9 | 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 10 | 11 | 12 | 13 | While this was possible via stringing together other projects, it was not easy to drop in and use. 14 | 15 | 16 | 17 | This project uses the following flow to publish to Confluence: 18 | 19 | 20 | 21 | Your Swagger Schema -> Swagger2Markup -> AsciiDoctorJ -> XHTML -> Confluence REST API 22 | 23 | 24 | 25 | This project requires the use of Java 7 or later. 26 | 27 | ## Components 28 | 29 | The project is current broken into three components 30 | 31 | - **swagger-confluence-core:** a core shared library to handle converting and publishing the swagger schema to confluence. This shared library should be reusable by other projects 32 | - **swagger-confluence-gradle-plugin:** a gradle plugin to provide seamless conversion and publishing 33 | - **swagger-confluence-cli:** a command line executor for publishing to swagger docs to confluence 34 | 35 | ## Documentation & Usage Guide 36 | 37 | You can view the documentation and usage guide [here](https://cloud.slkdev.net/swagger-confluence) 38 | 39 | ## Live Demo 40 | 41 | You can view a live demo of Swagger Confluence [here on my Confluence Server](https://cloud.slkdev.net/confluence/display/DEMO/Swagger+Confluence+Demos) 42 | 43 | ## Contributing 44 | 45 | ### Community contributions 46 | 47 | Pull requests are welcome. The primary source repository for this project is hosted on my [GitLab CE Instance](https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence). 48 | 49 | 50 | It is preferred that if you wish to contribute, you submit there as this is where I have CI, SonarQube, etc set up. GitLab CE officially provides OmniAuth integration to make this easy, or you can of course sign up manually as well. 51 | 52 | 53 | GitLab CE is open source software. If you are unfamiliar with it, you can read more about it [here](https://about.gitlab.com/) on their official web site. 54 | 55 | 56 | If you are not comfortable with this, you may submit via the GitHub mirror, and I will merge it back manually. 57 | 58 | ### Questions, Bugs, or Enhacement Requests 59 | 60 | 61 | 62 | If you have any questions about the project, please feel free to open an [issue](https://cloud.slkdev.net/gitlab/starlightknight/swagger-confluence/issues) 63 | 64 | 65 | 66 | If you believe you have found a bug in the project, please take a moment to search the existing issues before posting a new one. If there is no existing issue regarding the problem, please open a new issue that describes the problem in detail. If possible, please also include a unit test that reproduces the problem. 67 | 68 | 69 | 70 | If you would like an enhancement to be made to the Swagger Confluence, pull requests are welcome. Before beginning work on an enhancement, you may want to search the existing issues and pull requests to see if a similar enhancement is already being worked on. You may also want to open a new issue to discuss the enhancement. 71 | 72 | 73 | 74 | ## Static Code Analysis + Coverage 75 | 76 | See [SonarQube](https://cloud.slkdev.net/sonar/overview?id=30) for this project 77 | 78 | ## Special Thanks 79 | 80 | 81 | A special thanks for the following projects, who make this project possible: 82 | 83 | 84 | * [Swagger2Markup](https://github.com/Swagger2Markup/swagger2markup) 85 | * [AsciiDoctorJ](https://github.com/asciidoctor/asciidoctorj) 86 | * [JSoup](http://jsoup.org/) 87 | * [Confluence REST API](https://developer.atlassian.com/confdev/confluence-rest-api) 88 | 89 | 90 | 91 | 92 | Additional shout-outs to the following two projects - whom I tried using manually in 93 | conjunction with the above projects and their respective gradle plugins before starting this project: 94 | 95 | * [asciidoctor-confluence](https://github.com/gscheibel/asciidoctor-confluence) 96 | * [asciidoc2confluence](https://github.com/rdmueller/asciidoc2confluence) 97 | 98 | The XHTML->Confluence REST API portion of this library was originally inspired by the 99 | asciidoc2confluence groovy script 100 | 101 | ## License 102 | 103 | Copyright 2016 Aaron Knight 104 | 105 | 106 | 107 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at 108 | 109 | 110 | 111 | http://www.apache.org/licenses/LICENSE-2.0 112 | 113 | 114 | 115 | Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 116 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /swagger-confluence-core/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /swagger-confluence-gradle-plugin/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /swagger-confluence-cli/src/main/java/net/slkdev/swagger/confluence/cli/SwaggerConfluence.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.cli; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import net.slkdev.swagger.confluence.context.SwaggerConfluenceContextConfig; 20 | import net.slkdev.swagger.confluence.exception.SwaggerConfluenceConfigurationException; 21 | import net.slkdev.swagger.confluence.service.SwaggerToConfluenceService; 22 | import org.apache.commons.cli.*; 23 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; 24 | 25 | import static org.apache.commons.lang3.Validate.notNull; 26 | 27 | public class SwaggerConfluence { 28 | 29 | private SwaggerToConfluenceService swaggerToConfluenceService; 30 | 31 | public SwaggerConfluence(final SwaggerToConfluenceService swaggerToConfluenceService){ 32 | notNull(swaggerToConfluenceService, "SwaggerToConfluenceService Cannot Be Null!"); 33 | this.swaggerToConfluenceService = swaggerToConfluenceService; 34 | } 35 | 36 | public static void main(final String[] args){ 37 | final SwaggerToConfluenceService swaggerToConfluenceService = bootSwaggerConfluence(); 38 | final SwaggerConfluence swaggerConfluence = new SwaggerConfluence(swaggerToConfluenceService); 39 | swaggerConfluence.runCLI(args); 40 | } 41 | 42 | private static SwaggerToConfluenceService bootSwaggerConfluence(){ 43 | final AnnotationConfigApplicationContext annotationConfigApplicationContext = 44 | new AnnotationConfigApplicationContext(SwaggerConfluenceContextConfig.class); 45 | final SwaggerToConfluenceService swaggerToConfluenceService = 46 | annotationConfigApplicationContext.getBean(SwaggerToConfluenceService.class); 47 | annotationConfigApplicationContext.close(); 48 | 49 | return swaggerToConfluenceService; 50 | } 51 | 52 | public void runCLI(final String[] args){ 53 | final Options options = buildOptions(); 54 | final CommandLine commandLine = parseCommandLineOptions(options, args); 55 | 56 | if(commandLine.hasOption("h") || args.length == 0){ 57 | final HelpFormatter formatter = new HelpFormatter(); 58 | formatter.printHelp("swagger-confluence-cli", options); 59 | } 60 | else { 61 | final SwaggerConfluenceConfig swaggerConfluenceConfig = 62 | buildSwaggerConfluenceConfig(commandLine); 63 | swaggerToConfluenceService.convertSwaggerToConfluence(swaggerConfluenceConfig); 64 | } 65 | } 66 | 67 | private static Options buildOptions(){ 68 | final Options options = new Options(); 69 | 70 | options.addOption("a", "ancestor-id", true, "ancestor id to use for the published api doc"); 71 | options.addOption("b", "authentication", true, "base64 encoded user:pass pair for authentication"); 72 | options.addOption("g", "generate-numeric-prefixes", true, "boolean flag to indicate whether to " + 73 | "generate numeric prefixes for titles"); 74 | options.addOption("h", "help", false, "Print help message with usage information"); 75 | options.addOption("i", "include-toc-on-single", true, "Include table of contents on single page mode"); 76 | options.addOption("k", "space-key", true, "Space Key to publish api doc to"); 77 | options.addOption("m", "pagination-mode", true, "Pagination mode to use: [single, category, individual]"); 78 | options.addOption("s", "swagger-schema", true, "Swagger Schema name. Absolute, relative, or classpath location"); 79 | options.addOption("p", "prefix", true, "Prefix to use for article titles to ensure uniqueness"); 80 | options.addOption("t", "title", true, "Base title to use for the root article of the API doc"); 81 | options.addOption("u", "confluence-rest-api-url", true, "URL to the confluence REST API"); 82 | 83 | return options; 84 | } 85 | 86 | private static CommandLine parseCommandLineOptions(final Options options, final String[] args){ 87 | final CommandLineParser commandLineParser = new DefaultParser(); 88 | 89 | try { 90 | return commandLineParser.parse(options, args); 91 | 92 | } catch (ParseException e) { 93 | throw new SwaggerConfluenceConfigurationException( 94 | "Error Parsing Command Line Arguments!", e); 95 | } 96 | } 97 | 98 | private static SwaggerConfluenceConfig buildSwaggerConfluenceConfig(final CommandLine commandLine){ 99 | final SwaggerConfluenceConfig swaggerConfluenceConfig = new SwaggerConfluenceConfig(); 100 | final String ancestorIdString = commandLine.getOptionValue("a"); 101 | final Integer ancestorId; 102 | 103 | if(ancestorIdString == null){ 104 | ancestorId = null; 105 | } 106 | else { 107 | ancestorId = Integer.valueOf(ancestorIdString); 108 | } 109 | 110 | swaggerConfluenceConfig.setAncestorId(ancestorId); 111 | swaggerConfluenceConfig.setAuthentication(commandLine.getOptionValue("b")); 112 | swaggerConfluenceConfig.setConfluenceRestApiUrl(commandLine.getOptionValue("u")); 113 | swaggerConfluenceConfig.setGenerateNumericPrefixes( 114 | Boolean.valueOf(commandLine.getOptionValue("g", "true")) 115 | ); 116 | swaggerConfluenceConfig.setIncludeTableOfContentsOnSinglePage( 117 | Boolean.valueOf(commandLine.getOptionValue("i", "true")) 118 | ); 119 | swaggerConfluenceConfig.setPaginationMode(commandLine.getOptionValue("m","single")); 120 | 121 | final String prefix = commandLine.getOptionValue("p"); 122 | 123 | if(prefix != null){ 124 | swaggerConfluenceConfig.setPrefix(prefix); 125 | } 126 | 127 | swaggerConfluenceConfig.setSpaceKey(commandLine.getOptionValue("k")); 128 | swaggerConfluenceConfig.setSwaggerSchema(commandLine.getOptionValue("s")); 129 | swaggerConfluenceConfig.setTitle(commandLine.getOptionValue("t")); 130 | 131 | return swaggerConfluenceConfig; 132 | } 133 | 134 | } 135 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/config/SwaggerConfluenceConfigTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.config; 17 | 18 | import net.slkdev.swagger.confluence.constants.PaginationMode; 19 | import net.slkdev.swagger.confluence.exception.SwaggerConfluenceConfigurationException; 20 | import org.junit.Before; 21 | import org.junit.Test; 22 | 23 | import static org.junit.Assert.*; 24 | 25 | public class SwaggerConfluenceConfigTest { 26 | 27 | private SwaggerConfluenceConfig swaggerConfluenceConfig; 28 | 29 | @Before 30 | public void setUp(){ 31 | swaggerConfluenceConfig = new SwaggerConfluenceConfig(); 32 | } 33 | 34 | @Test 35 | public void testNoDefaultAncestorIdExists(){ 36 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getAncestorId()); 37 | } 38 | 39 | @Test 40 | public void testGetAndSetAncestorId(){ 41 | swaggerConfluenceConfig.setAncestorId(1);; 42 | assertEquals("Expected AncestorId 1", Integer.valueOf(1), 43 | swaggerConfluenceConfig.getAncestorId()); 44 | } 45 | 46 | @Test 47 | public void testNoDefaultAuthenticationExists(){ 48 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getAuthentication()); 49 | } 50 | 51 | @Test 52 | public void testGetAndSetAuthentication(){ 53 | swaggerConfluenceConfig.setAuthentication("abc"); 54 | assertEquals("Expected Authentication \"abc\"", "abc", 55 | swaggerConfluenceConfig.getAuthentication()); 56 | } 57 | 58 | @Test 59 | public void testNoDefaultConfluenceRestApiUrlExists(){ 60 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getConfluenceRestApiUrl()); 61 | } 62 | 63 | @Test 64 | public void testGetAndSetConfluenceRestApiUrl(){ 65 | swaggerConfluenceConfig.setConfluenceRestApiUrl("http://localhost"); 66 | assertEquals("Expected Confluence Rest Api \"http://localhost\"", "http://localhost", 67 | swaggerConfluenceConfig.getConfluenceRestApiUrl()); 68 | } 69 | 70 | @Test 71 | public void testDefaultGenerateNumericPrefixes(){ 72 | assertTrue("Default Should \"true\"", swaggerConfluenceConfig.isGenerateNumericPrefixes()); 73 | } 74 | 75 | @Test 76 | public void testGetAndSetGenerateNumericPrefixes(){ 77 | swaggerConfluenceConfig.setGenerateNumericPrefixes(false); 78 | assertFalse("Expected Generate Numeric Prefixes -> False", 79 | swaggerConfluenceConfig.isGenerateNumericPrefixes()); 80 | } 81 | 82 | @Test 83 | public void testDefaultIncludeTableOfContentsOnSinglePage(){ 84 | assertTrue("Default Should \"true\"", swaggerConfluenceConfig.isIncludeTableOfContentsOnSinglePage()); 85 | } 86 | 87 | @Test 88 | public void testGetAndSetIncludeTableOfContentsOnSinglePage(){ 89 | swaggerConfluenceConfig.setIncludeTableOfContentsOnSinglePage(false); 90 | assertFalse("Expected Include Table Of Contents On Single Page -> False", 91 | swaggerConfluenceConfig.isIncludeTableOfContentsOnSinglePage()); 92 | } 93 | 94 | @Test 95 | public void testDefaultPaginationModeIsSingle(){ 96 | assertEquals("Default Should \"SINGLE_PAGE\"", PaginationMode.SINGLE_PAGE, 97 | swaggerConfluenceConfig.getPaginationMode()); 98 | } 99 | 100 | @Test 101 | public void testEnumPaginationModeWithSingle(){ 102 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.SINGLE_PAGE); 103 | assertEquals("Expected Pagination Mode \"SINGLE_PAGE\"", PaginationMode.SINGLE_PAGE, 104 | swaggerConfluenceConfig.getPaginationMode()); 105 | } 106 | 107 | @Test 108 | public void testEnumPaginationModeWithCategory(){ 109 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.CATEGORY_PAGES); 110 | assertEquals("Expected Pagination Mode \"CATEGORY_PAGES\"", 111 | PaginationMode.CATEGORY_PAGES, swaggerConfluenceConfig.getPaginationMode()); 112 | } 113 | 114 | @Test 115 | public void testEnumPaginationModeWithIndividual(){ 116 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.INDIVIDUAL_PAGES); 117 | assertEquals("Expected Pagination Mode \"INDIVIDUAL_PAGES\"", 118 | PaginationMode.INDIVIDUAL_PAGES, swaggerConfluenceConfig.getPaginationMode()); 119 | } 120 | 121 | @Test 122 | public void testStringPaginationModeWithSingle(){ 123 | swaggerConfluenceConfig.setPaginationMode("single"); 124 | assertEquals("Expected Pagination Mode \"SINGLE_PAGE\"", PaginationMode.SINGLE_PAGE, 125 | swaggerConfluenceConfig.getPaginationMode()); 126 | } 127 | 128 | @Test 129 | public void testStringPaginationModeWithCategory(){ 130 | swaggerConfluenceConfig.setPaginationMode("category"); 131 | assertEquals("Expected Pagination Mode \"CATEGORY_PAGES\"", 132 | PaginationMode.CATEGORY_PAGES, swaggerConfluenceConfig.getPaginationMode()); 133 | } 134 | 135 | @Test 136 | public void testStringPaginationModeWithIndividual(){ 137 | swaggerConfluenceConfig.setPaginationMode("individual"); 138 | assertEquals("Expected Pagination Mode \"INDIVIDUAL_PAGES\"", 139 | PaginationMode.INDIVIDUAL_PAGES, swaggerConfluenceConfig.getPaginationMode()); 140 | } 141 | 142 | @Test(expected = SwaggerConfluenceConfigurationException.class) 143 | public void testStringPaginationWithInvalidValueThrowsException(){ 144 | swaggerConfluenceConfig.setPaginationMode("invalid"); 145 | } 146 | 147 | @Test 148 | public void testNoDefaultPrefixExists(){ 149 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getPrefix()); 150 | } 151 | 152 | @Test 153 | public void testPrefixWithNoTrailingSpaceAutomaticallyAddsOne(){ 154 | swaggerConfluenceConfig.setPrefix("[P]"); 155 | assertEquals("Expected Prefix \"[P] \"", 156 | "[P] ", swaggerConfluenceConfig.getPrefix()); 157 | } 158 | 159 | @Test 160 | public void testPrefixWithTrailingSpaceDoesntAddAnotherOne(){ 161 | swaggerConfluenceConfig.setPrefix("[P] "); 162 | assertEquals("Expected Prefix \"[P] \"", 163 | "[P] ", swaggerConfluenceConfig.getPrefix()); 164 | } 165 | 166 | @Test 167 | public void testNoDefaultSpaceKeyExists(){ 168 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getSpaceKey()); 169 | } 170 | 171 | @Test 172 | public void testGetSetSpaceKey(){ 173 | swaggerConfluenceConfig.setSpaceKey("DOC"); 174 | assertEquals("Expected Space Key \"DOC\"", 175 | "DOC", swaggerConfluenceConfig.getSpaceKey()); 176 | } 177 | 178 | @Test 179 | public void testNoDefaultSwaggerSchemaExists(){ 180 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getSwaggerSchema()); 181 | } 182 | 183 | @Test 184 | public void testGetSetSwaggerSchema(){ 185 | swaggerConfluenceConfig.setSwaggerSchema("schema.yaml"); 186 | assertEquals("Expected Swagger Schema \"schema.yaml\"", 187 | "schema.yaml", swaggerConfluenceConfig.getSwaggerSchema()); 188 | } 189 | 190 | @Test 191 | public void testNoDefaultTitleExists(){ 192 | assertNull("No Default Should Be Set", swaggerConfluenceConfig.getSwaggerSchema()); 193 | } 194 | 195 | @Test 196 | public void testGetSetTitle(){ 197 | swaggerConfluenceConfig.setTitle("Test Schema"); 198 | assertEquals("Expected Title \"Test Schema\"", 199 | "Test Schema", swaggerConfluenceConfig.getTitle()); 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/resources/swagger-confluence-create-json-body-definitions-example.json: -------------------------------------------------------------------------------- 1 | {"type":"page","title":"3. Definitions","body":{"storage":{"value":"\n

Definitions<\/strong><\/h2>\n
\n
\n

Category<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

name<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

Order<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

complete<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

boolean<\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

petId<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

quantity<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int32)<\/p><\/td>\n<\/tr>\n

shipDate<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string(date-time)<\/p><\/td>\n<\/tr>\n

status<\/strong>
\noptional<\/em><\/p><\/td>\n

Order Status<\/p><\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

Pet<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

category<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

\n\nCategory\n<\/ac:link-body>\n<\/ac:link><\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

name<\/strong>
\nrequired<\/em><\/p><\/td>\n

Example<\/strong> : \"doggie\"<\/code><\/p><\/td>\n

string<\/p><\/td>\n<\/tr>\n

photoUrls<\/strong>
\nrequired<\/em><\/p><\/td>\n

<\/td>\n

< string > array<\/p><\/td>\n<\/tr>\n

status<\/strong>
\noptional<\/em><\/p><\/td>\n

pet status in the store<\/p><\/td>\n

string<\/p><\/td>\n<\/tr>\n

tags<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

< \n\nTag\n<\/ac:link-body>\n<\/ac:link> > array<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

Tag<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

name<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

User<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

email<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

firstName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

lastName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

password<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

phone<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

userStatus<\/strong>
\noptional<\/em><\/p><\/td>\n

User Status<\/p><\/td>\n

integer(int32)<\/p><\/td>\n<\/tr>\n

username<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n","representation":"storage"}},"ancestors":[{"id":1,"type":"page"}],"space":{"key":"DOC"}} -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/resources/swagger-confluence-update-json-body-definitions-example.json: -------------------------------------------------------------------------------- 1 | {"id":"1277959","type":"page","title":"3. Definitions","body":{"storage":{"value":"\n

Definitions<\/strong><\/h2>\n
\n
\n

Category<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

name<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

Order<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

complete<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

boolean<\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

petId<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

quantity<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int32)<\/p><\/td>\n<\/tr>\n

shipDate<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string(date-time)<\/p><\/td>\n<\/tr>\n

status<\/strong>
\noptional<\/em><\/p><\/td>\n

Order Status<\/p><\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

Pet<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

category<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

\n\nCategory\n<\/ac:link-body>\n<\/ac:link><\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

name<\/strong>
\nrequired<\/em><\/p><\/td>\n

Example<\/strong> : \"doggie\"<\/code><\/p><\/td>\n

string<\/p><\/td>\n<\/tr>\n

photoUrls<\/strong>
\nrequired<\/em><\/p><\/td>\n

<\/td>\n

< string > array<\/p><\/td>\n<\/tr>\n

status<\/strong>
\noptional<\/em><\/p><\/td>\n

pet status in the store<\/p><\/td>\n

string<\/p><\/td>\n<\/tr>\n

tags<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

< \n\nTag\n<\/ac:link-body>\n<\/ac:link> > array<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

Tag<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

name<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

\n

User<\/strong><\/h3>\n\n\n\n\n\n<\/colgroup>\n\n\n\n\n\n\n\n\n\n\n\n
Name<\/th>\nDescription<\/th>\nSchema<\/th>\n<\/tr>\n<\/thead>\n

email<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

firstName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

id<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

integer(int64)<\/p><\/td>\n<\/tr>\n

lastName<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

password<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

phone<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n

userStatus<\/strong>
\noptional<\/em><\/p><\/td>\n

User Status<\/p><\/td>\n

integer(int32)<\/p><\/td>\n<\/tr>\n

username<\/strong>
\noptional<\/em><\/p><\/td>\n

<\/td>\n

string<\/p><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n","representation":"storage"}},"ancestors":[{"id":1474805,"type":"page"}],"version":{"number":2},"space":{"key":"DOC"}} -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/resources/swagger-petstore-example.yaml: -------------------------------------------------------------------------------- 1 | swagger: "2.0" 2 | info: 3 | description: | 4 | This is a sample server Petstore server. 5 | 6 | [Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. 7 | 8 | For this sample, you can use the api key `special-key` to test the authorization filters 9 | version: "1.0.0" 10 | title: Swagger Petstore 11 | termsOfService: http://helloreverb.com/terms/ 12 | contact: 13 | name: apiteam@swagger.io 14 | license: 15 | name: Apache 2.0 16 | url: http://www.apache.org/licenses/LICENSE-2.0.html 17 | host: petstore.swagger.io 18 | basePath: /v2 19 | schemes: 20 | - http 21 | paths: 22 | /pets: 23 | post: 24 | tags: 25 | - pet 26 | summary: Add a new pet to the store 27 | description: "" 28 | operationId: addPet 29 | consumes: 30 | - application/json 31 | - application/xml 32 | produces: 33 | - application/json 34 | - application/xml 35 | parameters: 36 | - in: body 37 | name: body 38 | description: Pet object that needs to be added to the store 39 | required: false 40 | schema: 41 | $ref: "#/definitions/Pet" 42 | responses: 43 | "405": 44 | description: Invalid input 45 | security: 46 | - petstore_auth: 47 | - write_pets 48 | - read_pets 49 | put: 50 | tags: 51 | - pet 52 | summary: Update an existing pet 53 | description: "" 54 | operationId: updatePet 55 | consumes: 56 | - application/json 57 | - application/xml 58 | produces: 59 | - application/json 60 | - application/xml 61 | parameters: 62 | - in: body 63 | name: body 64 | description: Pet object that needs to be added to the store 65 | required: false 66 | schema: 67 | $ref: "#/definitions/Pet" 68 | responses: 69 | "405": 70 | description: Validation exception 71 | "404": 72 | description: Pet not found 73 | "400": 74 | description: Invalid ID supplied 75 | security: 76 | - petstore_auth: 77 | - write_pets 78 | - read_pets 79 | /pets/findByStatus: 80 | get: 81 | tags: 82 | - pet 83 | summary: Finds Pets by status 84 | description: Multiple status values can be provided with comma seperated strings 85 | operationId: findPetsByStatus 86 | produces: 87 | - application/json 88 | - application/xml 89 | parameters: 90 | - in: query 91 | name: status 92 | description: Status values that need to be considered for filter 93 | required: false 94 | type: array 95 | items: 96 | type: string 97 | collectionFormat: multi 98 | responses: 99 | "200": 100 | description: successful operation 101 | schema: 102 | type: array 103 | items: 104 | $ref: "#/definitions/Pet" 105 | "400": 106 | description: Invalid status value 107 | security: 108 | - petstore_auth: 109 | - write_pets 110 | - read_pets 111 | /pets/findByTags: 112 | get: 113 | tags: 114 | - pet 115 | summary: Finds Pets by tags 116 | description: Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. 117 | operationId: findPetsByTags 118 | produces: 119 | - application/json 120 | - application/xml 121 | parameters: 122 | - in: query 123 | name: tags 124 | description: Tags to filter by 125 | required: false 126 | type: array 127 | items: 128 | type: string 129 | collectionFormat: multi 130 | responses: 131 | "200": 132 | description: successful operation 133 | schema: 134 | type: array 135 | items: 136 | $ref: "#/definitions/Pet" 137 | "400": 138 | description: Invalid tag value 139 | security: 140 | - petstore_auth: 141 | - write_pets 142 | - read_pets 143 | /pets/{petId}: 144 | get: 145 | tags: 146 | - pet 147 | summary: Find pet by ID 148 | description: Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions 149 | operationId: getPetById 150 | produces: 151 | - application/json 152 | - application/xml 153 | parameters: 154 | - in: path 155 | name: petId 156 | description: ID of pet that needs to be fetched 157 | required: true 158 | type: integer 159 | format: int64 160 | responses: 161 | "404": 162 | description: Pet not found 163 | "200": 164 | description: successful operation 165 | schema: 166 | $ref: "#/definitions/Pet" 167 | "400": 168 | description: Invalid ID supplied 169 | security: 170 | - api_key: [] 171 | - petstore_auth: 172 | - write_pets 173 | - read_pets 174 | post: 175 | tags: 176 | - pet 177 | summary: Updates a pet in the store with form data 178 | description: "" 179 | operationId: updatePetWithForm 180 | consumes: 181 | - application/x-www-form-urlencoded 182 | produces: 183 | - application/json 184 | - application/xml 185 | parameters: 186 | - in: path 187 | name: petId 188 | description: ID of pet that needs to be updated 189 | required: true 190 | type: string 191 | - in: formData 192 | name: name 193 | description: Updated name of the pet 194 | required: true 195 | type: string 196 | - in: formData 197 | name: status 198 | description: Updated status of the pet 199 | required: true 200 | type: string 201 | responses: 202 | "405": 203 | description: Invalid input 204 | security: 205 | - petstore_auth: 206 | - write_pets 207 | - read_pets 208 | delete: 209 | tags: 210 | - pet 211 | summary: Deletes a pet 212 | description: "" 213 | operationId: deletePet 214 | produces: 215 | - application/json 216 | - application/xml 217 | parameters: 218 | - in: header 219 | name: api_key 220 | description: "" 221 | required: true 222 | type: string 223 | - in: path 224 | name: petId 225 | description: Pet id to delete 226 | required: true 227 | type: integer 228 | format: int64 229 | responses: 230 | "400": 231 | description: Invalid pet value 232 | security: 233 | - petstore_auth: 234 | - write_pets 235 | - read_pets 236 | /stores/order: 237 | post: 238 | tags: 239 | - store 240 | summary: Place an order for a pet 241 | description: "" 242 | operationId: placeOrder 243 | produces: 244 | - application/json 245 | - application/xml 246 | parameters: 247 | - in: body 248 | name: body 249 | description: order placed for purchasing the pet 250 | required: false 251 | schema: 252 | $ref: "#/definitions/Order" 253 | responses: 254 | "200": 255 | description: successful operation 256 | schema: 257 | $ref: "#/definitions/Order" 258 | "400": 259 | description: Invalid Order 260 | /stores/order/{orderId}: 261 | get: 262 | tags: 263 | - store 264 | summary: Find purchase order by ID 265 | description: For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions 266 | operationId: getOrderById 267 | produces: 268 | - application/json 269 | - application/xml 270 | parameters: 271 | - in: path 272 | name: orderId 273 | description: ID of pet that needs to be fetched 274 | required: true 275 | type: string 276 | responses: 277 | "404": 278 | description: Order not found 279 | "200": 280 | description: successful operation 281 | schema: 282 | $ref: "#/definitions/Order" 283 | "400": 284 | description: Invalid ID supplied 285 | delete: 286 | tags: 287 | - store 288 | summary: Delete purchase order by ID 289 | description: For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 290 | operationId: deleteOrder 291 | produces: 292 | - application/json 293 | - application/xml 294 | parameters: 295 | - in: path 296 | name: orderId 297 | description: ID of the order that needs to be deleted 298 | required: true 299 | type: string 300 | responses: 301 | "404": 302 | description: Order not found 303 | "400": 304 | description: Invalid ID supplied 305 | /users: 306 | post: 307 | tags: 308 | - user 309 | summary: Create user 310 | description: This can only be done by the logged in user. 311 | operationId: createUser 312 | produces: 313 | - application/json 314 | - application/xml 315 | parameters: 316 | - in: body 317 | name: body 318 | description: Created user object 319 | required: false 320 | schema: 321 | $ref: "#/definitions/User" 322 | responses: 323 | default: 324 | description: successful operation 325 | /users/createWithArray: 326 | post: 327 | tags: 328 | - user 329 | summary: Creates list of users with given input array 330 | description: "" 331 | operationId: createUsersWithArrayInput 332 | produces: 333 | - application/json 334 | - application/xml 335 | parameters: 336 | - in: body 337 | name: body 338 | description: List of user object 339 | required: false 340 | schema: 341 | type: array 342 | items: 343 | $ref: "#/definitions/User" 344 | responses: 345 | default: 346 | description: successful operation 347 | /users/createWithList: 348 | post: 349 | tags: 350 | - user 351 | summary: Creates list of users with given input array 352 | description: "" 353 | operationId: createUsersWithListInput 354 | produces: 355 | - application/json 356 | - application/xml 357 | parameters: 358 | - in: body 359 | name: body 360 | description: List of user object 361 | required: false 362 | schema: 363 | type: array 364 | items: 365 | $ref: "#/definitions/User" 366 | responses: 367 | default: 368 | description: successful operation 369 | /users/login: 370 | get: 371 | tags: 372 | - user 373 | summary: Logs user into the system 374 | description: "" 375 | operationId: loginUser 376 | produces: 377 | - application/json 378 | - application/xml 379 | parameters: 380 | - in: query 381 | name: username 382 | description: The user name for login 383 | required: false 384 | type: string 385 | - in: query 386 | name: password 387 | description: The password for login in clear text 388 | required: false 389 | type: string 390 | responses: 391 | "200": 392 | description: successful operation 393 | schema: 394 | type: string 395 | "400": 396 | description: Invalid username/password supplied 397 | /users/logout: 398 | get: 399 | tags: 400 | - user 401 | summary: Logs out current logged in user session 402 | description: "" 403 | operationId: logoutUser 404 | produces: 405 | - application/json 406 | - application/xml 407 | responses: 408 | default: 409 | description: successful operation 410 | /users/{username}: 411 | get: 412 | tags: 413 | - user 414 | summary: Get user by user name 415 | description: "" 416 | operationId: getUserByName 417 | produces: 418 | - application/json 419 | - application/xml 420 | parameters: 421 | - in: path 422 | name: username 423 | description: The name that needs to be fetched. Use user1 for testing. 424 | required: true 425 | type: string 426 | responses: 427 | "404": 428 | description: User not found 429 | "200": 430 | description: successful operation 431 | schema: 432 | $ref: "#/definitions/User" 433 | "400": 434 | description: Invalid username supplied 435 | put: 436 | tags: 437 | - user 438 | summary: Updated user 439 | description: This can only be done by the logged in user. 440 | operationId: updateUser 441 | produces: 442 | - application/json 443 | - application/xml 444 | parameters: 445 | - in: path 446 | name: username 447 | description: name that need to be deleted 448 | required: true 449 | type: string 450 | - in: body 451 | name: body 452 | description: Updated user object 453 | required: false 454 | schema: 455 | $ref: "#/definitions/User" 456 | responses: 457 | "404": 458 | description: User not found 459 | "400": 460 | description: Invalid user supplied 461 | delete: 462 | tags: 463 | - user 464 | summary: Delete user 465 | description: This can only be done by the logged in user. 466 | operationId: deleteUser 467 | produces: 468 | - application/json 469 | - application/xml 470 | parameters: 471 | - in: path 472 | name: username 473 | description: The name that needs to be deleted 474 | required: true 475 | type: string 476 | responses: 477 | "404": 478 | description: User not found 479 | "400": 480 | description: Invalid username supplied 481 | securityDefinitions: 482 | api_key: 483 | type: apiKey 484 | name: api_key 485 | in: header 486 | petstore_auth: 487 | type: oauth2 488 | authorizationUrl: http://petstore.swagger.io/api/oauth/dialog 489 | flow: implicit 490 | scopes: 491 | write_pets: modify pets in your account 492 | read_pets: read your pets 493 | definitions: 494 | User: 495 | type: object 496 | properties: 497 | id: 498 | type: integer 499 | format: int64 500 | username: 501 | type: string 502 | firstName: 503 | type: string 504 | lastName: 505 | type: string 506 | email: 507 | type: string 508 | password: 509 | type: string 510 | phone: 511 | type: string 512 | userStatus: 513 | type: integer 514 | format: int32 515 | description: User Status 516 | Category: 517 | type: object 518 | properties: 519 | id: 520 | type: integer 521 | format: int64 522 | name: 523 | type: string 524 | Pet: 525 | type: object 526 | required: 527 | - name 528 | - photoUrls 529 | properties: 530 | id: 531 | type: integer 532 | format: int64 533 | category: 534 | $ref: "#/definitions/Category" 535 | name: 536 | type: string 537 | example: doggie 538 | photoUrls: 539 | type: array 540 | items: 541 | type: string 542 | tags: 543 | type: array 544 | items: 545 | $ref: "#/definitions/Tag" 546 | status: 547 | type: string 548 | description: pet status in the store 549 | Tag: 550 | type: object 551 | properties: 552 | id: 553 | type: integer 554 | format: int64 555 | name: 556 | type: string 557 | Order: 558 | type: object 559 | properties: 560 | id: 561 | type: integer 562 | format: int64 563 | petId: 564 | type: integer 565 | format: int64 566 | quantity: 567 | type: integer 568 | format: int32 569 | shipDate: 570 | type: string 571 | format: date-time 572 | status: 573 | type: string 574 | description: Order Status 575 | complete: 576 | type: boolean 577 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/java/net/slkdev/swagger/confluence/service/impl/XHtmlToConfluenceServiceImplTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 Aaron Knight 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package net.slkdev.swagger.confluence.service.impl; 17 | 18 | import net.slkdev.swagger.confluence.config.SwaggerConfluenceConfig; 19 | import net.slkdev.swagger.confluence.constants.PaginationMode; 20 | import net.slkdev.swagger.confluence.service.XHtmlToConfluenceService; 21 | import org.apache.commons.codec.binary.Base64; 22 | import org.asciidoctor.internal.IOUtils; 23 | import org.junit.Before; 24 | import org.junit.Test; 25 | import org.junit.runner.RunWith; 26 | import org.mockito.ArgumentCaptor; 27 | import org.mockito.Mock; 28 | import org.mockito.runners.MockitoJUnitRunner; 29 | import org.springframework.http.*; 30 | import org.springframework.web.client.RestTemplate; 31 | 32 | import java.net.URI; 33 | import java.util.ArrayList; 34 | import java.util.Arrays; 35 | import java.util.List; 36 | 37 | import static org.junit.Assert.assertEquals; 38 | import static org.junit.Assert.assertNotNull; 39 | import static org.mockito.Matchers.any; 40 | import static org.mockito.Matchers.eq; 41 | import static org.mockito.Mockito.verify; 42 | import static org.mockito.Mockito.when; 43 | import static org.mockito.internal.verification.VerificationModeFactory.times; 44 | 45 | @RunWith(MockitoJUnitRunner.class) 46 | public class XHtmlToConfluenceServiceImplTest { 47 | 48 | private static final String GET_RESPONSE_FOUND = "{\"results\":[{\"id\":\"1277959\",\"type\":\"" + 49 | "page\",\"title\":\"Test\",\"version\":{\"number\":1},\"body\":{\"storage\":{\"value\":" + 50 | "\"\",\"representation\":\"storage\"}},\"ancestors\":[{\"id\":\"1474805\"}]}]}"; 51 | 52 | private static final String GET_RESPONSE_NOT_FOUND = "{\"results\":[]}"; 53 | 54 | private static final String GET_CHILDREN = "{\"page\":{\"results\":[{\"id\":\"1\",\"type\":\"" + 55 | "page\",\"status\":\"current\",\"title\":\"Test\",\"extensions\":{\"position\":\"none\"" + 56 | "}}]}}"; 57 | 58 | private static final String POST_RESPONSE = "{\"id\":\"1\"}"; 59 | 60 | private static final List CATEGORY_INDEXES = Arrays.asList(1, 6, 25, 31); 61 | 62 | @Mock 63 | private RestTemplate restTemplate; 64 | 65 | @Mock 66 | private ResponseEntity responseEntity; 67 | 68 | private XHtmlToConfluenceService xHtmlToConfluenceService; 69 | 70 | @Before 71 | public void setUp(){ 72 | xHtmlToConfluenceService = new XHtmlToConfluenceServiceImpl(restTemplate); 73 | } 74 | 75 | @Test 76 | public void testCreatePageWithPaginationModeSingleWithOrphanFailSafe(){ 77 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); 78 | swaggerConfluenceConfig.setAncestorId(null); 79 | 80 | final String xhtml = IOUtils.readFull( 81 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 82 | "/swagger-petstore-xhtml-example.html") 83 | ); 84 | 85 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), 86 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity, 87 | responseEntity); 88 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), 89 | any(HttpEntity.class), eq(String.class))).thenReturn(responseEntity); 90 | when(responseEntity.getBody()).thenReturn(GET_RESPONSE_NOT_FOUND, GET_RESPONSE_FOUND, 91 | POST_RESPONSE); 92 | 93 | final ArgumentCaptor httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); 94 | 95 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 96 | 97 | verify(restTemplate, times(2)).exchange(any(URI.class), eq(HttpMethod.GET), 98 | any(RequestEntity.class), eq(String.class)); 99 | verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.POST), 100 | httpEntityCaptor.capture(), eq(String.class)); 101 | 102 | final HttpEntity capturedHttpEntity = httpEntityCaptor.getValue(); 103 | 104 | final String expectedPostBody = IOUtils.readFull( 105 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 106 | "/swagger-confluence-create-json-body-example.json") 107 | ); 108 | 109 | assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity); 110 | assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); 111 | } 112 | 113 | @Test 114 | public void testUpdatePageWithPaginationModeSingleAndNoTableOfContents(){ 115 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); 116 | swaggerConfluenceConfig.setIncludeTableOfContentsOnSinglePage(false); 117 | 118 | final String xhtml = IOUtils.readFull( 119 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 120 | "/swagger-petstore-xhtml-example.html") 121 | ); 122 | 123 | final ResponseEntity postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK); 124 | 125 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), 126 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); 127 | when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND); 128 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), 129 | any(RequestEntity.class), eq(String.class))).thenReturn(postResponseEntity); 130 | 131 | final ArgumentCaptor httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); 132 | 133 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 134 | 135 | verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.GET), 136 | any(RequestEntity.class), eq(String.class)); 137 | verify(restTemplate).exchange(any(URI.class), eq(HttpMethod.PUT), 138 | httpEntityCaptor.capture(), eq(String.class)); 139 | 140 | final HttpEntity capturedHttpEntity = httpEntityCaptor.getValue(); 141 | 142 | final String expectedPostBody = IOUtils.readFull( 143 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 144 | "/swagger-confluence-update-json-body-example.json") 145 | ); 146 | 147 | assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity); 148 | assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); 149 | } 150 | 151 | @Test 152 | public void testCreatePageWithPaginationModeCategory(){ 153 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); 154 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.CATEGORY_PAGES); 155 | 156 | final String xhtml = IOUtils.readFull( 157 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 158 | "/swagger-petstore-xhtml-example.html") 159 | ); 160 | 161 | for(int i = 0; i < 5; i++) { 162 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), 163 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); 164 | when(responseEntity.getBody()).thenReturn(GET_RESPONSE_NOT_FOUND); 165 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), 166 | any(HttpEntity.class), eq(String.class))).thenReturn(responseEntity); 167 | when(responseEntity.getBody()).thenReturn(POST_RESPONSE); 168 | } 169 | 170 | final ArgumentCaptor httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); 171 | 172 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 173 | 174 | verify(restTemplate, times(5)).exchange(any(URI.class), eq(HttpMethod.GET), 175 | any(RequestEntity.class), eq(String.class)); 176 | verify(restTemplate, times(5)).exchange(any(URI.class), eq(HttpMethod.POST), 177 | httpEntityCaptor.capture(), eq(String.class)); 178 | 179 | final HttpEntity capturedHttpEntity = httpEntityCaptor.getAllValues().get(3); 180 | 181 | final String expectedPostBody = IOUtils.readFull( 182 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 183 | "/swagger-confluence-create-json-body-definitions-example.json") 184 | ); 185 | 186 | assertNotNull("Failed to Capture RequeestEntity for POST", capturedHttpEntity); 187 | // We'll do a full check on the last page versus a resource; not doing all of them as it 188 | // would be a pain to maintain, but this should give us a nod of confidence. 189 | assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); 190 | } 191 | 192 | @Test 193 | public void testUpdatePageWithPaginationModeCategory(){ 194 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); 195 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.CATEGORY_PAGES); 196 | 197 | final String xhtml = IOUtils.readFull( 198 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 199 | "/swagger-petstore-xhtml-example.html") 200 | ); 201 | 202 | final ResponseEntity postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK); 203 | 204 | for(int i = 0; i < 5; i++) { 205 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), 206 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); 207 | when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND); 208 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), 209 | any(RequestEntity.class), eq(String.class))).thenReturn(postResponseEntity); 210 | } 211 | 212 | final ArgumentCaptor httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); 213 | 214 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 215 | 216 | verify(restTemplate, times(5)).exchange(any(URI.class), eq(HttpMethod.GET), 217 | any(RequestEntity.class), eq(String.class)); 218 | verify(restTemplate, times(5)).exchange(any(URI.class), eq(HttpMethod.PUT), 219 | httpEntityCaptor.capture(), eq(String.class)); 220 | 221 | final HttpEntity capturedHttpEntity = httpEntityCaptor.getAllValues().get(3); 222 | 223 | final String expectedPostBody = IOUtils.readFull( 224 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 225 | "/swagger-confluence-update-json-body-definitions-example.json") 226 | ); 227 | 228 | assertNotNull("Failed to Capture RequeestEntity for POST", capturedHttpEntity); 229 | // We'll do a full check on the last page versus a resource; not doing all of them as it 230 | // would be a pain to maintain, but this should give us a nod of confidence. 231 | assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); 232 | } 233 | 234 | @Test 235 | public void testCreatePageWithPaginationModeIndividual(){ 236 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); 237 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.INDIVIDUAL_PAGES); 238 | 239 | final String xhtml = IOUtils.readFull( 240 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 241 | "/swagger-petstore-xhtml-example.html") 242 | ); 243 | 244 | for(int i = 0; i < 31; i++) { 245 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), 246 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); 247 | when(responseEntity.getBody()).thenReturn(GET_RESPONSE_NOT_FOUND); 248 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.POST), 249 | any(HttpEntity.class), eq(String.class))).thenReturn(responseEntity); 250 | when(responseEntity.getBody()).thenReturn(POST_RESPONSE); 251 | } 252 | 253 | final ArgumentCaptor httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); 254 | 255 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 256 | 257 | verify(restTemplate, times(34)).exchange(any(URI.class), eq(HttpMethod.GET), 258 | any(RequestEntity.class), eq(String.class)); 259 | verify(restTemplate, times(34)).exchange(any(URI.class), eq(HttpMethod.POST), 260 | httpEntityCaptor.capture(), eq(String.class)); 261 | 262 | final HttpEntity capturedHttpEntity = httpEntityCaptor.getAllValues().get(30); 263 | 264 | final String expectedPostBody = IOUtils.readFull( 265 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 266 | "/swagger-confluence-create-json-body-user-example.json") 267 | ); 268 | 269 | assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity); 270 | // We'll do a full check on the last page versus a resource; not doing all of them as it 271 | // would be a pain to maintain, but this should give us a nod of confidence. 272 | assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); 273 | } 274 | 275 | @Test 276 | public void testUpdatePageWithPaginationModeIndividual(){ 277 | final SwaggerConfluenceConfig swaggerConfluenceConfig = getTestSwaggerConfluenceConfig(); 278 | swaggerConfluenceConfig.setPaginationMode(PaginationMode.INDIVIDUAL_PAGES); 279 | 280 | final String xhtml = IOUtils.readFull( 281 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 282 | "/swagger-petstore-xhtml-example.html") 283 | ); 284 | 285 | final ResponseEntity postResponseEntity = new ResponseEntity<>(POST_RESPONSE, HttpStatus.OK); 286 | 287 | final List returnJson = new ArrayList<>(); 288 | 289 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.GET), 290 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); 291 | 292 | for(int i = 0; i < 34; i++) { 293 | if(i > 0) { 294 | returnJson.add(GET_RESPONSE_FOUND); 295 | } 296 | 297 | if(CATEGORY_INDEXES.contains(i)){ 298 | returnJson.add(GET_CHILDREN); 299 | } 300 | } 301 | 302 | final String[] returnJsonArray = new String[returnJson.size()]; 303 | returnJson.toArray(returnJsonArray); 304 | 305 | when(responseEntity.getBody()).thenReturn(GET_RESPONSE_FOUND, returnJsonArray); 306 | 307 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.DELETE), 308 | any(RequestEntity.class), eq(String.class))).thenReturn(responseEntity); 309 | when(responseEntity.getStatusCode()).thenReturn(HttpStatus.NO_CONTENT); 310 | 311 | when(restTemplate.exchange(any(URI.class), eq(HttpMethod.PUT), 312 | any(RequestEntity.class), eq(String.class))).thenReturn(postResponseEntity); 313 | 314 | final ArgumentCaptor httpEntityCaptor = ArgumentCaptor.forClass(HttpEntity.class); 315 | 316 | xHtmlToConfluenceService.postXHtmlToConfluence(swaggerConfluenceConfig, xhtml); 317 | 318 | verify(restTemplate, times(38)).exchange(any(URI.class), eq(HttpMethod.GET), 319 | any(RequestEntity.class), eq(String.class)); 320 | verify(restTemplate, times(34)).exchange(any(URI.class), eq(HttpMethod.PUT), 321 | httpEntityCaptor.capture(), eq(String.class)); 322 | 323 | final HttpEntity capturedHttpEntity = httpEntityCaptor.getAllValues().get(30); 324 | 325 | final String expectedPostBody = IOUtils.readFull( 326 | AsciiDocToXHtmlServiceImplTest.class.getResourceAsStream( 327 | "/swagger-confluence-update-json-body-user-example.json") 328 | ); 329 | 330 | assertNotNull("Failed to Capture RequestEntity for POST", capturedHttpEntity); 331 | // We'll do a full check on the last page versus a resource; not doing all of them as it 332 | // would be a pain to maintain, but this should give us a nod of confidence. 333 | assertEquals("Unexpected JSON Post Body", expectedPostBody, capturedHttpEntity.getBody()); 334 | } 335 | 336 | private SwaggerConfluenceConfig getTestSwaggerConfluenceConfig(){ 337 | final SwaggerConfluenceConfig swaggerConfluenceConfig = new SwaggerConfluenceConfig(); 338 | 339 | swaggerConfluenceConfig.setAuthentication(getTestAuthentication()); 340 | swaggerConfluenceConfig.setAncestorId(0); 341 | swaggerConfluenceConfig.setConfluenceRestApiUrl("https://localhost/confluence/rest/api/"); 342 | swaggerConfluenceConfig.setPrefix(""); 343 | swaggerConfluenceConfig.setSpaceKey("DOC"); 344 | swaggerConfluenceConfig.setTitle("Test"); 345 | 346 | return swaggerConfluenceConfig; 347 | } 348 | 349 | private String getTestAuthentication(){ 350 | final String plainCreds = "test:password"; 351 | final byte[] plainCredsBytes = plainCreds.getBytes(); 352 | final byte[] base64CredsBytes = Base64.encodeBase64(plainCredsBytes); 353 | return new String(base64CredsBytes); 354 | } 355 | 356 | } 357 | -------------------------------------------------------------------------------- /swagger-confluence-core/src/test/resources/swagger-petstore-asciidoc-example.adoc: -------------------------------------------------------------------------------- 1 | = Swagger Petstore 2 | 3 | 4 | [[_overview]] 5 | == Overview 6 | This is a sample server Petstore server. 7 | 8 | http://swagger.io[Learn about Swagger] or join the IRC channel `#swagger` on irc.freenode.net. 9 | 10 | For this sample, you can use the api key `special-key` to test the authorization filters 11 | 12 | 13 | === Version information 14 | [%hardbreaks] 15 | _Version_ : 1.0.0 16 | 17 | 18 | === Contact information 19 | [%hardbreaks] 20 | _Contact_ : apiteam@swagger.io 21 | 22 | 23 | === License information 24 | [%hardbreaks] 25 | _License_ : Apache 2.0 26 | _License URL_ : http://www.apache.org/licenses/LICENSE-2.0.html 27 | _Terms of service_ : http://helloreverb.com/terms/ 28 | 29 | 30 | === URI scheme 31 | [%hardbreaks] 32 | _Host_ : petstore.swagger.io 33 | _BasePath_ : /v2 34 | _Schemes_ : HTTP 35 | 36 | 37 | [[_paths]] 38 | == Paths 39 | 40 | [[_addpet]] 41 | === Add a new pet to the store 42 | .... 43 | POST /pets 44 | .... 45 | 46 | 47 | ==== Parameters 48 | 49 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 50 | |=== 51 | |Type|Name|Description|Schema|Default 52 | |*Body*|*body* + 53 | _optional_|Pet object that needs to be added to the store|<<_pet,Pet>>| 54 | |=== 55 | 56 | 57 | ==== Responses 58 | 59 | [options="header", cols=".^1,.^15,.^4"] 60 | |=== 61 | |HTTP Code|Description|Schema 62 | |*405*|Invalid input|No Content 63 | |=== 64 | 65 | 66 | ==== Consumes 67 | 68 | * `application/json` 69 | * `application/xml` 70 | 71 | 72 | ==== Produces 73 | 74 | * `application/json` 75 | * `application/xml` 76 | 77 | 78 | ==== Tags 79 | 80 | * pet 81 | 82 | 83 | ==== Security 84 | 85 | [options="header", cols=".^3,.^4,.^13"] 86 | |=== 87 | |Type|Name|Scopes 88 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 89 | |=== 90 | 91 | 92 | [[_updatepet]] 93 | === Update an existing pet 94 | .... 95 | PUT /pets 96 | .... 97 | 98 | 99 | ==== Parameters 100 | 101 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 102 | |=== 103 | |Type|Name|Description|Schema|Default 104 | |*Body*|*body* + 105 | _optional_|Pet object that needs to be added to the store|<<_pet,Pet>>| 106 | |=== 107 | 108 | 109 | ==== Responses 110 | 111 | [options="header", cols=".^1,.^15,.^4"] 112 | |=== 113 | |HTTP Code|Description|Schema 114 | |*400*|Invalid ID supplied|No Content 115 | |*404*|Pet not found|No Content 116 | |*405*|Validation exception|No Content 117 | |=== 118 | 119 | 120 | ==== Consumes 121 | 122 | * `application/json` 123 | * `application/xml` 124 | 125 | 126 | ==== Produces 127 | 128 | * `application/json` 129 | * `application/xml` 130 | 131 | 132 | ==== Tags 133 | 134 | * pet 135 | 136 | 137 | ==== Security 138 | 139 | [options="header", cols=".^3,.^4,.^13"] 140 | |=== 141 | |Type|Name|Scopes 142 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 143 | |=== 144 | 145 | 146 | [[_findpetsbystatus]] 147 | === Finds Pets by status 148 | .... 149 | GET /pets/findByStatus 150 | .... 151 | 152 | 153 | ==== Description 154 | Multiple status values can be provided with comma seperated strings 155 | 156 | 157 | ==== Parameters 158 | 159 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 160 | |=== 161 | |Type|Name|Description|Schema|Default 162 | |*Query*|*status* + 163 | _optional_|Status values that need to be considered for filter|< string > array(multi)| 164 | |=== 165 | 166 | 167 | ==== Responses 168 | 169 | [options="header", cols=".^1,.^15,.^4"] 170 | |=== 171 | |HTTP Code|Description|Schema 172 | |*200*|successful operation|< <<_pet,Pet>> > array 173 | |*400*|Invalid status value|No Content 174 | |=== 175 | 176 | 177 | ==== Produces 178 | 179 | * `application/json` 180 | * `application/xml` 181 | 182 | 183 | ==== Tags 184 | 185 | * pet 186 | 187 | 188 | ==== Security 189 | 190 | [options="header", cols=".^3,.^4,.^13"] 191 | |=== 192 | |Type|Name|Scopes 193 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 194 | |=== 195 | 196 | 197 | [[_findpetsbytags]] 198 | === Finds Pets by tags 199 | .... 200 | GET /pets/findByTags 201 | .... 202 | 203 | 204 | ==== Description 205 | Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. 206 | 207 | 208 | ==== Parameters 209 | 210 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 211 | |=== 212 | |Type|Name|Description|Schema|Default 213 | |*Query*|*tags* + 214 | _optional_|Tags to filter by|< string > array(multi)| 215 | |=== 216 | 217 | 218 | ==== Responses 219 | 220 | [options="header", cols=".^1,.^15,.^4"] 221 | |=== 222 | |HTTP Code|Description|Schema 223 | |*200*|successful operation|< <<_pet,Pet>> > array 224 | |*400*|Invalid tag value|No Content 225 | |=== 226 | 227 | 228 | ==== Produces 229 | 230 | * `application/json` 231 | * `application/xml` 232 | 233 | 234 | ==== Tags 235 | 236 | * pet 237 | 238 | 239 | ==== Security 240 | 241 | [options="header", cols=".^3,.^4,.^13"] 242 | |=== 243 | |Type|Name|Scopes 244 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 245 | |=== 246 | 247 | 248 | [[_updatepetwithform]] 249 | === Updates a pet in the store with form data 250 | .... 251 | POST /pets/{petId} 252 | .... 253 | 254 | 255 | ==== Parameters 256 | 257 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 258 | |=== 259 | |Type|Name|Description|Schema|Default 260 | |*Path*|*petId* + 261 | _required_|ID of pet that needs to be updated|string| 262 | |*FormData*|*name* + 263 | _required_|Updated name of the pet|string| 264 | |*FormData*|*status* + 265 | _required_|Updated status of the pet|string| 266 | |=== 267 | 268 | 269 | ==== Responses 270 | 271 | [options="header", cols=".^1,.^15,.^4"] 272 | |=== 273 | |HTTP Code|Description|Schema 274 | |*405*|Invalid input|No Content 275 | |=== 276 | 277 | 278 | ==== Consumes 279 | 280 | * `application/x-www-form-urlencoded` 281 | 282 | 283 | ==== Produces 284 | 285 | * `application/json` 286 | * `application/xml` 287 | 288 | 289 | ==== Tags 290 | 291 | * pet 292 | 293 | 294 | ==== Security 295 | 296 | [options="header", cols=".^3,.^4,.^13"] 297 | |=== 298 | |Type|Name|Scopes 299 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 300 | |=== 301 | 302 | 303 | [[_deletepet]] 304 | === Deletes a pet 305 | .... 306 | DELETE /pets/{petId} 307 | .... 308 | 309 | 310 | ==== Parameters 311 | 312 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 313 | |=== 314 | |Type|Name|Description|Schema|Default 315 | |*Header*|*api_key* + 316 | _required_||string| 317 | |*Path*|*petId* + 318 | _required_|Pet id to delete|integer(int64)| 319 | |=== 320 | 321 | 322 | ==== Responses 323 | 324 | [options="header", cols=".^1,.^15,.^4"] 325 | |=== 326 | |HTTP Code|Description|Schema 327 | |*400*|Invalid pet value|No Content 328 | |=== 329 | 330 | 331 | ==== Produces 332 | 333 | * `application/json` 334 | * `application/xml` 335 | 336 | 337 | ==== Tags 338 | 339 | * pet 340 | 341 | 342 | ==== Security 343 | 344 | [options="header", cols=".^3,.^4,.^13"] 345 | |=== 346 | |Type|Name|Scopes 347 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 348 | |=== 349 | 350 | 351 | [[_getpetbyid]] 352 | === Find pet by ID 353 | .... 354 | GET /pets/{petId} 355 | .... 356 | 357 | 358 | ==== Description 359 | Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions 360 | 361 | 362 | ==== Parameters 363 | 364 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 365 | |=== 366 | |Type|Name|Description|Schema|Default 367 | |*Path*|*petId* + 368 | _required_|ID of pet that needs to be fetched|integer(int64)| 369 | |=== 370 | 371 | 372 | ==== Responses 373 | 374 | [options="header", cols=".^1,.^15,.^4"] 375 | |=== 376 | |HTTP Code|Description|Schema 377 | |*200*|successful operation|<<_pet,Pet>> 378 | |*400*|Invalid ID supplied|No Content 379 | |*404*|Pet not found|No Content 380 | |=== 381 | 382 | 383 | ==== Produces 384 | 385 | * `application/json` 386 | * `application/xml` 387 | 388 | 389 | ==== Tags 390 | 391 | * pet 392 | 393 | 394 | ==== Security 395 | 396 | [options="header", cols=".^3,.^4,.^13"] 397 | |=== 398 | |Type|Name|Scopes 399 | |*apiKey*|*<<_api_key,api_key>>*| 400 | |*oauth2*|*<<_petstore_auth,petstore_auth>>*|write_pets,read_pets 401 | |=== 402 | 403 | 404 | [[_placeorder]] 405 | === Place an order for a pet 406 | .... 407 | POST /stores/order 408 | .... 409 | 410 | 411 | ==== Parameters 412 | 413 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 414 | |=== 415 | |Type|Name|Description|Schema|Default 416 | |*Body*|*body* + 417 | _optional_|order placed for purchasing the pet|<<_order,Order>>| 418 | |=== 419 | 420 | 421 | ==== Responses 422 | 423 | [options="header", cols=".^1,.^15,.^4"] 424 | |=== 425 | |HTTP Code|Description|Schema 426 | |*200*|successful operation|<<_order,Order>> 427 | |*400*|Invalid Order|No Content 428 | |=== 429 | 430 | 431 | ==== Produces 432 | 433 | * `application/json` 434 | * `application/xml` 435 | 436 | 437 | ==== Tags 438 | 439 | * store 440 | 441 | 442 | [[_deleteorder]] 443 | === Delete purchase order by ID 444 | .... 445 | DELETE /stores/order/{orderId} 446 | .... 447 | 448 | 449 | ==== Description 450 | For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors 451 | 452 | 453 | ==== Parameters 454 | 455 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 456 | |=== 457 | |Type|Name|Description|Schema|Default 458 | |*Path*|*orderId* + 459 | _required_|ID of the order that needs to be deleted|string| 460 | |=== 461 | 462 | 463 | ==== Responses 464 | 465 | [options="header", cols=".^1,.^15,.^4"] 466 | |=== 467 | |HTTP Code|Description|Schema 468 | |*400*|Invalid ID supplied|No Content 469 | |*404*|Order not found|No Content 470 | |=== 471 | 472 | 473 | ==== Produces 474 | 475 | * `application/json` 476 | * `application/xml` 477 | 478 | 479 | ==== Tags 480 | 481 | * store 482 | 483 | 484 | [[_getorderbyid]] 485 | === Find purchase order by ID 486 | .... 487 | GET /stores/order/{orderId} 488 | .... 489 | 490 | 491 | ==== Description 492 | For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions 493 | 494 | 495 | ==== Parameters 496 | 497 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 498 | |=== 499 | |Type|Name|Description|Schema|Default 500 | |*Path*|*orderId* + 501 | _required_|ID of pet that needs to be fetched|string| 502 | |=== 503 | 504 | 505 | ==== Responses 506 | 507 | [options="header", cols=".^1,.^15,.^4"] 508 | |=== 509 | |HTTP Code|Description|Schema 510 | |*200*|successful operation|<<_order,Order>> 511 | |*400*|Invalid ID supplied|No Content 512 | |*404*|Order not found|No Content 513 | |=== 514 | 515 | 516 | ==== Produces 517 | 518 | * `application/json` 519 | * `application/xml` 520 | 521 | 522 | ==== Tags 523 | 524 | * store 525 | 526 | 527 | [[_createuser]] 528 | === Create user 529 | .... 530 | POST /users 531 | .... 532 | 533 | 534 | ==== Description 535 | This can only be done by the logged in user. 536 | 537 | 538 | ==== Parameters 539 | 540 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 541 | |=== 542 | |Type|Name|Description|Schema|Default 543 | |*Body*|*body* + 544 | _optional_|Created user object|<<_user,User>>| 545 | |=== 546 | 547 | 548 | ==== Responses 549 | 550 | [options="header", cols=".^1,.^15,.^4"] 551 | |=== 552 | |HTTP Code|Description|Schema 553 | |*default*|successful operation|No Content 554 | |=== 555 | 556 | 557 | ==== Produces 558 | 559 | * `application/json` 560 | * `application/xml` 561 | 562 | 563 | ==== Tags 564 | 565 | * user 566 | 567 | 568 | [[_createuserswitharrayinput]] 569 | === Creates list of users with given input array 570 | .... 571 | POST /users/createWithArray 572 | .... 573 | 574 | 575 | ==== Parameters 576 | 577 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 578 | |=== 579 | |Type|Name|Description|Schema|Default 580 | |*Body*|*body* + 581 | _optional_|List of user object|< <<_user,User>> > array| 582 | |=== 583 | 584 | 585 | ==== Responses 586 | 587 | [options="header", cols=".^1,.^15,.^4"] 588 | |=== 589 | |HTTP Code|Description|Schema 590 | |*default*|successful operation|No Content 591 | |=== 592 | 593 | 594 | ==== Produces 595 | 596 | * `application/json` 597 | * `application/xml` 598 | 599 | 600 | ==== Tags 601 | 602 | * user 603 | 604 | 605 | [[_createuserswithlistinput]] 606 | === Creates list of users with given input array 607 | .... 608 | POST /users/createWithList 609 | .... 610 | 611 | 612 | ==== Parameters 613 | 614 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 615 | |=== 616 | |Type|Name|Description|Schema|Default 617 | |*Body*|*body* + 618 | _optional_|List of user object|< <<_user,User>> > array| 619 | |=== 620 | 621 | 622 | ==== Responses 623 | 624 | [options="header", cols=".^1,.^15,.^4"] 625 | |=== 626 | |HTTP Code|Description|Schema 627 | |*default*|successful operation|No Content 628 | |=== 629 | 630 | 631 | ==== Produces 632 | 633 | * `application/json` 634 | * `application/xml` 635 | 636 | 637 | ==== Tags 638 | 639 | * user 640 | 641 | 642 | [[_loginuser]] 643 | === Logs user into the system 644 | .... 645 | GET /users/login 646 | .... 647 | 648 | 649 | ==== Parameters 650 | 651 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 652 | |=== 653 | |Type|Name|Description|Schema|Default 654 | |*Query*|*password* + 655 | _optional_|The password for login in clear text|string| 656 | |*Query*|*username* + 657 | _optional_|The user name for login|string| 658 | |=== 659 | 660 | 661 | ==== Responses 662 | 663 | [options="header", cols=".^1,.^15,.^4"] 664 | |=== 665 | |HTTP Code|Description|Schema 666 | |*200*|successful operation|string 667 | |*400*|Invalid username/password supplied|No Content 668 | |=== 669 | 670 | 671 | ==== Produces 672 | 673 | * `application/json` 674 | * `application/xml` 675 | 676 | 677 | ==== Tags 678 | 679 | * user 680 | 681 | 682 | [[_logoutuser]] 683 | === Logs out current logged in user session 684 | .... 685 | GET /users/logout 686 | .... 687 | 688 | 689 | ==== Responses 690 | 691 | [options="header", cols=".^1,.^15,.^4"] 692 | |=== 693 | |HTTP Code|Description|Schema 694 | |*default*|successful operation|No Content 695 | |=== 696 | 697 | 698 | ==== Produces 699 | 700 | * `application/json` 701 | * `application/xml` 702 | 703 | 704 | ==== Tags 705 | 706 | * user 707 | 708 | 709 | [[_updateuser]] 710 | === Updated user 711 | .... 712 | PUT /users/{username} 713 | .... 714 | 715 | 716 | ==== Description 717 | This can only be done by the logged in user. 718 | 719 | 720 | ==== Parameters 721 | 722 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 723 | |=== 724 | |Type|Name|Description|Schema|Default 725 | |*Path*|*username* + 726 | _required_|name that need to be deleted|string| 727 | |*Body*|*body* + 728 | _optional_|Updated user object|<<_user,User>>| 729 | |=== 730 | 731 | 732 | ==== Responses 733 | 734 | [options="header", cols=".^1,.^15,.^4"] 735 | |=== 736 | |HTTP Code|Description|Schema 737 | |*400*|Invalid user supplied|No Content 738 | |*404*|User not found|No Content 739 | |=== 740 | 741 | 742 | ==== Produces 743 | 744 | * `application/json` 745 | * `application/xml` 746 | 747 | 748 | ==== Tags 749 | 750 | * user 751 | 752 | 753 | [[_deleteuser]] 754 | === Delete user 755 | .... 756 | DELETE /users/{username} 757 | .... 758 | 759 | 760 | ==== Description 761 | This can only be done by the logged in user. 762 | 763 | 764 | ==== Parameters 765 | 766 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 767 | |=== 768 | |Type|Name|Description|Schema|Default 769 | |*Path*|*username* + 770 | _required_|The name that needs to be deleted|string| 771 | |=== 772 | 773 | 774 | ==== Responses 775 | 776 | [options="header", cols=".^1,.^15,.^4"] 777 | |=== 778 | |HTTP Code|Description|Schema 779 | |*400*|Invalid username supplied|No Content 780 | |*404*|User not found|No Content 781 | |=== 782 | 783 | 784 | ==== Produces 785 | 786 | * `application/json` 787 | * `application/xml` 788 | 789 | 790 | ==== Tags 791 | 792 | * user 793 | 794 | 795 | [[_getuserbyname]] 796 | === Get user by user name 797 | .... 798 | GET /users/{username} 799 | .... 800 | 801 | 802 | ==== Parameters 803 | 804 | [options="header", cols=".^1,.^3,.^10,.^4,.^2"] 805 | |=== 806 | |Type|Name|Description|Schema|Default 807 | |*Path*|*username* + 808 | _required_|The name that needs to be fetched. Use user1 for testing.|string| 809 | |=== 810 | 811 | 812 | ==== Responses 813 | 814 | [options="header", cols=".^1,.^15,.^4"] 815 | |=== 816 | |HTTP Code|Description|Schema 817 | |*200*|successful operation|<<_user,User>> 818 | |*400*|Invalid username supplied|No Content 819 | |*404*|User not found|No Content 820 | |=== 821 | 822 | 823 | ==== Produces 824 | 825 | * `application/json` 826 | * `application/xml` 827 | 828 | 829 | ==== Tags 830 | 831 | * user 832 | 833 | 834 | [[_definitions]] 835 | == Definitions 836 | 837 | [[_category]] 838 | === Category 839 | 840 | [options="header", cols=".^3,.^11,.^4"] 841 | |=== 842 | |Name|Description|Schema 843 | |*id* + 844 | _optional_||integer(int64) 845 | |*name* + 846 | _optional_||string 847 | |=== 848 | 849 | 850 | [[_order]] 851 | === Order 852 | 853 | [options="header", cols=".^3,.^11,.^4"] 854 | |=== 855 | |Name|Description|Schema 856 | |*complete* + 857 | _optional_||boolean 858 | |*id* + 859 | _optional_||integer(int64) 860 | |*petId* + 861 | _optional_||integer(int64) 862 | |*quantity* + 863 | _optional_||integer(int32) 864 | |*shipDate* + 865 | _optional_||string(date-time) 866 | |*status* + 867 | _optional_|Order Status|string 868 | |=== 869 | 870 | 871 | [[_pet]] 872 | === Pet 873 | 874 | [options="header", cols=".^3,.^11,.^4"] 875 | |=== 876 | |Name|Description|Schema 877 | |*category* + 878 | _optional_||<<_category,Category>> 879 | |*id* + 880 | _optional_||integer(int64) 881 | |*name* + 882 | _required_|*Example* : `"doggie"`|string 883 | |*photoUrls* + 884 | _required_||< string > array 885 | |*status* + 886 | _optional_|pet status in the store|string 887 | |*tags* + 888 | _optional_||< <<_tag,Tag>> > array 889 | |=== 890 | 891 | 892 | [[_tag]] 893 | === Tag 894 | 895 | [options="header", cols=".^3,.^11,.^4"] 896 | |=== 897 | |Name|Description|Schema 898 | |*id* + 899 | _optional_||integer(int64) 900 | |*name* + 901 | _optional_||string 902 | |=== 903 | 904 | 905 | [[_user]] 906 | === User 907 | 908 | [options="header", cols=".^3,.^11,.^4"] 909 | |=== 910 | |Name|Description|Schema 911 | |*email* + 912 | _optional_||string 913 | |*firstName* + 914 | _optional_||string 915 | |*id* + 916 | _optional_||integer(int64) 917 | |*lastName* + 918 | _optional_||string 919 | |*password* + 920 | _optional_||string 921 | |*phone* + 922 | _optional_||string 923 | |*userStatus* + 924 | _optional_|User Status|integer(int32) 925 | |*username* + 926 | _optional_||string 927 | |=== 928 | 929 | 930 | [[_securityscheme]] 931 | == Security 932 | 933 | [[_api_key]] 934 | === api_key 935 | [%hardbreaks] 936 | _Type_ : apiKey 937 | _Name_ : api_key 938 | _In_ : HEADER 939 | 940 | 941 | [[_petstore_auth]] 942 | === petstore_auth 943 | [%hardbreaks] 944 | _Type_ : oauth2 945 | _Flow_ : implicit 946 | _Token URL_ : http://petstore.swagger.io/api/oauth/dialog 947 | 948 | 949 | [options="header", cols=".^3,.^17"] 950 | |=== 951 | |Name|Description 952 | |write_pets|modify pets in your account 953 | |read_pets|read your pets 954 | |=== 955 | --------------------------------------------------------------------------------