From 194efab1f6062843bcf50deeca51c72e90d8edc2 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Fri, 4 Mar 2016 12:14:37 +0100 Subject: [PATCH 1/7] Added a DiffUtils class which can be used to assert that the content of the generated files are not different to the content of the expected files. --- .../Swagger2MarkupConverterTest.java | 68 +++---- .../swagger2markup/assertions/DiffAssert.java | 20 +- .../assertions/DiffAssertions.java | 2 +- .../swagger2markup/assertions/DiffUtils.java | 48 +++++ .../results/asciidoc/default/definitions.adoc | 48 ++--- .../results/asciidoc/default/paths.adoc | 172 +++++++++--------- 6 files changed, 202 insertions(+), 156 deletions(-) create mode 100644 src/test/java/io/github/robwin/swagger2markup/assertions/DiffUtils.java diff --git a/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java index 09857ef2..37c2bdec 100644 --- a/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java @@ -20,7 +20,7 @@ import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.Sets; import io.github.robwin.markup.builder.MarkupLanguage; -import io.github.robwin.swagger2markup.assertions.DiffAssertions; +import io.github.robwin.swagger2markup.assertions.DiffUtils; import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; import io.github.robwin.swagger2markup.extension.Swagger2MarkupExtensionRegistry; import io.github.robwin.swagger2markup.extension.repository.DynamicDefinitionsContentExtension; @@ -67,8 +67,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); } @@ -94,7 +94,9 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( + asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc")))) .contains("==== HTTP request", "==== HTTP response", "==== Curl request", "===== curl-request"); } @@ -116,7 +118,9 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( + asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); String orderExample = "----\n" + "{\n" + " \"id\" : 99,\n" + @@ -176,7 +180,7 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); + String[] files = outputDirectory.toFile().list(); String petGeneratedExample = "----\n" + "{\n" + " \"tags\" : [ {\n" + @@ -284,16 +288,12 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); - Path actual = outputDirectory.resolve("overview.adoc"); - Path expected = Paths.get(Swagger2MarkupConverterTest.class.getResource("/results/asciidoc/default/overview.adoc").toURI()); - - DiffAssertions.assertThat(actual) - .isEqualTo(expected,"testSwagger2AsciiDocConversion.html"); - + Path expectedFilesDirectory = Paths.get(Swagger2MarkupConverterTest.class.getResource("/results/asciidoc/default").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); } @Test @@ -334,8 +334,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); } @@ -379,8 +379,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); } @@ -396,8 +396,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")))) @@ -416,8 +416,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")))) @@ -441,8 +441,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.md", "overview.md", "paths.md", "security.md")); } @@ -464,8 +464,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(4).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( asList("definitions.md", "overview.md", "paths.md", "security.md")); } @@ -484,8 +484,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(5).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(5).containsAll( asList("definitions", "definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); Path definitionsDirectory = outputDirectory.resolve("definitions"); @@ -509,8 +509,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(5).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(5).containsAll( asList("operations", "definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); Path pathsDirectory = outputDirectory.resolve("operations"); @@ -536,8 +536,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); //Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(5).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(5).containsAll( asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); Path definitionsDirectory = outputDirectory.resolve("definitions"); @@ -564,8 +564,8 @@ public class Swagger2MarkupConverterTest { .intoFolder(outputDirectory); // Then - String[] directories = outputDirectory.toFile().list(); - assertThat(directories).hasSize(5).containsAll( + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(5).containsAll( asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); Path definitionsDirectory = outputDirectory.resolve("definitions"); verifyMarkdownContainsFieldsInTables( diff --git a/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssert.java b/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssert.java index 6ccf7402..ccdc477a 100644 --- a/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssert.java +++ b/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssert.java @@ -1,6 +1,6 @@ /* * - * Copyright 2015 Robert Winkler + * Copyright 2016 Robert Winkler * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; -import java.nio.file.Paths; import java.util.LinkedList; import static org.assertj.core.api.Assertions.assertThat; @@ -43,17 +42,17 @@ public class DiffAssert extends AbstractAssert{ * Verifies that the content of the actual File is equal to the given one. * * @param expected the given value to compare the actual value to. - * @param reportName the name of the report which should be generated if the files differ. + * @param reportPath the path to the report which should be generated if the files differ. * @return {@code this} assertion object. * @throws AssertionError if the actual value is not equal to the given one or if the actual value is {@code null}.. */ - public DiffAssert isEqualTo(Path expected, String reportName) { + public DiffAssert isEqualTo(Path expected, Path reportPath) { LinkedList diffs = diff(actual, expected); boolean allDiffsAreEqual = assertThatAllDiffsAreEqual(diffs); if(!allDiffsAreEqual){ - writeHtmlReport(reportName, diffs); + writeHtmlReport(reportPath, diffs); } - assertThat(allDiffsAreEqual).as("The content of the files differ. Check the HTML report for more details.").isTrue(); + assertThat(allDiffsAreEqual).as("The content of the following files differ. Actual: %s, Expected %s. Check the HTML report for more details: %s", actual.toAbsolutePath(), expected.toAbsolutePath(), reportPath.toAbsolutePath()).isTrue(); return myself; } @@ -75,16 +74,15 @@ public class DiffAssert extends AbstractAssert{ } } - private static void writeHtmlReport(String reportName, LinkedList diffs){ + private static void writeHtmlReport(Path reportPath, LinkedList diffs){ DiffMatchPatch differ = new DiffMatchPatch(); - String reportFolder = "build/diff-report"; try { - Files.createDirectories(Paths.get(reportFolder)); - try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(reportFolder, reportName), Charset.forName("UTF-8"))) { + Files.createDirectories(reportPath.getParent()); + try (BufferedWriter writer = Files.newBufferedWriter(reportPath, Charset.forName("UTF-8"))) { writer.write(differ.diff_prettyHtml(diffs)); } } catch (IOException e) { - throw new RuntimeException(String.format("Failed to write report into folder %s", reportFolder), e); + throw new RuntimeException(String.format("Failed to write report %s", reportPath.toAbsolutePath()), e); } } } diff --git a/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssertions.java b/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssertions.java index 47370095..4ac70e52 100644 --- a/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssertions.java +++ b/src/test/java/io/github/robwin/swagger2markup/assertions/DiffAssertions.java @@ -1,6 +1,6 @@ /* * - * Copyright 2015 Robert Winkler + * Copyright 2016 Robert Winkler * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/src/test/java/io/github/robwin/swagger2markup/assertions/DiffUtils.java b/src/test/java/io/github/robwin/swagger2markup/assertions/DiffUtils.java new file mode 100644 index 00000000..281b83c0 --- /dev/null +++ b/src/test/java/io/github/robwin/swagger2markup/assertions/DiffUtils.java @@ -0,0 +1,48 @@ +/* + * + * Copyright 2016 Robert Winkler + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + * + * + */ +package io.github.robwin.swagger2markup.assertions; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; +import java.nio.file.DirectoryStream; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +public class DiffUtils { + + private static final Logger LOGGER = LoggerFactory.getLogger(DiffUtils.class); + + public static void assertThatAllFilesAreEqual(Path actualDirectory, Path expectedDirectory, String reportName) { + Path reportPath = Paths.get("build/diff-report/", reportName); + try { + try (DirectoryStream directoryStream = Files.newDirectoryStream(actualDirectory)) { + for (Path actualFile : directoryStream) { + Path expectedFile = expectedDirectory.resolve(actualFile.getFileName()); + LOGGER.info("Diffing file {} with {}", actualFile, expectedFile); + DiffAssertions.assertThat(actualFile).isEqualTo(expectedFile, reportPath); + } + } + } catch (IOException e) { + throw new RuntimeException("Failed to assert that all files are equal", e); + } + } +} diff --git a/src/test/resources/results/asciidoc/default/definitions.adoc b/src/test/resources/results/asciidoc/default/definitions.adoc index a504f8aa..e8b03ced 100644 --- a/src/test/resources/results/asciidoc/default/definitions.adoc +++ b/src/test/resources/results/asciidoc/default/definitions.adoc @@ -7,8 +7,8 @@ [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] |=== |Name|Description|Required|Schema|Default|Example -|id||false|integer(int64)||0 -|name||false|string||string +|id||false|integer(int64)|| +|name||false|string|| |=== @@ -17,12 +17,12 @@ [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] |=== |Name|Description|Required|Schema|Default|Example -|complete||false|boolean||true -|id||false|integer(int64)||0 -|petId||false|integer(int64)||0 -|quantity||false|integer(int32)||0 -|shipDate||false|string(date-time)||string -|status|Order Status|false|string||string +|complete||false|boolean|| +|id||false|integer(int64)|| +|petId||false|integer(int64)|| +|quantity||false|integer(int32)|| +|shipDate||false|string(date-time)|| +|status|Order Status|false|string|| |=== @@ -31,12 +31,12 @@ [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] |=== |Name|Description|Required|Schema|Default|Example -|category||false|<<_category,Category>>||<<_category>> -|id||false|integer(int64)||0 -|name||true|string||doggie -|photoUrls||true|string array||[ string ] -|status|pet status in the store|false|string||string -|tags||false|<<_tag,Tag>> array||[ <<_tag>> ] +|category||false|<<_category,Category>>|| +|id||false|integer(int64)|| +|name||true|string||"doggie" +|photoUrls||true|string array|| +|status|pet status in the store|false|string|| +|tags||false|<<_tag,Tag>> array|| |=== @@ -45,8 +45,8 @@ [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] |=== |Name|Description|Required|Schema|Default|Example -|id||false|integer(int64)||0 -|name||false|string||string +|id||false|integer(int64)|| +|name||false|string|| |=== @@ -55,14 +55,14 @@ [options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] |=== |Name|Description|Required|Schema|Default|Example -|email||false|string||string -|firstName||false|string||string -|id||false|integer(int64)||0 -|lastName||false|string||string -|password||false|string||string -|phone||false|string||string -|userStatus|User Status|false|integer(int32)||0 -|username||false|string||string +|email||false|string|| +|firstName||false|string|| +|id||false|integer(int64)|| +|lastName||false|string|| +|password||false|string|| +|phone||false|string|| +|userStatus|User Status|false|integer(int32)|| +|username||false|string|| |=== diff --git a/src/test/resources/results/asciidoc/default/paths.adoc b/src/test/resources/results/asciidoc/default/paths.adoc index c8522dd4..99072ee0 100644 --- a/src/test/resources/results/asciidoc/default/paths.adoc +++ b/src/test/resources/results/asciidoc/default/paths.adoc @@ -204,51 +204,6 @@ Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 |=== -=== Deletes a pet ----- -DELETE /pets/{petId} ----- - - -==== Parameters - -[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] -|=== -|Type|Name|Description|Required|Schema|Default -|Header|api_key||true|string| -|Path|petId|Pet id to delete|true|integer(int64)| -|=== - - -==== Responses - -[options="header", cols=".^1h,.^3,.^3,.^1"] -|=== -|HTTP Code|Description|Headers|Schema -|400|Invalid pet value|No Content -|=== - - -==== Produces - -* application/json -* application/xml - - -==== Tags - -* pet - - -==== Security - -[options="header", cols=".^1,.^1h,.^6"] -|=== -|Type|Name|Scopes -|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets -|=== - - === Updates a pet in the store with form data ---- POST /pets/{petId} @@ -300,6 +255,51 @@ POST /pets/{petId} |=== +=== Deletes a pet +---- +DELETE /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Header|api_key||true|string| +|Path|petId|Pet id to delete|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid pet value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + === Find pet by ID ---- GET /pets/{petId} @@ -644,47 +644,6 @@ GET /users/logout * user -=== Delete user ----- -DELETE /users/{username} ----- - - -==== Description -[%hardbreaks] -This can only be done by the logged in user. - - -==== Parameters - -[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] -|=== -|Type|Name|Description|Required|Schema|Default -|Path|username|The name that needs to be deleted|true|string| -|=== - - -==== Responses - -[options="header", cols=".^1h,.^3,.^3,.^1"] -|=== -|HTTP Code|Description|Headers|Schema -|400|Invalid username supplied|No Content -|404|User not found|No Content -|=== - - -==== Produces - -* application/json -* application/xml - - -==== Tags - -* user - - === Updated user ---- PUT /users/{username} @@ -727,6 +686,47 @@ This can only be done by the logged in user. * user +=== Delete user +---- +DELETE /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + === Get user by user name ---- GET /users/{username} From 52c1780f7929b05a14e8bd7e896d7753c5f62139 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Fri, 4 Mar 2016 13:20:56 +0100 Subject: [PATCH 2/7] AS_IS ordering of path operations does not work yet, because of https://github.com/swagger-api/swagger-core/issues/1696. New default value is NATURAL. --- .../builder/document/PathsDocument.java | 2 +- .../swagger2markup/config/default.properties | 2 +- .../results/asciidoc/default/paths.adoc | 246 +++++++++--------- 3 files changed, 125 insertions(+), 125 deletions(-) diff --git a/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java b/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java index 8ec5454b..84c26b92 100644 --- a/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java +++ b/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java @@ -157,7 +157,7 @@ public class PathsDocument extends MarkupDocument { if (paths != null) { for (Map.Entry path : paths.entrySet()) { - Map operations = path.getValue().getOperationMap(); + Map operations = path.getValue().getOperationMap(); // TODO AS_IS does not work because of https://github.com/swagger-api/swagger-core/issues/1696 if (operations != null) { for (Map.Entry operation : operations.entrySet()) { diff --git a/src/main/resources/io/github/robwin/swagger2markup/config/default.properties b/src/main/resources/io/github/robwin/swagger2markup/config/default.properties index cc0a9b16..174b71c1 100644 --- a/src/main/resources/io/github/robwin/swagger2markup/config/default.properties +++ b/src/main/resources/io/github/robwin/swagger2markup/config/default.properties @@ -19,7 +19,7 @@ swagger2markup.securityDocument=security swagger2markup.separatedOperationsFolder=operations swagger2markup.separatedDefinitionsFolder=definitions swagger2markup.tagOrderBy=NATURAL -swagger2markup.operationOrderBy=AS_IS +swagger2markup.operationOrderBy=NATURAL swagger2markup.definitionOrderBy=NATURAL swagger2markup.parameterOrderBy=NATURAL swagger2markup.propertyOrderBy=NATURAL diff --git a/src/test/resources/results/asciidoc/default/paths.adoc b/src/test/resources/results/asciidoc/default/paths.adoc index 99072ee0..f8bcd46e 100644 --- a/src/test/resources/results/asciidoc/default/paths.adoc +++ b/src/test/resources/results/asciidoc/default/paths.adoc @@ -255,51 +255,6 @@ POST /pets/{petId} |=== -=== Deletes a pet ----- -DELETE /pets/{petId} ----- - - -==== Parameters - -[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] -|=== -|Type|Name|Description|Required|Schema|Default -|Header|api_key||true|string| -|Path|petId|Pet id to delete|true|integer(int64)| -|=== - - -==== Responses - -[options="header", cols=".^1h,.^3,.^3,.^1"] -|=== -|HTTP Code|Description|Headers|Schema -|400|Invalid pet value|No Content -|=== - - -==== Produces - -* application/json -* application/xml - - -==== Tags - -* pet - - -==== Security - -[options="header", cols=".^1,.^1h,.^6"] -|=== -|Type|Name|Scopes -|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets -|=== - - === Find pet by ID ---- GET /pets/{petId} @@ -352,6 +307,51 @@ Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error cond |=== +=== Deletes a pet +---- +DELETE /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Header|api_key||true|string| +|Path|petId|Pet id to delete|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid pet value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + === Place an order for a pet ---- POST /stores/order @@ -388,47 +388,6 @@ POST /stores/order * store -=== Delete purchase order by ID ----- -DELETE /stores/order/{orderId} ----- - - -==== Description -[%hardbreaks] -For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors - - -==== Parameters - -[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] -|=== -|Type|Name|Description|Required|Schema|Default -|Path|orderId|ID of the order that needs to be deleted|true|string| -|=== - - -==== Responses - -[options="header", cols=".^1h,.^3,.^3,.^1"] -|=== -|HTTP Code|Description|Headers|Schema -|400|Invalid ID supplied|No Content -|404|Order not found|No Content -|=== - - -==== Produces - -* application/json -* application/xml - - -==== Tags - -* store - - === Find purchase order by ID ---- GET /stores/order/{orderId} @@ -471,6 +430,47 @@ For valid response try integer IDs with value <= 5 or > 10. Other values will ge * store +=== Delete purchase order by ID +---- +DELETE /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of the order that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + === Create user ---- POST /users @@ -644,6 +644,43 @@ GET /users/logout * user +=== Get user by user name +---- +GET /users/{username} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_user,User>> +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + === Updated user ---- PUT /users/{username} @@ -727,41 +764,4 @@ This can only be done by the logged in user. * user -=== Get user by user name ----- -GET /users/{username} ----- - - -==== Parameters - -[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] -|=== -|Type|Name|Description|Required|Schema|Default -|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string| -|=== - - -==== Responses - -[options="header", cols=".^1h,.^3,.^3,.^1"] -|=== -|HTTP Code|Description|Headers|Schema -|200|successful operation|<<_user,User>> -|400|Invalid username supplied|No Content -|404|User not found|No Content -|=== - - -==== Produces - -* application/json -* application/xml - - -==== Tags - -* user - - From 4ec11f835954fc494b7c6f15cdd623673c3f3ca3 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Fri, 4 Mar 2016 13:30:03 +0100 Subject: [PATCH 3/7] Separated AsciiDocConverterTest into three different files. --- ...erTest.java => AsciidocConverterTest.java} | 378 +++--------------- .../swagger2markup/GeneralConverterTest.java | 90 +++++ .../swagger2markup/MarkdownConverterTest.java | 260 ++++++++++++ 3 files changed, 400 insertions(+), 328 deletions(-) rename src/test/java/io/github/robwin/swagger2markup/{Swagger2MarkupConverterTest.java => AsciidocConverterTest.java} (59%) create mode 100644 src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java create mode 100644 src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java diff --git a/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java similarity index 59% rename from src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java rename to src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java index 37c2bdec..69841605 100644 --- a/src/test/java/io/github/robwin/swagger2markup/Swagger2MarkupConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java @@ -15,11 +15,6 @@ */ package io.github.robwin.swagger2markup; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import io.github.robwin.markup.builder.MarkupLanguage; import io.github.robwin.swagger2markup.assertions.DiffUtils; import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; import io.github.robwin.swagger2markup.extension.Swagger2MarkupExtensionRegistry; @@ -33,30 +28,56 @@ import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.File; import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; -import java.util.Map; -import java.util.Set; import static java.util.Arrays.asList; -import static org.assertj.core.api.Assertions.fail; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; import static org.assertj.core.api.BDDAssertions.assertThat; -public class Swagger2MarkupConverterTest { +public class AsciidocConverterTest { - private static final Logger LOG = LoggerFactory.getLogger(Swagger2MarkupConverterTest.class); + private static final Logger LOG = LoggerFactory.getLogger(AsciidocConverterTest.class); @Test - public void testSwagger2AsciiDocConversionFromString() throws IOException { + public void testSwagger2AsciiDocConversionAsString() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + + //When + String asciiDocAsString = Swagger2MarkupConverter.from(file).build() + .asString(); + //Then + assertThat(asciiDocAsString).isNotEmpty(); + } + + + @Test + public void testSwagger2AsciiDocConversion() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConverter.from(file).build() + .intoFolder(outputDirectory); + + //Then + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( + asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/default").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); + } + + @Test + public void testSwagger2AsciiDocConversionFromString() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_petstore.yaml")); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); @@ -70,6 +91,9 @@ public class Swagger2MarkupConverterTest { String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll( asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/default").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); } @Test @@ -262,44 +286,10 @@ public class Swagger2MarkupConverterTest { } - - @Test - public void testSwagger2AsciiDocConversionAsString() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - - //When - String asciiDocAsString = Swagger2MarkupConverter.from(file).build() - .asString(); - //Then - assertThat(asciiDocAsString).isNotEmpty(); - } - - - @Test - public void testSwagger2AsciiDocConversion() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); - FileUtils.deleteQuietly(outputDirectory.toFile()); - - //When - Swagger2MarkupConverter.from(file).build() - .intoFolder(outputDirectory); - - //Then - String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); - - Path expectedFilesDirectory = Paths.get(Swagger2MarkupConverterTest.class.getResource("/results/asciidoc/default").toURI()); - DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); - } - @Test public void testSwagger2AsciiDocWithInlineSchema() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -321,7 +311,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocGroupedByTags() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When @@ -342,7 +332,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocGroupedByTagsWithMissingTag() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/json/swagger_missing_tag.json").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_missing_tag.json").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When @@ -365,7 +355,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocConversionWithDefinitionDescriptions() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -387,7 +377,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocConversionDoesNotContainUriScheme() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_should_not_contain_uri_scheme.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_should_not_contain_uri_scheme.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -407,7 +397,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocConversionContainsUriScheme() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_should_contain_uri_scheme.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_should_contain_uri_scheme.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -424,55 +414,11 @@ public class Swagger2MarkupConverterTest { .contains("=== URI scheme"); } - @Test - public void testSwagger2MarkdownConversion() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Path outputDirectory = Paths.get("build/docs/markdown/generated"); - FileUtils.deleteQuietly(outputDirectory.toFile()); - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) - .build(); - Swagger2MarkupConverter.from(file) - .withConfig(config) - .build() - .intoFolder(outputDirectory); - - //Then - String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.md", "overview.md", "paths.md", "security.md")); - } - - @Test - public void testSwagger2MarkdownConversionWithDescriptions() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Path outputDirectory = Paths.get("build/docs/markdown/generated"); - FileUtils.deleteQuietly(outputDirectory.toFile()); - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withDefinitionDescriptions(Paths.get("src/docs/markdown/definitions")) - .withMarkupLanguage(MarkupLanguage.MARKDOWN) - .build(); - Swagger2MarkupConverter.from(file) - .withConfig(config) - .build() - .intoFolder(outputDirectory); - - //Then - String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.md", "overview.md", "paths.md", "security.md")); - } @Test public void testSwagger2AsciiDocConversionWithSeparatedDefinitions() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -497,7 +443,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocConversionWithSeparatedOperations() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -518,70 +464,10 @@ public class Swagger2MarkupConverterTest { assertThat(paths).hasSize(18); } - @Test - public void testSwagger2MarkdownConversionWithSeparatedDefinitions() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Path outputDirectory = Paths.get("build/docs/markdown/generated"); - FileUtils.deleteQuietly(outputDirectory.toFile()); - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withSeparatedDefinitions() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) - .build(); - Swagger2MarkupConverter.from(file) - .withConfig(config) - .build() - .intoFolder(outputDirectory); - - //Then - String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(5).containsAll( - asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); - - Path definitionsDirectory = outputDirectory.resolve("definitions"); - String[] definitions = definitionsDirectory.toFile().list(); - assertThat(definitions).hasSize(5).containsAll( - asList("Category.md", "Order.md", "Pet.md", "Tag.md", "User.md")); - } - - @Test - public void testSwagger2MarkdownConversionHandlesComposition() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Path outputDirectory = Paths.get("build/docs/markdown/generated"); - FileUtils.deleteQuietly(outputDirectory.toFile()); - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withSeparatedDefinitions() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) - .build(); - Swagger2MarkupConverter.from(file) - .withConfig(config) - .build() - .intoFolder(outputDirectory); - - // Then - String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(5).containsAll( - asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); - Path definitionsDirectory = outputDirectory.resolve("definitions"); - verifyMarkdownContainsFieldsInTables( - definitionsDirectory.resolve("User.md").toFile(), - ImmutableMap.>builder() - .put("User", ImmutableSet.of("id", "username", "firstName", - "lastName", "email", "password", "phone", "userStatus")) - .build() - ); - - } - @Test public void testSwagger2AsciiDocConversionWithRussianOutputLanguage() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -602,7 +488,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocConversionWithFrenchOutputLanguage() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -623,7 +509,7 @@ public class Swagger2MarkupConverterTest { @Test public void testSwagger2AsciiDocExtensions() throws IOException, URISyntaxException { //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); @@ -647,168 +533,4 @@ public class Swagger2MarkupConverterTest { "Pet extension"); } - - @Test - public void testSwagger2MarkdownExtensions() throws IOException, URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - Path outputDirectory = Paths.get("build/docs/markdown/generated"); - FileUtils.deleteQuietly(outputDirectory.toFile()); - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withMarkupLanguage(MarkupLanguage.MARKDOWN) - .build(); - Swagger2MarkupExtensionRegistry registry = Swagger2MarkupExtensionRegistry.ofEmpty() - .withExtension(new DynamicDefinitionsContentExtension(Paths.get("src/docs/markdown/extensions"))) - .withExtension(new DynamicOperationsContentExtension(Paths.get("src/docs/markdown/extensions"))) - .build(); - Swagger2MarkupConverter.from(file) - .withConfig(config) - .withExtensionRegistry(registry) - .build() - .intoFolder(outputDirectory); - - //Then - assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.md")))).contains( - "Pet update request extension"); - assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.md")))).contains( - "Pet extension"); - - } - - @Test - public void testSwagger2MarkupConfigDefaultPaths() throws URISyntaxException { - //Given - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withDefinitionDescriptions() - .withOperationDescriptions() - .withSchemas() - .build(); - - Swagger2MarkupConverter converterBuilder = Swagger2MarkupConverter.from(file) - .withConfig(config) - .build(); - - //Then - URI baseUri = io.github.robwin.swagger2markup.utils.IOUtils.uriParent(converterBuilder.globalContext.swaggerLocation); - assertThat(converterBuilder.globalContext.config.getDefinitionDescriptionsUri()).isEqualTo(baseUri); - assertThat(converterBuilder.globalContext.config.getOperationDescriptionsUri()).isEqualTo(baseUri); - assertThat(converterBuilder.globalContext.config.getSchemasUri()).isEqualTo(baseUri); - } - - @Test - public void testSwagger2MarkupConfigDefaultPathsWithUri() throws MalformedURLException { - //Given - - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withDefinitionDescriptions() - .withOperationDescriptions() - .withSchemas() - .build(); - - Swagger2MarkupConverter converterBuilder = Swagger2MarkupConverter.from(URI.create("http://petstore.swagger.io/v2/swagger.json").toURL()) - .withConfig(config) - .build(); - - //Then - assertThat(converterBuilder.globalContext.config.getDefinitionDescriptionsUri()).isNull(); - assertThat(converterBuilder.globalContext.config.getOperationDescriptionsUri()).isNull(); - assertThat(converterBuilder.globalContext.config.getSchemasUri()).isNull(); - } - - @Test - public void testSwagger2MarkupConfigDefaultPathsWithoutFile() { - //Given - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withDefinitionDescriptions() - .build(); - - //Then - Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(new Swagger()) - .withConfig(config) - .build(); - assertThat(converter.globalContext.config.isDefinitionDescriptionsEnabled()).isFalse(); - } - - /** - * Given a markdown document to search, this checks to see if the specified tables - * have all of the expected fields listed. - * - * @param doc markdown document file to inspect - * @param fieldsByTable map of table name (header) to field names expected - * to be found in that table. - * @throws IOException if the markdown document could not be read - */ - private static void verifyMarkdownContainsFieldsInTables(File doc, Map> fieldsByTable) throws IOException { - final List lines = Files.readAllLines(doc.toPath(), Charset.defaultCharset()); - final Map> fieldsLeftByTable = Maps.newHashMap(); - for (Map.Entry> entry : fieldsByTable.entrySet()) { - fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue())); - } - String inTable = null; - for (String line : lines) { - // If we've found every field we care about, quit early - if (fieldsLeftByTable.isEmpty()) { - return; - } - - // Transition to a new table if we encounter a header - final String currentHeader = getTableHeader(line); - if (inTable == null || currentHeader != null) { - inTable = currentHeader; - } - - // If we're in a table that we care about, inspect this potential table row - if (inTable != null && fieldsLeftByTable.containsKey(inTable)) { - // If we're still in a table, read the row and check for the field name - // NOTE: If there was at least one pipe, then there's at least 2 fields - String[] parts = line.split("\\|"); - if (parts.length > 1) { - final String fieldName = parts[1]; - final Set fieldsLeft = fieldsLeftByTable.get(inTable); - // Mark the field as found and if this table has no more fields to find, - // remove it from the "fieldsLeftByTable" map to mark the table as done - if (fieldsLeft.remove(fieldName) && fieldsLeft.isEmpty()) { - fieldsLeftByTable.remove(inTable); - } - } - } - } - - // After reading the file, if there were still types, fail - if (!fieldsLeftByTable.isEmpty()) { - fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s", - doc, fieldsLeftByTable)); - } - } - - private static String getTableHeader(String line) { - return line.startsWith("###") - ? line.replace("###", "").trim() - : null; - } - - /* - @Test - public void testSwagger2HtmlConversion() throws IOException { - Path file = Paths.get(Swagger2MarkupConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); - String asciiDoc = Swagger2MarkupConverter.from(file).build().asString(); - String path = "build/docs/generated/asciidocAsString"; - Files.createDirectories(Paths.get(path)); - try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.adoc"), StandardCharsets.UTF_8)){ - writer.write(asciiDoc); } - String asciiDocAsHtml = Asciidoctor.Factory.create().convert(asciiDoc, - OptionsBuilder.options().backend("html5").headerFooter(true).safe(SafeMode.UNSAFE).docType("book").attributes(AttributesBuilder.attributes() - .tableOfContents(true).tableOfContents(Placement.LEFT).sectionNumbers(true).hardbreaks(true).setAnchors(true).attribute("sectlinks"))); - try (BufferedWriter writer = Files.newBufferedWriter(Paths.get(path, "swagger.html"), StandardCharsets.UTF_8)){ - writer.write(asciiDocAsHtml); - } - } - */ } diff --git a/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java new file mode 100644 index 00000000..5e323344 --- /dev/null +++ b/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java @@ -0,0 +1,90 @@ +/* + * Copyright 2016 Robert Winkler + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package io.github.robwin.swagger2markup; + +import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; +import io.swagger.models.Swagger; +import org.junit.Test; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static org.assertj.core.api.Assertions.assertThat; + +public class GeneralConverterTest { + + @Test + public void testSwagger2MarkupConfigDefaultPaths() throws URISyntaxException { + //Given + Path file = Paths.get(GeneralConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withDefinitionDescriptions() + .withOperationDescriptions() + .withSchemas() + .build(); + + Swagger2MarkupConverter converterBuilder = Swagger2MarkupConverter.from(file) + .withConfig(config) + .build(); + + //Then + URI baseUri = io.github.robwin.swagger2markup.utils.IOUtils.uriParent(converterBuilder.globalContext.swaggerLocation); + assertThat(converterBuilder.globalContext.config.getDefinitionDescriptionsUri()).isEqualTo(baseUri); + assertThat(converterBuilder.globalContext.config.getOperationDescriptionsUri()).isEqualTo(baseUri); + assertThat(converterBuilder.globalContext.config.getSchemasUri()).isEqualTo(baseUri); + } + + @Test + public void testSwagger2MarkupConfigDefaultPathsWithUri() throws MalformedURLException { + //Given + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withDefinitionDescriptions() + .withOperationDescriptions() + .withSchemas() + .build(); + + Swagger2MarkupConverter converterBuilder = Swagger2MarkupConverter.from(URI.create("http://petstore.swagger.io/v2/swagger.json").toURL()) + .withConfig(config) + .build(); + + //Then + assertThat(converterBuilder.globalContext.config.getDefinitionDescriptionsUri()).isNull(); + assertThat(converterBuilder.globalContext.config.getOperationDescriptionsUri()).isNull(); + assertThat(converterBuilder.globalContext.config.getSchemasUri()).isNull(); + } + + @Test + public void testSwagger2MarkupConfigDefaultPathsWithoutFile() { + //Given + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withDefinitionDescriptions() + .build(); + + //Then + Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(new Swagger()) + .withConfig(config) + .build(); + assertThat(converter.globalContext.config.isDefinitionDescriptionsEnabled()).isFalse(); + } +} diff --git a/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java new file mode 100644 index 00000000..5b6118aa --- /dev/null +++ b/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java @@ -0,0 +1,260 @@ +/* + * Copyright 2016 Robert Winkler + * + * 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 + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * 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. + */ +package io.github.robwin.swagger2markup; + +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import io.github.robwin.markup.builder.MarkupLanguage; +import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; +import io.github.robwin.swagger2markup.extension.Swagger2MarkupExtensionRegistry; +import io.github.robwin.swagger2markup.extension.repository.DynamicDefinitionsContentExtension; +import io.github.robwin.swagger2markup.extension.repository.DynamicOperationsContentExtension; +import io.swagger.models.Swagger; +import org.apache.commons.io.FileUtils; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.net.URI; +import java.net.URISyntaxException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static java.util.Arrays.asList; +import static org.assertj.core.api.Assertions.fail; +import static org.assertj.core.api.BDDAssertions.assertThat; + +public class MarkdownConverterTest { + + private static final Logger LOG = LoggerFactory.getLogger(MarkdownConverterTest.class); + + + @Test + public void testSwagger2MarkdownConversion() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/docs/markdown/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .build(); + Swagger2MarkupConverter.from(file) + .withConfig(config) + .build() + .intoFolder(outputDirectory); + + //Then + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( + asList("definitions.md", "overview.md", "paths.md", "security.md")); + } + + @Test + public void testSwagger2MarkdownConversionWithDescriptions() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/docs/markdown/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withDefinitionDescriptions(Paths.get("src/docs/markdown/definitions")) + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .build(); + Swagger2MarkupConverter.from(file) + .withConfig(config) + .build() + .intoFolder(outputDirectory); + + //Then + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(4).containsAll( + asList("definitions.md", "overview.md", "paths.md", "security.md")); + } + + @Test + public void testSwagger2MarkdownConversionWithSeparatedDefinitions() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/docs/markdown/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withSeparatedDefinitions() + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .build(); + Swagger2MarkupConverter.from(file) + .withConfig(config) + .build() + .intoFolder(outputDirectory); + + //Then + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(5).containsAll( + asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); + + Path definitionsDirectory = outputDirectory.resolve("definitions"); + String[] definitions = definitionsDirectory.toFile().list(); + assertThat(definitions).hasSize(5).containsAll( + asList("Category.md", "Order.md", "Pet.md", "Tag.md", "User.md")); + } + + @Test + public void testSwagger2MarkdownConversionHandlesComposition() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/docs/markdown/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withSeparatedDefinitions() + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .build(); + Swagger2MarkupConverter.from(file) + .withConfig(config) + .build() + .intoFolder(outputDirectory); + + // Then + String[] files = outputDirectory.toFile().list(); + assertThat(files).hasSize(5).containsAll( + asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); + Path definitionsDirectory = outputDirectory.resolve("definitions"); + verifyMarkdownContainsFieldsInTables( + definitionsDirectory.resolve("User.md").toFile(), + ImmutableMap.>builder() + .put("User", ImmutableSet.of("id", "username", "firstName", + "lastName", "email", "password", "phone", "userStatus")) + .build() + ); + + } + + @Test + public void testSwagger2MarkdownExtensions() throws IOException, URISyntaxException { + //Given + Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); + Path outputDirectory = Paths.get("build/docs/markdown/generated"); + FileUtils.deleteQuietly(outputDirectory.toFile()); + + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .build(); + Swagger2MarkupExtensionRegistry registry = Swagger2MarkupExtensionRegistry.ofEmpty() + .withExtension(new DynamicDefinitionsContentExtension(Paths.get("src/docs/markdown/extensions"))) + .withExtension(new DynamicOperationsContentExtension(Paths.get("src/docs/markdown/extensions"))) + .build(); + Swagger2MarkupConverter.from(file) + .withConfig(config) + .withExtensionRegistry(registry) + .build() + .intoFolder(outputDirectory); + + //Then + assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.md")))).contains( + "Pet update request extension"); + assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.md")))).contains( + "Pet extension"); + + } + + @Test + public void testSwagger2MarkupConfigDefaultPathsWithoutFile() { + //Given + //When + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withDefinitionDescriptions() + .build(); + + //Then + Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(new Swagger()) + .withConfig(config) + .build(); + assertThat(converter.globalContext.config.isDefinitionDescriptionsEnabled()).isFalse(); + } + + /** + * Given a markdown document to search, this checks to see if the specified tables + * have all of the expected fields listed. + * + * @param doc markdown document file to inspect + * @param fieldsByTable map of table name (header) to field names expected + * to be found in that table. + * @throws IOException if the markdown document could not be read + */ + private static void verifyMarkdownContainsFieldsInTables(File doc, Map> fieldsByTable) throws IOException { + final List lines = Files.readAllLines(doc.toPath(), Charset.defaultCharset()); + final Map> fieldsLeftByTable = Maps.newHashMap(); + for (Map.Entry> entry : fieldsByTable.entrySet()) { + fieldsLeftByTable.put(entry.getKey(), Sets.newHashSet(entry.getValue())); + } + String inTable = null; + for (String line : lines) { + // If we've found every field we care about, quit early + if (fieldsLeftByTable.isEmpty()) { + return; + } + + // Transition to a new table if we encounter a header + final String currentHeader = getTableHeader(line); + if (inTable == null || currentHeader != null) { + inTable = currentHeader; + } + + // If we're in a table that we care about, inspect this potential table row + if (inTable != null && fieldsLeftByTable.containsKey(inTable)) { + // If we're still in a table, read the row and check for the field name + // NOTE: If there was at least one pipe, then there's at least 2 fields + String[] parts = line.split("\\|"); + if (parts.length > 1) { + final String fieldName = parts[1]; + final Set fieldsLeft = fieldsLeftByTable.get(inTable); + // Mark the field as found and if this table has no more fields to find, + // remove it from the "fieldsLeftByTable" map to mark the table as done + if (fieldsLeft.remove(fieldName) && fieldsLeft.isEmpty()) { + fieldsLeftByTable.remove(inTable); + } + } + } + } + + // After reading the file, if there were still types, fail + if (!fieldsLeftByTable.isEmpty()) { + fail(String.format("Markdown file '%s' did not contain expected fields (by table): %s", + doc, fieldsLeftByTable)); + } + } + + private static String getTableHeader(String line) { + return line.startsWith("###") + ? line.replace("###", "").trim() + : null; + } +} From e79f6c49a4b89ba009697d7fbde2c50f2ca7ca9d Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Fri, 4 Mar 2016 13:32:37 +0100 Subject: [PATCH 4/7] Moved testSwagger2MarkupConfigDefaultPathsWithoutFile from MarkdownConvertTest into GeneralConverterTest. --- .../swagger2markup/GeneralConverterTest.java | 6 +++--- .../swagger2markup/MarkdownConverterTest.java | 17 ----------------- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java index 5e323344..19673f0d 100644 --- a/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/GeneralConverterTest.java @@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat; public class GeneralConverterTest { @Test - public void testSwagger2MarkupConfigDefaultPaths() throws URISyntaxException { + public void testConfigDefaultPaths() throws URISyntaxException { //Given Path file = Paths.get(GeneralConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); @@ -53,7 +53,7 @@ public class GeneralConverterTest { } @Test - public void testSwagger2MarkupConfigDefaultPathsWithUri() throws MalformedURLException { + public void testConfigDefaultPathsWithUri() throws MalformedURLException { //Given //When @@ -74,7 +74,7 @@ public class GeneralConverterTest { } @Test - public void testSwagger2MarkupConfigDefaultPathsWithoutFile() { + public void testDefaultPathsWithoutFile() { //Given //When Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() diff --git a/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java index 5b6118aa..58ff7929 100644 --- a/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java @@ -24,7 +24,6 @@ import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; import io.github.robwin.swagger2markup.extension.Swagger2MarkupExtensionRegistry; import io.github.robwin.swagger2markup.extension.repository.DynamicDefinitionsContentExtension; import io.github.robwin.swagger2markup.extension.repository.DynamicOperationsContentExtension; -import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.junit.Test; import org.slf4j.Logger; @@ -32,7 +31,6 @@ import org.slf4j.LoggerFactory; import java.io.File; import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; import java.nio.charset.Charset; import java.nio.file.Files; @@ -185,21 +183,6 @@ public class MarkdownConverterTest { } - @Test - public void testSwagger2MarkupConfigDefaultPathsWithoutFile() { - //Given - //When - Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() - .withDefinitionDescriptions() - .build(); - - //Then - Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(new Swagger()) - .withConfig(config) - .build(); - assertThat(converter.globalContext.config.isDefinitionDescriptionsEnabled()).isFalse(); - } - /** * Given a markdown document to search, this checks to see if the specified tables * have all of the expected fields listed. From d0dc6188cd782c02989b6476fd289263a83967e7 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Fri, 4 Mar 2016 14:54:25 +0100 Subject: [PATCH 5/7] Removed io.spring.gradle:dependency-management-plugin --- build.gradle | 36 ++++++++++-------------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/build.gradle b/build.gradle index 0225b643..d353e81f 100644 --- a/build.gradle +++ b/build.gradle @@ -6,7 +6,6 @@ buildscript { dependencies { classpath 'org.asciidoctor:asciidoctor-gradle-plugin:1.5.3' classpath 'org.asciidoctor:asciidoctorj-pdf:1.5.0-alpha.10.1' - classpath 'io.spring.gradle:dependency-management-plugin:0.5.5.RELEASE' classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.0.1' classpath 'org.asciidoctor:asciidoctorj:1.5.2' classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.2' @@ -22,7 +21,6 @@ apply plugin: 'maven-publish' apply plugin: 'org.asciidoctor.convert' apply plugin: 'jacoco' apply plugin: 'com.github.kt3k.coveralls' -apply plugin: 'io.spring.dependency-management' apply plugin: 'com.jfrog.bintray' apply plugin: "com.jfrog.artifactory" apply from: 'gradle/publishing.gradle' @@ -41,34 +39,20 @@ repositories { } jcenter() mavenCentral() - mavenLocal() + //mavenLocal() } dependencies { - compile 'io.github.robwin:markup-document-builder' - compile 'io.swagger:swagger-compat-spec-parser' - compile 'commons-collections:commons-collections' - compile 'commons-io:commons-io' - compile 'org.slf4j:slf4j-api' - testCompile 'junit:junit' + compile 'io.github.robwin:markup-document-builder:0.1.6-SNAPSHOT' + compile 'io.swagger:swagger-compat-spec-parser:1.0.17' + compile 'commons-collections:commons-collections:3.2.1' + compile 'commons-io:commons-io:2.4' + compile 'org.slf4j:slf4j-api:1.7.12' + testCompile 'junit:junit:4.11' testCompile 'org.asciidoctor:asciidoctorj:1.5.4' - testCompile 'ch.qos.logback:logback-classic' - testCompile 'org.assertj:assertj-core' - testCompile 'com.sksamuel.diff:diff' -} - -dependencyManagement { - dependencies { - dependency "io.github.robwin:markup-document-builder:0.1.6-SNAPSHOT" - dependency "io.swagger:swagger-compat-spec-parser:1.0.17" - dependency "commons-collections:commons-collections:3.2.1" - dependency "commons-io:commons-io:2.4" - dependency "junit:junit:4.11" - dependency "org.slf4j:slf4j-api:1.7.12" - dependency "ch.qos.logback:logback-classic:1.1.2" - dependency "org.assertj:assertj-core:2.2.0" - dependency "com.sksamuel.diff:diff:1.1.11" - } + testCompile 'ch.qos.logback:logback-classic:1.1.2' + testCompile 'org.assertj:assertj-core:2.2.0' + testCompile 'com.sksamuel.diff:diff:1.1.11' } task sourcesJar(type: Jar, dependsOn: classes) { From 5b054761cfdbbf39793ba0c6e0c80d3fbdbe5d99 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Mon, 7 Mar 2016 11:08:51 +0100 Subject: [PATCH 6/7] Added expected AsciiDoc and Markdown files. --- .../swagger2markup/AsciidocConverterTest.java | 193 +-- .../swagger2markup/MarkdownConverterTest.java | 30 +- .../asciidoc/examples/definitions.adoc | 84 ++ .../results/asciidoc/examples/overview.adoc | 36 + .../results/asciidoc/examples/paths.adoc | 828 ++++++++++++ .../results/asciidoc/examples/security.adoc | 23 + .../generated_examples/definitions.adoc | 86 ++ .../asciidoc/generated_examples/overview.adoc | 36 + .../asciidoc/generated_examples/paths.adoc | 1184 +++++++++++++++++ .../asciidoc/generated_examples/security.adoc | 23 + .../asciidoc/group_by_tags/definitions.adoc | 69 + .../asciidoc/group_by_tags/overview.adoc | 36 + .../results/asciidoc/group_by_tags/paths.adoc | 692 ++++++++++ .../asciidoc/group_by_tags/security.adoc | 23 + .../spring_rest_docs/definitions.adoc | 69 + .../asciidoc/spring_rest_docs/overview.adoc | 36 + .../asciidoc/spring_rest_docs/paths.adoc | 806 +++++++++++ .../asciidoc/spring_rest_docs/security.adoc | 23 + .../results/markdown/default/definitions.md | 59 + .../results/markdown/default/overview.md | 36 + .../results/markdown/default/paths.md | 675 ++++++++++ .../results/markdown/default/security.md | 21 + 22 files changed, 4912 insertions(+), 156 deletions(-) create mode 100644 src/test/resources/results/asciidoc/examples/definitions.adoc create mode 100644 src/test/resources/results/asciidoc/examples/overview.adoc create mode 100644 src/test/resources/results/asciidoc/examples/paths.adoc create mode 100644 src/test/resources/results/asciidoc/examples/security.adoc create mode 100644 src/test/resources/results/asciidoc/generated_examples/definitions.adoc create mode 100644 src/test/resources/results/asciidoc/generated_examples/overview.adoc create mode 100644 src/test/resources/results/asciidoc/generated_examples/paths.adoc create mode 100644 src/test/resources/results/asciidoc/generated_examples/security.adoc create mode 100644 src/test/resources/results/asciidoc/group_by_tags/definitions.adoc create mode 100644 src/test/resources/results/asciidoc/group_by_tags/overview.adoc create mode 100644 src/test/resources/results/asciidoc/group_by_tags/paths.adoc create mode 100644 src/test/resources/results/asciidoc/group_by_tags/security.adoc create mode 100644 src/test/resources/results/asciidoc/spring_rest_docs/definitions.adoc create mode 100644 src/test/resources/results/asciidoc/spring_rest_docs/overview.adoc create mode 100644 src/test/resources/results/asciidoc/spring_rest_docs/paths.adoc create mode 100644 src/test/resources/results/asciidoc/spring_rest_docs/security.adoc create mode 100644 src/test/resources/results/markdown/default/definitions.md create mode 100644 src/test/resources/results/markdown/default/overview.md create mode 100644 src/test/resources/results/markdown/default/paths.md create mode 100644 src/test/resources/results/markdown/default/security.md diff --git a/src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java index 69841605..13436c21 100644 --- a/src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/AsciidocConverterTest.java @@ -15,15 +15,16 @@ */ package io.github.robwin.swagger2markup; +import io.github.robwin.markup.builder.LineSeparator; import io.github.robwin.swagger2markup.assertions.DiffUtils; import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; import io.github.robwin.swagger2markup.extension.Swagger2MarkupExtensionRegistry; import io.github.robwin.swagger2markup.extension.repository.DynamicDefinitionsContentExtension; import io.github.robwin.swagger2markup.extension.repository.DynamicOperationsContentExtension; import io.github.robwin.swagger2markup.extension.repository.SpringRestDocsExtension; -import io.swagger.models.Swagger; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,6 +35,8 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.failBecauseExceptionWasNotThrown; @@ -42,6 +45,13 @@ import static org.assertj.core.api.BDDAssertions.assertThat; public class AsciidocConverterTest { private static final Logger LOG = LoggerFactory.getLogger(AsciidocConverterTest.class); + private static final String[] EXPECTED_FILES = new String[]{"definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc"}; + private List expectedFiles; + + @Before + public void setUp(){ + expectedFiles = new ArrayList<>(asList(EXPECTED_FILES)); + } @Test public void testSwagger2AsciiDocConversionAsString() throws IOException, URISyntaxException { @@ -64,13 +74,15 @@ public class AsciidocConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConverter.from(file).build() + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withLineSeparator(LineSeparator.WINDOWS).build(); + + Swagger2MarkupConverter.from(file).withConfig(config).build() .intoFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/default").toURI()); DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); @@ -84,20 +96,22 @@ public class AsciidocConverterTest { FileUtils.deleteQuietly(outputDirectory.toFile()); //When - Swagger2MarkupConverter.from(swaggerJsonString).build() + Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() + .withLineSeparator(LineSeparator.WINDOWS).build(); + + Swagger2MarkupConverter.from(swaggerJsonString).withConfig(config).build() .intoFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/default").toURI()); DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); } @Test - public void testSwagger2AsciiDocConversionWithSpringRestDocsExtension() throws IOException { + public void testSwagger2AsciiDocConversionWithSpringRestDocsExtension() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_petstore.yaml")); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); @@ -119,14 +133,14 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); - assertThat(new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc")))) - .contains("==== HTTP request", "==== HTTP response", "==== Curl request", "===== curl-request"); + assertThat(files).hasSize(4).containsAll(expectedFiles); + + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/spring_rest_docs").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversionWithSpringRestDocsExtension.html"); } @Test - public void testSwagger2AsciiDocConversionWithExamples() throws IOException { + public void testSwagger2AsciiDocConversionWithExamples() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json")); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); @@ -143,51 +157,13 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); - String orderExample = "----\n" + - "{\n" + - " \"id\" : 99,\n" + - " \"petId\" : 122,\n" + - " \"quantity\" : 2,\n" + - " \"shipDate\" : \"2016-02-22T23:02:05Z\",\n" + - " \"status\" : \"PENDING\",\n" + - " \"complete\" : true\n" + - "}\n" + - "----\n"; - String petResponseExample = "----\n" + - "{\n" + - " \"application/json\" : {\n" + - " \"name\" : \"Puma\",\n" + - " \"type\" : 22,\n" + - " \"color\" : \"Black\",\n" + - " \"gender\" : \"Female\",\n" + - " \"breed\" : \"Mixed\"\n" + - " }\n" + - "}\n" + - "----\n"; - - String pathsDocument = new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc"))); - assertThat(pathsDocument) - .contains("==== Response 405\n" + petResponseExample); - assertThat(pathsDocument) - .contains("==== Request body\n" + orderExample); - assertThat(pathsDocument) - .contains("==== Response 200\n" + orderExample); - - String definitionsDocument = new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc"))); - assertThat(definitionsDocument) - .contains("|name||true|string||\"doggie\""); - assertThat(definitionsDocument) - .contains("|id||false|integer(int64)||77"); - assertThat(definitionsDocument).contains("|pictures||false|string(byte) array||"); - assertThat(definitionsDocument).contains("|shipDate||false|string(date-time)||"); - assertThat(definitionsDocument) - .doesNotContain("99"); + assertThat(files).hasSize(4).containsAll(expectedFiles); + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/examples").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversionWithExamples.html"); } @Test - public void testSwagger2AsciiDocConversionWithGeneratedExamples() throws IOException { + public void testSwagger2AsciiDocConversionWithGeneratedExamples() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json")); Path outputDirectory = Paths.get("build/docs/asciidoc/generated"); @@ -205,85 +181,9 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - String petGeneratedExample = "----\n" + - "{\n" + - " \"tags\" : [ {\n" + - " \"id\" : 0,\n" + - " \"name\" : \"string\"\n" + - " } ],\n" + - " \"id\" : 0,\n" + - " \"nicknames\" : {\n" + - " \"string\" : \"string\"\n" + - " },\n" + - " \"category\" : {\n" + - " \"id\" : 123,\n" + - " \"name\" : \"Canines\"\n" + - " },\n" + - " \"weight\" : 0.0,\n" + - " \"status\" : \"string\",\n" + - " \"name\" : \"doggie\",\n" + - " \"photoUrls\" : [ \"string\" ]\n" + - "}\n" + - "----\n"; - String petResponseExample = "----\n" + - "{\n" + - " \"application/json\" : {\n" + - " \"name\" : \"Puma\",\n" + - " \"type\" : 22,\n" + - " \"color\" : \"Black\",\n" + - " \"gender\" : \"Female\",\n" + - " \"breed\" : \"Mixed\"\n" + - " }\n" + - "}\n" + - "----\n"; - String pathsDocument = new String(Files.readAllBytes(outputDirectory.resolve("paths.adoc"))); - assertThat(pathsDocument) - .contains("==== Request body\n" + petGeneratedExample); - assertThat(pathsDocument) - .contains("== Request path\n" + "----\n" + - "\"/pets\"\n" + - "----"); - assertThat(pathsDocument) - .contains("==== Request query\n" + - "----\n" + - "{\n" + - " \"status\" : \"string\"\n" + - "}\n" + - "----\n"); - assertThat(pathsDocument) - .contains("==== Response 405\n" + petResponseExample); - assertThat(pathsDocument) - .contains("==== Response 200\n" + - "----\n" + - "\"array\"\n" + - "----"); - assertThat(pathsDocument) - .contains("==== Request path\n" + - "----\n" + - "\"/pets/0\"\n" + - "----"); - - String definitionsDocument = new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc"))); - assertThat(definitionsDocument) - .contains("|name||true|string||\"doggie\""); - assertThat(definitionsDocument) - .contains("|id||false|integer(int64)||77"); - assertThat(definitionsDocument).contains("|pictures||false|string(byte) array||[ \"string\" ]"); - assertThat(definitionsDocument).contains("|shipDate||false|string(date-time)||\"string\""); - assertThat(definitionsDocument) - .doesNotContain("99"); - assertThat(definitionsDocument) - .contains("|nicknames||false|object||{\n" + - " \"string\" : \"string\"\n" + - "}"); - assertThat(definitionsDocument) - .contains("[options=\"header\", cols=\".^1h,.^6,.^1,.^1,.^1,.^1\"]\n" + - "|===\n" + - "|Name|Description|Required|Schema|Default|Example\n" + - "|id||false|integer(int64)||0\n" + - "|===\n"); - - + assertThat(files).hasSize(4).containsAll(expectedFiles); + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/generated_examples").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversionWithGeneratedExamples.html"); } @Test @@ -304,8 +204,7 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); } @Test @@ -325,8 +224,9 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/asciidoc/group_by_tags").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocGroupedByTags.html"); } @Test @@ -370,8 +270,7 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); } @Test @@ -387,8 +286,7 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")))) .doesNotContain("=== URI scheme"); @@ -407,8 +305,7 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + assertThat(files).hasSize(4).containsAll(expectedFiles); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("overview.adoc")))) .contains("=== URI scheme"); @@ -431,8 +328,8 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(5).containsAll( - asList("definitions", "definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + expectedFiles.add("definitions"); + assertThat(files).hasSize(5).containsAll(expectedFiles); Path definitionsDirectory = outputDirectory.resolve("definitions"); String[] definitions = definitionsDirectory.toFile().list(); @@ -456,8 +353,8 @@ public class AsciidocConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(5).containsAll( - asList("operations", "definitions.adoc", "overview.adoc", "paths.adoc", "security.adoc")); + expectedFiles.add("operations"); + assertThat(files).hasSize(5).containsAll(expectedFiles); Path pathsDirectory = outputDirectory.resolve("operations"); String[] paths = pathsDirectory.toFile().list(); diff --git a/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java b/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java index 58ff7929..e35050d5 100644 --- a/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/MarkdownConverterTest.java @@ -19,12 +19,15 @@ import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import io.github.robwin.markup.builder.LineSeparator; import io.github.robwin.markup.builder.MarkupLanguage; +import io.github.robwin.swagger2markup.assertions.DiffUtils; import io.github.robwin.swagger2markup.config.Swagger2MarkupConfig; import io.github.robwin.swagger2markup.extension.Swagger2MarkupExtensionRegistry; import io.github.robwin.swagger2markup.extension.repository.DynamicDefinitionsContentExtension; import io.github.robwin.swagger2markup.extension.repository.DynamicOperationsContentExtension; import org.apache.commons.io.FileUtils; +import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,6 +39,7 @@ import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Set; @@ -48,6 +52,14 @@ public class MarkdownConverterTest { private static final Logger LOG = LoggerFactory.getLogger(MarkdownConverterTest.class); + private static final String[] EXPECTED_FILES = new String[]{"definitions.md", "overview.md", "paths.md", "security.md"}; + private List expectedFiles; + + @Before + public void setUp(){ + expectedFiles = new ArrayList<>(asList(EXPECTED_FILES)); + } + @Test public void testSwagger2MarkdownConversion() throws IOException, URISyntaxException { @@ -59,6 +71,7 @@ public class MarkdownConverterTest { //When Swagger2MarkupConfig config = Swagger2MarkupConfig.ofDefaults() .withMarkupLanguage(MarkupLanguage.MARKDOWN) + .withLineSeparator(LineSeparator.WINDOWS) .build(); Swagger2MarkupConverter.from(file) .withConfig(config) @@ -67,8 +80,10 @@ public class MarkdownConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.md", "overview.md", "paths.md", "security.md")); + assertThat(files).hasSize(4).containsAll(expectedFiles); + + Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/results/markdown/default").toURI()); + DiffUtils.assertThatAllFilesAreEqual(outputDirectory, expectedFilesDirectory, "testSwagger2AsciiDocConversion.html"); } @Test @@ -90,8 +105,7 @@ public class MarkdownConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(4).containsAll( - asList("definitions.md", "overview.md", "paths.md", "security.md")); + assertThat(files).hasSize(4).containsAll(expectedFiles); } @Test @@ -113,8 +127,8 @@ public class MarkdownConverterTest { //Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(5).containsAll( - asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); + expectedFiles.add("definitions"); + assertThat(files).hasSize(5).containsAll(expectedFiles); Path definitionsDirectory = outputDirectory.resolve("definitions"); String[] definitions = definitionsDirectory.toFile().list(); @@ -141,8 +155,8 @@ public class MarkdownConverterTest { // Then String[] files = outputDirectory.toFile().list(); - assertThat(files).hasSize(5).containsAll( - asList("definitions", "definitions.md", "overview.md", "paths.md", "security.md")); + expectedFiles.add("definitions"); + assertThat(files).hasSize(5).containsAll(expectedFiles); Path definitionsDirectory = outputDirectory.resolve("definitions"); verifyMarkdownContainsFieldsInTables( definitionsDirectory.resolve("User.md").toFile(), diff --git a/src/test/resources/results/asciidoc/examples/definitions.adoc b/src/test/resources/results/asciidoc/examples/definitions.adoc new file mode 100644 index 00000000..bdf5ec56 --- /dev/null +++ b/src/test/resources/results/asciidoc/examples/definitions.adoc @@ -0,0 +1,84 @@ + +[[_definitions]] +== Definitions + +=== Category + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)||123 +|name||false|string||"Canines" +|=== + + +=== Identified + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)|| +|=== + + +=== Order + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|complete||false|boolean|| +|id||false|integer(int64)||77 +|petId||false|integer(int64)|| +|quantity||false|integer(int32)|| +|shipDate||false|string(date-time)|| +|status|Order Status|false|string||"DONE" +|=== + + +=== Pet +[%hardbreaks] +Test description + + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|category||false|<<_category,Category>>|| +|id||false|integer(int64)|| +|name||true|string||"doggie" +|nicknames||false|object|| +|photoUrls||true|string array|| +|status|pet status in the store|false|string|| +|tags||false|<<_tag,Tag>> array|| +|weight|the weight of the pet|false|number|| +|=== + + +=== Tag + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)|| +|name||false|string|| +|=== + + +=== User + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|email||false|string|| +|firstName||false|string|| +|id||false|integer(int64)|| +|lastName||false|string|| +|password||false|string|| +|phone||false|string|| +|pictures||false|string(byte) array|| +|userStatus|User Status|false|integer(int32)|| +|username||false|string|| +|=== + + + diff --git a/src/test/resources/results/asciidoc/examples/overview.adoc b/src/test/resources/results/asciidoc/examples/overview.adoc new file mode 100644 index 00000000..2efcd1d8 --- /dev/null +++ b/src/test/resources/results/asciidoc/examples/overview.adoc @@ -0,0 +1,36 @@ += Swagger Petstore API + + +[[_overview]] +== Overview +This is a sample server Petstore server. + +[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net. + +For this sample, you can use the api key `special-key` to test the authorization filters + + +=== Version information +Version : 1.0.0 + +=== Contact information +Contact : apiteam@wordnik.com + +=== License information +License : Apache 2.0 +License URL : http://www.apache.org/licenses/LICENSE-2.0.html +Terms of service : http://helloreverb.com/terms/ + +=== URI scheme +Host : petstore.swagger.wordnik.com +BasePath : /v2 +Schemes : HTTP + +=== Tags + +* pet : Pet resource +* store : Store resource +* user : User resource + + + diff --git a/src/test/resources/results/asciidoc/examples/paths.adoc b/src/test/resources/results/asciidoc/examples/paths.adoc new file mode 100644 index 00000000..0939c175 --- /dev/null +++ b/src/test/resources/results/asciidoc/examples/paths.adoc @@ -0,0 +1,828 @@ + +[[_paths]] +== Paths + +=== Add a new pet to the store +---- +POST /pets +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +==== Consumes + +* application/json +* application/xml + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP response + +==== Response 405 +---- +{ + "application/json" : { + "name" : "Puma", + "type" : 22, + "color" : "Black", + "gender" : "Female", + "breed" : "Mixed" + } +} +---- + + +=== Update an existing pet +---- +PUT /pets +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|405|Validation exception|No Content +|=== + + +==== Consumes + +* application/json +* application/xml + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Finds Pets by status +---- +GET /pets/findByStatus +---- + + +==== Description +[%hardbreaks] +Multiple status values can be provided with comma seperated strings + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|status|Status values that need to be considered for filter|false|multi string array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid status value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Finds Pets by tags +---- +GET /pets/findByTags +---- + + +==== Description +[%hardbreaks] +Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|tags|Tags to filter by|false|multi string array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid tag value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Updates a pet in the store with form data +---- +POST /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of pet that needs to be updated|true|string| +|FormData|name|Updated name of the pet|true|string| +|FormData|status|Updated status of the pet|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +==== Consumes + +* application/x-www-form-urlencoded + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Find pet by ID +---- +GET /pets/{petId} +---- + + +==== Description +[%hardbreaks] +Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of the pet|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|apiKey|<<_api_key,api_key>>| +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Deletes a pet +---- +DELETE /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Header|api_key||true|string| +|Path|petId|Pet id to delete|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid pet value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Place an order for a pet +---- +POST /stores/order +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|order placed for purchasing the pet|false|<<_order,Order>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid Order|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +==== Example HTTP request + +==== Request body +---- +{ + "id" : 99, + "petId" : 122, + "quantity" : 2, + "shipDate" : "2016-02-22T23:02:05Z", + "status" : "PENDING", + "complete" : true +} +---- + + +==== Example HTTP response + +==== Response 200 +---- +{ + "id" : 99, + "petId" : 122, + "quantity" : 2, + "shipDate" : "2016-02-22T23:02:05Z", + "status" : "PENDING", + "complete" : true +} +---- + + +=== Find purchase order by ID +---- +GET /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of pet that needs to be fetched|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +==== Example HTTP response + +==== Response 200 +---- +{ + "id" : 99, + "petId" : 122, + "quantity" : 2, + "shipDate" : "2016-02-22T23:02:05Z", + "status" : "PENDING", + "complete" : true +} +---- + + +=== Delete purchase order by ID +---- +DELETE /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of the order that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +=== Create user +---- +POST /users +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Created user object|false|<<_user,User>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Creates list of users with given input array +---- +POST /users/createWithArray +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Creates list of users with given input array +---- +POST /users/createWithList +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Logs user into the system +---- +GET /users/login +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|password|The password for login in clear text|false|string|testPassword +|Query|username|The user name for login|false|string|testUser +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|string +|400|Invalid username/password supplied|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Logs out current logged in user session +---- +GET /users/logout +---- + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Get user by user name +---- +GET /users/{username} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string|testUser +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_user,User>> +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Updated user +---- +PUT /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|name that need to be deleted|true|string| +|Body|body|Updated user object|false|<<_user,User>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid user supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Delete user +---- +DELETE /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + + diff --git a/src/test/resources/results/asciidoc/examples/security.adoc b/src/test/resources/results/asciidoc/examples/security.adoc new file mode 100644 index 00000000..635887ad --- /dev/null +++ b/src/test/resources/results/asciidoc/examples/security.adoc @@ -0,0 +1,23 @@ + +[[_security]] +== Security + +=== api_key +Type : apiKey +Name : api_key +In : HEADER + +=== petstore_auth +Type : oauth2 +Flow : implicit +Token URL : http://petstore.swagger.wordnik.com/api/oauth/dialog + +[options="header", cols="1,6"] +|=== +|Name|Description +|write_pets|modify pets in your account +|read_pets|read your pets +|=== + + + diff --git a/src/test/resources/results/asciidoc/generated_examples/definitions.adoc b/src/test/resources/results/asciidoc/generated_examples/definitions.adoc new file mode 100644 index 00000000..aa021bec --- /dev/null +++ b/src/test/resources/results/asciidoc/generated_examples/definitions.adoc @@ -0,0 +1,86 @@ + +[[_definitions]] +== Definitions + +=== Category + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)||123 +|name||false|string||"Canines" +|=== + + +=== Identified + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)||0 +|=== + + +=== Order + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|complete||false|boolean||true +|id||false|integer(int64)||77 +|petId||false|integer(int64)||0 +|quantity||false|integer(int32)||0 +|shipDate||false|string(date-time)||"string" +|status|Order Status|false|string||"DONE" +|=== + + +=== Pet +[%hardbreaks] +Test description + + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|category||false|<<_category,Category>>||"<<_category>>" +|id||false|integer(int64)||0 +|name||true|string||"doggie" +|nicknames||false|object||{ + "string" : "string" +} +|photoUrls||true|string array||[ "string" ] +|status|pet status in the store|false|string||"string" +|tags||false|<<_tag,Tag>> array||[ "<<_tag>>" ] +|weight|the weight of the pet|false|number||0.0 +|=== + + +=== Tag + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)||0 +|name||false|string||"string" +|=== + + +=== User + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|email||false|string||"string" +|firstName||false|string||"string" +|id||false|integer(int64)||0 +|lastName||false|string||"string" +|password||false|string||"string" +|phone||false|string||"string" +|pictures||false|string(byte) array||[ "string" ] +|userStatus|User Status|false|integer(int32)||0 +|username||false|string||"string" +|=== + + + diff --git a/src/test/resources/results/asciidoc/generated_examples/overview.adoc b/src/test/resources/results/asciidoc/generated_examples/overview.adoc new file mode 100644 index 00000000..2efcd1d8 --- /dev/null +++ b/src/test/resources/results/asciidoc/generated_examples/overview.adoc @@ -0,0 +1,36 @@ += Swagger Petstore API + + +[[_overview]] +== Overview +This is a sample server Petstore server. + +[Learn about Swagger](http://swagger.wordnik.com) or join the IRC channel `#swagger` on irc.freenode.net. + +For this sample, you can use the api key `special-key` to test the authorization filters + + +=== Version information +Version : 1.0.0 + +=== Contact information +Contact : apiteam@wordnik.com + +=== License information +License : Apache 2.0 +License URL : http://www.apache.org/licenses/LICENSE-2.0.html +Terms of service : http://helloreverb.com/terms/ + +=== URI scheme +Host : petstore.swagger.wordnik.com +BasePath : /v2 +Schemes : HTTP + +=== Tags + +* pet : Pet resource +* store : Store resource +* user : User resource + + + diff --git a/src/test/resources/results/asciidoc/generated_examples/paths.adoc b/src/test/resources/results/asciidoc/generated_examples/paths.adoc new file mode 100644 index 00000000..4925df38 --- /dev/null +++ b/src/test/resources/results/asciidoc/generated_examples/paths.adoc @@ -0,0 +1,1184 @@ + +[[_paths]] +== Paths + +=== Add a new pet to the store +---- +POST /pets +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +==== Consumes + +* application/json +* application/xml + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request body +---- +{ + "tags" : [ { + "id" : 0, + "name" : "string" + } ], + "id" : 0, + "nicknames" : { + "string" : "string" + }, + "category" : { + "id" : 123, + "name" : "Canines" + }, + "weight" : 0.0, + "status" : "string", + "name" : "doggie", + "photoUrls" : [ "string" ] +} +---- + + +==== Request path +---- +"/pets" +---- + + +==== Example HTTP response + +==== Response 405 +---- +{ + "application/json" : { + "name" : "Puma", + "type" : 22, + "color" : "Black", + "gender" : "Female", + "breed" : "Mixed" + } +} +---- + + +=== Update an existing pet +---- +PUT /pets +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|405|Validation exception|No Content +|=== + + +==== Consumes + +* application/json +* application/xml + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request body +---- +{ + "tags" : [ { + "id" : 0, + "name" : "string" + } ], + "id" : 0, + "nicknames" : { + "string" : "string" + }, + "category" : { + "id" : 123, + "name" : "Canines" + }, + "weight" : 0.0, + "status" : "string", + "name" : "doggie", + "photoUrls" : [ "string" ] +} +---- + + +==== Request path +---- +"/pets" +---- + + +=== Finds Pets by status +---- +GET /pets/findByStatus +---- + + +==== Description +[%hardbreaks] +Multiple status values can be provided with comma seperated strings + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|status|Status values that need to be considered for filter|false|multi string array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid status value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request query +---- +{ + "status" : "string" +} +---- + + +==== Request path +---- +"/pets/findByStatus" +---- + + +==== Example HTTP response + +==== Response 200 +---- +"array" +---- + + +=== Finds Pets by tags +---- +GET /pets/findByTags +---- + + +==== Description +[%hardbreaks] +Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|tags|Tags to filter by|false|multi string array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid tag value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request query +---- +{ + "tags" : "string" +} +---- + + +==== Request path +---- +"/pets/findByTags" +---- + + +==== Example HTTP response + +==== Response 200 +---- +"array" +---- + + +=== Updates a pet in the store with form data +---- +POST /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of pet that needs to be updated|true|string| +|FormData|name|Updated name of the pet|true|string| +|FormData|status|Updated status of the pet|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +==== Consumes + +* application/x-www-form-urlencoded + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request formData +---- +"string" +---- + + +==== Request path +---- +"/pets/string" +---- + + +=== Find pet by ID +---- +GET /pets/{petId} +---- + + +==== Description +[%hardbreaks] +Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of the pet|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|apiKey|<<_api_key,api_key>>| +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request path +---- +"/pets/0" +---- + + +==== Example HTTP response + +==== Response 200 +---- +{ + "tags" : [ { + "id" : 0, + "name" : "string" + } ], + "id" : 0, + "nicknames" : { + "string" : "string" + }, + "category" : { + "id" : 123, + "name" : "Canines" + }, + "weight" : 0.0, + "status" : "string", + "name" : "doggie", + "photoUrls" : [ "string" ] +} +---- + + +=== Deletes a pet +---- +DELETE /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Header|api_key||true|string| +|Path|petId|Pet id to delete|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid pet value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Example HTTP request + +==== Request path +---- +"/pets/0" +---- + + +==== Request header +---- +"string" +---- + + +=== Place an order for a pet +---- +POST /stores/order +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|order placed for purchasing the pet|false|<<_order,Order>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid Order|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +==== Example HTTP request + +==== Request body +---- +{ + "id" : 99, + "petId" : 122, + "quantity" : 2, + "shipDate" : "2016-02-22T23:02:05Z", + "status" : "PENDING", + "complete" : true +} +---- + + +==== Request path +---- +"/stores/order" +---- + + +==== Example HTTP response + +==== Response 200 +---- +{ + "id" : 99, + "petId" : 122, + "quantity" : 2, + "shipDate" : "2016-02-22T23:02:05Z", + "status" : "PENDING", + "complete" : true +} +---- + + +=== Find purchase order by ID +---- +GET /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of pet that needs to be fetched|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +==== Example HTTP request + +==== Request path +---- +"/stores/order/string" +---- + + +==== Example HTTP response + +==== Response 200 +---- +{ + "id" : 99, + "petId" : 122, + "quantity" : 2, + "shipDate" : "2016-02-22T23:02:05Z", + "status" : "PENDING", + "complete" : true +} +---- + + +=== Delete purchase order by ID +---- +DELETE /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of the order that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +==== Example HTTP request + +==== Request path +---- +"/stores/order/string" +---- + + +=== Create user +---- +POST /users +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Created user object|false|<<_user,User>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request body +---- +{ + "id" : 0, + "lastName" : "string", + "phone" : "string", + "username" : "string", + "email" : "string", + "userStatus" : 0, + "pictures" : [ "string" ], + "firstName" : "string", + "password" : "string" +} +---- + + +==== Request path +---- +"/users" +---- + + +=== Creates list of users with given input array +---- +POST /users/createWithArray +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request body +---- +[ { + "id" : 0, + "lastName" : "string", + "phone" : "string", + "username" : "string", + "email" : "string", + "userStatus" : 0, + "pictures" : [ "string" ], + "firstName" : "string", + "password" : "string" +} ] +---- + + +==== Request path +---- +"/users/createWithArray" +---- + + +=== Creates list of users with given input array +---- +POST /users/createWithList +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request body +---- +[ { + "id" : 0, + "lastName" : "string", + "phone" : "string", + "username" : "string", + "email" : "string", + "userStatus" : 0, + "pictures" : [ "string" ], + "firstName" : "string", + "password" : "string" +} ] +---- + + +==== Request path +---- +"/users/createWithList" +---- + + +=== Logs user into the system +---- +GET /users/login +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|password|The password for login in clear text|false|string|testPassword +|Query|username|The user name for login|false|string|testUser +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|string +|400|Invalid username/password supplied|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request query +---- +{ + "username" : "string", + "password" : "string" +} +---- + + +==== Request path +---- +"/users/login" +---- + + +==== Example HTTP response + +==== Response 200 +---- +"string" +---- + + +=== Logs out current logged in user session +---- +GET /users/logout +---- + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request path +---- +"/users/logout" +---- + + +=== Get user by user name +---- +GET /users/{username} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string|testUser +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_user,User>> +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request path +---- +"/users/string" +---- + + +==== Example HTTP response + +==== Response 200 +---- +{ + "id" : 0, + "lastName" : "string", + "phone" : "string", + "username" : "string", + "email" : "string", + "userStatus" : 0, + "pictures" : [ "string" ], + "firstName" : "string", + "password" : "string" +} +---- + + +=== Updated user +---- +PUT /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|name that need to be deleted|true|string| +|Body|body|Updated user object|false|<<_user,User>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid user supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request body +---- +{ + "id" : 0, + "lastName" : "string", + "phone" : "string", + "username" : "string", + "email" : "string", + "userStatus" : 0, + "pictures" : [ "string" ], + "firstName" : "string", + "password" : "string" +} +---- + + +==== Request path +---- +"/users/string" +---- + + +=== Delete user +---- +DELETE /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +==== Example HTTP request + +==== Request path +---- +"/users/string" +---- + + + diff --git a/src/test/resources/results/asciidoc/generated_examples/security.adoc b/src/test/resources/results/asciidoc/generated_examples/security.adoc new file mode 100644 index 00000000..635887ad --- /dev/null +++ b/src/test/resources/results/asciidoc/generated_examples/security.adoc @@ -0,0 +1,23 @@ + +[[_security]] +== Security + +=== api_key +Type : apiKey +Name : api_key +In : HEADER + +=== petstore_auth +Type : oauth2 +Flow : implicit +Token URL : http://petstore.swagger.wordnik.com/api/oauth/dialog + +[options="header", cols="1,6"] +|=== +|Name|Description +|write_pets|modify pets in your account +|read_pets|read your pets +|=== + + + diff --git a/src/test/resources/results/asciidoc/group_by_tags/definitions.adoc b/src/test/resources/results/asciidoc/group_by_tags/definitions.adoc new file mode 100644 index 00000000..e8b03ced --- /dev/null +++ b/src/test/resources/results/asciidoc/group_by_tags/definitions.adoc @@ -0,0 +1,69 @@ + +[[_definitions]] +== Definitions + +=== Category + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)|| +|name||false|string|| +|=== + + +=== Order + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|complete||false|boolean|| +|id||false|integer(int64)|| +|petId||false|integer(int64)|| +|quantity||false|integer(int32)|| +|shipDate||false|string(date-time)|| +|status|Order Status|false|string|| +|=== + + +=== Pet + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|category||false|<<_category,Category>>|| +|id||false|integer(int64)|| +|name||true|string||"doggie" +|photoUrls||true|string array|| +|status|pet status in the store|false|string|| +|tags||false|<<_tag,Tag>> array|| +|=== + + +=== Tag + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)|| +|name||false|string|| +|=== + + +=== User + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|email||false|string|| +|firstName||false|string|| +|id||false|integer(int64)|| +|lastName||false|string|| +|password||false|string|| +|phone||false|string|| +|userStatus|User Status|false|integer(int32)|| +|username||false|string|| +|=== + + + diff --git a/src/test/resources/results/asciidoc/group_by_tags/overview.adoc b/src/test/resources/results/asciidoc/group_by_tags/overview.adoc new file mode 100644 index 00000000..f087d535 --- /dev/null +++ b/src/test/resources/results/asciidoc/group_by_tags/overview.adoc @@ -0,0 +1,36 @@ += Swagger Petstore + + +[[_overview]] +== Overview +This is a sample server Petstore server. + +[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. + +For this sample, you can use the api key `special-key` to test the authorization filters + + +=== Version information +Version : 1.0.0 + +=== Contact information +Contact : apiteam@swagger.io + +=== License information +License : Apache 2.0 +License URL : http://www.apache.org/licenses/LICENSE-2.0.html +Terms of service : http://helloreverb.com/terms/ + +=== URI scheme +Host : petstore.swagger.io +BasePath : /v2 +Schemes : HTTP + +=== Tags + +* pet : Pet resource +* store : Store resource +* user : User resource + + + diff --git a/src/test/resources/results/asciidoc/group_by_tags/paths.adoc b/src/test/resources/results/asciidoc/group_by_tags/paths.adoc new file mode 100644 index 00000000..93b48b49 --- /dev/null +++ b/src/test/resources/results/asciidoc/group_by_tags/paths.adoc @@ -0,0 +1,692 @@ + +[[_paths]] +== Resources + +=== Pet +[%hardbreaks] +Pet resource + + +==== Add a new pet to the store +---- +POST /pets +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +===== Consumes + +* application/json +* application/xml + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Update an existing pet +---- +PUT /pets +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|405|Validation exception|No Content +|=== + + +===== Consumes + +* application/json +* application/xml + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Finds Pets by status +---- +GET /pets/findByStatus +---- + + +===== Description +[%hardbreaks] +Multiple status values can be provided with comma seperated strings + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|status|Status values that need to be considered for filter|false|multi string array| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid status value|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Finds Pets by tags +---- +GET /pets/findByTags +---- + + +===== Description +[%hardbreaks] +Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|tags|Tags to filter by|false|multi string array| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid tag value|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Updates a pet in the store with form data +---- +POST /pets/{petId} +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of pet that needs to be updated|true|string| +|FormData|name|Updated name of the pet|true|string| +|FormData|status|Updated status of the pet|true|string| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +===== Consumes + +* application/x-www-form-urlencoded + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Find pet by ID +---- +GET /pets/{petId} +---- + + +===== Description +[%hardbreaks] +Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of pet that needs to be fetched|true|integer(int64)| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|apiKey|<<_api_key,api_key>>| +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== Deletes a pet +---- +DELETE /pets/{petId} +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Header|api_key||true|string| +|Path|petId|Pet id to delete|true|integer(int64)| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid pet value|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +===== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Store +[%hardbreaks] +Store resource + + +==== Place an order for a pet +---- +POST /stores/order +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|order placed for purchasing the pet|false|<<_order,Order>>| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid Order|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Find purchase order by ID +---- +GET /stores/order/{orderId} +---- + + +===== Description +[%hardbreaks] +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of pet that needs to be fetched|true|string| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Delete purchase order by ID +---- +DELETE /stores/order/{orderId} +---- + + +===== Description +[%hardbreaks] +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of the order that needs to be deleted|true|string| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +=== User +[%hardbreaks] +User resource + + +==== Create user +---- +POST /users +---- + + +===== Description +[%hardbreaks] +This can only be done by the logged in user. + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Created user object|false|<<_user,User>>| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Creates list of users with given input array +---- +POST /users/createWithArray +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Creates list of users with given input array +---- +POST /users/createWithList +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Logs user into the system +---- +GET /users/login +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|password|The password for login in clear text|false|string| +|Query|username|The user name for login|false|string| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|string +|400|Invalid username/password supplied|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Logs out current logged in user session +---- +GET /users/logout +---- + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Get user by user name +---- +GET /users/{username} +---- + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_user,User>> +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Updated user +---- +PUT /users/{username} +---- + + +===== Description +[%hardbreaks] +This can only be done by the logged in user. + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|name that need to be deleted|true|string| +|Body|body|Updated user object|false|<<_user,User>>| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid user supplied|No Content +|404|User not found|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + +==== Delete user +---- +DELETE /users/{username} +---- + + +===== Description +[%hardbreaks] +This can only be done by the logged in user. + + +===== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be deleted|true|string| +|=== + + +===== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +===== Produces + +* application/json +* application/xml + + + diff --git a/src/test/resources/results/asciidoc/group_by_tags/security.adoc b/src/test/resources/results/asciidoc/group_by_tags/security.adoc new file mode 100644 index 00000000..32c7cb10 --- /dev/null +++ b/src/test/resources/results/asciidoc/group_by_tags/security.adoc @@ -0,0 +1,23 @@ + +[[_security]] +== Security + +=== api_key +Type : apiKey +Name : api_key +In : HEADER + +=== petstore_auth +Type : oauth2 +Flow : implicit +Token URL : http://petstore.swagger.io/api/oauth/dialog + +[options="header", cols="1,6"] +|=== +|Name|Description +|write_pets|modify pets in your account +|read_pets|read your pets +|=== + + + diff --git a/src/test/resources/results/asciidoc/spring_rest_docs/definitions.adoc b/src/test/resources/results/asciidoc/spring_rest_docs/definitions.adoc new file mode 100644 index 00000000..e8b03ced --- /dev/null +++ b/src/test/resources/results/asciidoc/spring_rest_docs/definitions.adoc @@ -0,0 +1,69 @@ + +[[_definitions]] +== Definitions + +=== Category + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)|| +|name||false|string|| +|=== + + +=== Order + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|complete||false|boolean|| +|id||false|integer(int64)|| +|petId||false|integer(int64)|| +|quantity||false|integer(int32)|| +|shipDate||false|string(date-time)|| +|status|Order Status|false|string|| +|=== + + +=== Pet + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|category||false|<<_category,Category>>|| +|id||false|integer(int64)|| +|name||true|string||"doggie" +|photoUrls||true|string array|| +|status|pet status in the store|false|string|| +|tags||false|<<_tag,Tag>> array|| +|=== + + +=== Tag + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|id||false|integer(int64)|| +|name||false|string|| +|=== + + +=== User + +[options="header", cols=".^1h,.^6,.^1,.^1,.^1,.^1"] +|=== +|Name|Description|Required|Schema|Default|Example +|email||false|string|| +|firstName||false|string|| +|id||false|integer(int64)|| +|lastName||false|string|| +|password||false|string|| +|phone||false|string|| +|userStatus|User Status|false|integer(int32)|| +|username||false|string|| +|=== + + + diff --git a/src/test/resources/results/asciidoc/spring_rest_docs/overview.adoc b/src/test/resources/results/asciidoc/spring_rest_docs/overview.adoc new file mode 100644 index 00000000..f087d535 --- /dev/null +++ b/src/test/resources/results/asciidoc/spring_rest_docs/overview.adoc @@ -0,0 +1,36 @@ += Swagger Petstore + + +[[_overview]] +== Overview +This is a sample server Petstore server. + +[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. + +For this sample, you can use the api key `special-key` to test the authorization filters + + +=== Version information +Version : 1.0.0 + +=== Contact information +Contact : apiteam@swagger.io + +=== License information +License : Apache 2.0 +License URL : http://www.apache.org/licenses/LICENSE-2.0.html +Terms of service : http://helloreverb.com/terms/ + +=== URI scheme +Host : petstore.swagger.io +BasePath : /v2 +Schemes : HTTP + +=== Tags + +* pet : Pet resource +* store : Store resource +* user : User resource + + + diff --git a/src/test/resources/results/asciidoc/spring_rest_docs/paths.adoc b/src/test/resources/results/asciidoc/spring_rest_docs/paths.adoc new file mode 100644 index 00000000..057aa4d4 --- /dev/null +++ b/src/test/resources/results/asciidoc/spring_rest_docs/paths.adoc @@ -0,0 +1,806 @@ + +[[_paths]] +== Paths + +=== Add a new pet to the store +---- +POST /pets +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +==== Consumes + +* application/json +* application/xml + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +==== HTTP request + + +[source,http] +---- +POST /api/pet/ HTTP/1.1 +Content-Type: application/json +Content-Length: 111 + +{"id":1,"category":{"id":1,"name":"Hund"},"name":"Wuffy","photoUrls":[],"tags":[],"status":null,"identifier":1} +---- + + + +==== HTTP response + + +[source,http] +---- +HTTP/1.1 200 OK +Content-Type: application/json +Content-Length: 7 + +SUCCESS +---- + + + +==== Curl request + +===== curl-request + +[source,bash] +---- +$ curl 'http://localhost:8080/api/pet/' -i -X POST -H 'Content-Type: application/json' -H 'Content-Length: 111' -d '{"id":1,"category":{"id":1,"name":"Hund"},"name":"Wuffy","photoUrls":[],"tags":[],"status":null,"identifier":1}' +---- + + + +=== Update an existing pet +---- +PUT /pets +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Pet object that needs to be added to the store|false|<<_pet,Pet>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|405|Validation exception|No Content +|=== + + +==== Consumes + +* application/json +* application/xml + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Finds Pets by status +---- +GET /pets/findByStatus +---- + + +==== Description +[%hardbreaks] +Multiple status values can be provided with comma seperated strings + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|status|Status values that need to be considered for filter|false|multi string array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid status value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Finds Pets by tags +---- +GET /pets/findByTags +---- + + +==== Description +[%hardbreaks] +Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|tags|Tags to filter by|false|multi string array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> array +|400|Invalid tag value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Updates a pet in the store with form data +---- +POST /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of pet that needs to be updated|true|string| +|FormData|name|Updated name of the pet|true|string| +|FormData|status|Updated status of the pet|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|405|Invalid input|No Content +|=== + + +==== Consumes + +* application/x-www-form-urlencoded + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Find pet by ID +---- +GET /pets/{petId} +---- + + +==== Description +[%hardbreaks] +Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|petId|ID of pet that needs to be fetched|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_pet,Pet>> +|400|Invalid ID supplied|No Content +|404|Pet not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|apiKey|<<_api_key,api_key>>| +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Deletes a pet +---- +DELETE /pets/{petId} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Header|api_key||true|string| +|Path|petId|Pet id to delete|true|integer(int64)| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid pet value|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* pet + + +==== Security + +[options="header", cols=".^1,.^1h,.^6"] +|=== +|Type|Name|Scopes +|oauth2|<<_petstore_auth,petstore_auth>>|write_pets,read_pets +|=== + + +=== Place an order for a pet +---- +POST /stores/order +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|order placed for purchasing the pet|false|<<_order,Order>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid Order|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +=== Find purchase order by ID +---- +GET /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of pet that needs to be fetched|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_order,Order>> +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +=== Delete purchase order by ID +---- +DELETE /stores/order/{orderId} +---- + + +==== Description +[%hardbreaks] +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|orderId|ID of the order that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid ID supplied|No Content +|404|Order not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* store + + +=== Create user +---- +POST /users +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|Created user object|false|<<_user,User>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Creates list of users with given input array +---- +POST /users/createWithArray +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Creates list of users with given input array +---- +POST /users/createWithList +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Body|body|List of user object|false|<<_user,User>> array| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Logs user into the system +---- +GET /users/login +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Query|password|The password for login in clear text|false|string| +|Query|username|The user name for login|false|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|string +|400|Invalid username/password supplied|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Logs out current logged in user session +---- +GET /users/logout +---- + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|default|successful operation|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Get user by user name +---- +GET /users/{username} +---- + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|200|successful operation|<<_user,User>> +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Updated user +---- +PUT /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|name that need to be deleted|true|string| +|Body|body|Updated user object|false|<<_user,User>>| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid user supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + +=== Delete user +---- +DELETE /users/{username} +---- + + +==== Description +[%hardbreaks] +This can only be done by the logged in user. + + +==== Parameters + +[options="header", cols=".^1h,.^1h,.^6,.^1,.^1,.^1"] +|=== +|Type|Name|Description|Required|Schema|Default +|Path|username|The name that needs to be deleted|true|string| +|=== + + +==== Responses + +[options="header", cols=".^1h,.^3,.^3,.^1"] +|=== +|HTTP Code|Description|Headers|Schema +|400|Invalid username supplied|No Content +|404|User not found|No Content +|=== + + +==== Produces + +* application/json +* application/xml + + +==== Tags + +* user + + + diff --git a/src/test/resources/results/asciidoc/spring_rest_docs/security.adoc b/src/test/resources/results/asciidoc/spring_rest_docs/security.adoc new file mode 100644 index 00000000..32c7cb10 --- /dev/null +++ b/src/test/resources/results/asciidoc/spring_rest_docs/security.adoc @@ -0,0 +1,23 @@ + +[[_security]] +== Security + +=== api_key +Type : apiKey +Name : api_key +In : HEADER + +=== petstore_auth +Type : oauth2 +Flow : implicit +Token URL : http://petstore.swagger.io/api/oauth/dialog + +[options="header", cols="1,6"] +|=== +|Name|Description +|write_pets|modify pets in your account +|read_pets|read your pets +|=== + + + diff --git a/src/test/resources/results/markdown/default/definitions.md b/src/test/resources/results/markdown/default/definitions.md new file mode 100644 index 00000000..c6a7c1e4 --- /dev/null +++ b/src/test/resources/results/markdown/default/definitions.md @@ -0,0 +1,59 @@ + + +## Definitions + +### Category + +|Name|Description|Required|Schema|Default|Example| +|---|---|---|---|---|---| +|id||false|integer(int64)||| +|name||false|string||| + + +### Order + +|Name|Description|Required|Schema|Default|Example| +|---|---|---|---|---|---| +|complete||false|boolean||| +|id||false|integer(int64)||| +|petId||false|integer(int64)||| +|quantity||false|integer(int32)||| +|shipDate||false|string(date-time)||| +|status|Order Status|false|string||| + + +### Pet + +|Name|Description|Required|Schema|Default|Example| +|---|---|---|---|---|---| +|category||false|[Category](#category)||| +|id||false|integer(int64)||| +|name||true|string||"doggie"| +|photoUrls||true|string array||| +|status|pet status in the store|false|string||| +|tags||false|[Tag](#tag) array||| + + +### Tag + +|Name|Description|Required|Schema|Default|Example| +|---|---|---|---|---|---| +|id||false|integer(int64)||| +|name||false|string||| + + +### User + +|Name|Description|Required|Schema|Default|Example| +|---|---|---|---|---|---| +|email||false|string||| +|firstName||false|string||| +|id||false|integer(int64)||| +|lastName||false|string||| +|password||false|string||| +|phone||false|string||| +|userStatus|User Status|false|integer(int32)||| +|username||false|string||| + + + diff --git a/src/test/resources/results/markdown/default/overview.md b/src/test/resources/results/markdown/default/overview.md new file mode 100644 index 00000000..433f58a8 --- /dev/null +++ b/src/test/resources/results/markdown/default/overview.md @@ -0,0 +1,36 @@ +# Swagger Petstore + + + +## Overview +This is a sample server Petstore server. + +[Learn about Swagger](http://swagger.io) or join the IRC channel `#swagger` on irc.freenode.net. + +For this sample, you can use the api key `special-key` to test the authorization filters + + +### Version information +Version : 1.0.0 + +### Contact information +Contact : apiteam@swagger.io + +### License information +License : Apache 2.0 +License URL : http://www.apache.org/licenses/LICENSE-2.0.html +Terms of service : http://helloreverb.com/terms/ + +### URI scheme +Host : petstore.swagger.io +BasePath : /v2 +Schemes : HTTP + +### Tags + +* pet : Pet resource +* store : Store resource +* user : User resource + + + diff --git a/src/test/resources/results/markdown/default/paths.md b/src/test/resources/results/markdown/default/paths.md new file mode 100644 index 00000000..26091808 --- /dev/null +++ b/src/test/resources/results/markdown/default/paths.md @@ -0,0 +1,675 @@ + + +## Paths + +### Add a new pet to the store +``` +POST /pets +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Body|body|Pet object that needs to be added to the store|false|[Pet](#pet)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|405|Invalid input|No Content| + + +#### Consumes + +* application/json +* application/xml + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Update an existing pet +``` +PUT /pets +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Body|body|Pet object that needs to be added to the store|false|[Pet](#pet)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|400|Invalid ID supplied|No Content| +|404|Pet not found|No Content| +|405|Validation exception|No Content| + + +#### Consumes + +* application/json +* application/xml + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Finds Pets by status +``` +GET /pets/findByStatus +``` + + +#### Description +Multiple status values can be provided with comma seperated strings + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Query|status|Status values that need to be considered for filter|false|multi string array|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|[Pet](#pet) array| +|400|Invalid status value|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Finds Pets by tags +``` +GET /pets/findByTags +``` + + +#### Description +Muliple tags can be provided with comma seperated strings. Use tag1, tag2, tag3 for testing. + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Query|tags|Tags to filter by|false|multi string array|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|[Pet](#pet) array| +|400|Invalid tag value|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Updates a pet in the store with form data +``` +POST /pets/{petId} +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|petId|ID of pet that needs to be updated|true|string|| +|FormData|name|Updated name of the pet|true|string|| +|FormData|status|Updated status of the pet|true|string|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|405|Invalid input|No Content| + + +#### Consumes + +* application/x-www-form-urlencoded + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Find pet by ID +``` +GET /pets/{petId} +``` + + +#### Description +Returns a pet when ID < 10. ID > 10 or nonintegers will simulate API error conditions + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|petId|ID of pet that needs to be fetched|true|integer(int64)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|[Pet](#pet)| +|400|Invalid ID supplied|No Content| +|404|Pet not found|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|apiKey|[api_key](#api_key)|| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Deletes a pet +``` +DELETE /pets/{petId} +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Header|api_key||true|string|| +|Path|petId|Pet id to delete|true|integer(int64)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|400|Invalid pet value|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* pet + + +#### Security + +|Type|Name|Scopes| +|---|---|---| +|oauth2|[petstore_auth](#petstore_auth)|write_pets,read_pets| + + +### Place an order for a pet +``` +POST /stores/order +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Body|body|order placed for purchasing the pet|false|[Order](#order)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|[Order](#order)| +|400|Invalid Order|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* store + + +### Find purchase order by ID +``` +GET /stores/order/{orderId} +``` + + +#### Description +For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|orderId|ID of pet that needs to be fetched|true|string|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|[Order](#order)| +|400|Invalid ID supplied|No Content| +|404|Order not found|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* store + + +### Delete purchase order by ID +``` +DELETE /stores/order/{orderId} +``` + + +#### Description +For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|orderId|ID of the order that needs to be deleted|true|string|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|400|Invalid ID supplied|No Content| +|404|Order not found|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* store + + +### Create user +``` +POST /users +``` + + +#### Description +This can only be done by the logged in user. + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Body|body|Created user object|false|[User](#user)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|default|successful operation|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Creates list of users with given input array +``` +POST /users/createWithArray +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Body|body|List of user object|false|[User](#user) array|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|default|successful operation|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Creates list of users with given input array +``` +POST /users/createWithList +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Body|body|List of user object|false|[User](#user) array|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|default|successful operation|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Logs user into the system +``` +GET /users/login +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Query|password|The password for login in clear text|false|string|| +|Query|username|The user name for login|false|string|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|string| +|400|Invalid username/password supplied|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Logs out current logged in user session +``` +GET /users/logout +``` + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|default|successful operation|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Get user by user name +``` +GET /users/{username} +``` + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|username|The name that needs to be fetched. Use user1 for testing.|true|string|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|200|successful operation|[User](#user)| +|400|Invalid username supplied|No Content| +|404|User not found|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Updated user +``` +PUT /users/{username} +``` + + +#### Description +This can only be done by the logged in user. + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|username|name that need to be deleted|true|string|| +|Body|body|Updated user object|false|[User](#user)|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|400|Invalid user supplied|No Content| +|404|User not found|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + +### Delete user +``` +DELETE /users/{username} +``` + + +#### Description +This can only be done by the logged in user. + + +#### Parameters + +|Type|Name|Description|Required|Schema|Default| +|---|---|---|---|---|---| +|Path|username|The name that needs to be deleted|true|string|| + + +#### Responses + +|HTTP Code|Description|Headers|Schema| +|---|---|---|---| +|400|Invalid username supplied|No Content| +|404|User not found|No Content| + + +#### Produces + +* application/json +* application/xml + + +#### Tags + +* user + + + diff --git a/src/test/resources/results/markdown/default/security.md b/src/test/resources/results/markdown/default/security.md new file mode 100644 index 00000000..d9b0b6a9 --- /dev/null +++ b/src/test/resources/results/markdown/default/security.md @@ -0,0 +1,21 @@ + + +## Security + +### api_key +Type : apiKey +Name : api_key +In : HEADER + +### petstore_auth +Type : oauth2 +Flow : implicit +Token URL : http://petstore.swagger.io/api/oauth/dialog + +|Name|Description| +|---|---| +|write_pets|modify pets in your account| +|read_pets|read your pets| + + + From 9f197074efbbb2e05490ab226d906d8e1c749de1 Mon Sep 17 00:00:00 2001 From: Robert Winkler Date: Mon, 7 Mar 2016 11:10:28 +0100 Subject: [PATCH 7/7] The line separator which should be used can be configured now. --- .../builder/document/MarkupDocument.java | 2 +- .../builder/document/PathsDocument.java | 11 ++++++-- .../config/Swagger2MarkupConfig.java | 25 ++++++++++++++++++- .../config/Swagger2MarkupConfigTest.java | 4 +-- 4 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/main/java/io/github/robwin/swagger2markup/builder/document/MarkupDocument.java b/src/main/java/io/github/robwin/swagger2markup/builder/document/MarkupDocument.java index 94ae1a7f..b0d3082f 100644 --- a/src/main/java/io/github/robwin/swagger2markup/builder/document/MarkupDocument.java +++ b/src/main/java/io/github/robwin/swagger2markup/builder/document/MarkupDocument.java @@ -71,7 +71,7 @@ public abstract class MarkupDocument { this.config = globalContext.config; this.outputPath = outputPath; - this.markupDocBuilder = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage()).withAnchorPrefix(config.getAnchorPrefix()); + this.markupDocBuilder = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage(), config.getLineSeparator()).withAnchorPrefix(config.getAnchorPrefix()); ResourceBundle labels = ResourceBundle.getBundle("io/github/robwin/swagger2markup/lang/labels", config.getOutputLanguage().toLocale()); DEFAULT_COLUMN = labels.getString("default_column"); diff --git a/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java b/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java index 84c26b92..5c9b1c5b 100644 --- a/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java +++ b/src/main/java/io/github/robwin/swagger2markup/builder/document/PathsDocument.java @@ -504,7 +504,7 @@ public class PathsDocument extends MarkupDocument { docBuilder.paragraph(parameter.getDescription()); } - MarkupDocBuilder typeInfos = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage()); + MarkupDocBuilder typeInfos = MarkupDocBuilders.documentBuilder(config.getMarkupLanguage(), config.getLineSeparator()); typeInfos.italicText(REQUIRED_COLUMN).textLine(": " + parameter.getRequired()); typeInfos.italicText(NAME_COLUMN).textLine(": " + parameter.getName()); if (!(type instanceof ObjectType)) { @@ -682,7 +682,8 @@ public class PathsDocument extends MarkupDocument { List> cells = new ArrayList<>(); List cols = Arrays.asList( new MarkupTableColumn(HTTP_CODE_COLUMN, 1).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^1h"), - new MarkupTableColumn(DESCRIPTION_COLUMN, 6).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^6"), + new MarkupTableColumn(DESCRIPTION_COLUMN, 6).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"), + new MarkupTableColumn(HEADERS_COLUMN, 6).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^3"), new MarkupTableColumn(SCHEMA_COLUMN, 1).withMarkupSpecifiers(MarkupLanguage.ASCIIDOC, ".^1")); Set responseNames; if (config.getResponseOrdering() == null) @@ -693,6 +694,12 @@ public class PathsDocument extends MarkupDocument { for (String responseName : responseNames) { Response response = responses.get(responseName); + Map headers = response.getHeaders(); + + List headersToRender = new LinkedList<>(); + if(MapUtils.isNotEmpty(headers)){ + + } if (response.getSchema() != null) { Property property = response.getSchema(); diff --git a/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java b/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java index ee5a2ddd..3990724f 100644 --- a/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java +++ b/src/main/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfig.java @@ -17,11 +17,13 @@ package io.github.robwin.swagger2markup.config; import com.google.common.base.Function; import com.google.common.collect.Ordering; +import io.github.robwin.markup.builder.LineSeparator; import io.github.robwin.markup.builder.MarkupLanguage; import io.github.robwin.swagger2markup.*; import io.github.robwin.swagger2markup.utils.IOUtils; import io.swagger.models.HttpMethod; import io.swagger.models.parameters.Parameter; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -66,6 +68,7 @@ public class Swagger2MarkupConfig { private String interDocumentCrossReferencesPrefix; private boolean flatBodyEnabled; private String anchorPrefix; + private LineSeparator lineSeparator; private String overviewDocument; private String pathsDocument; @@ -275,6 +278,10 @@ public class Swagger2MarkupConfig { return separatedDefinitionsFolder; } + public LineSeparator getLineSeparator() { + return lineSeparator; + } + public static class Builder { private static final String PROPERTIES_PREFIX = "swagger2markup."; @@ -355,6 +362,10 @@ public class Swagger2MarkupConfig { config.parameterOrderBy = OrderBy.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "parameterOrderBy")); config.propertyOrderBy = OrderBy.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "propertyOrderBy")); config.responseOrderBy = OrderBy.valueOf(safeProperties.getProperty(PROPERTIES_PREFIX + "responseOrderBy")); + String lineSeparator = safeProperties.getProperty(PROPERTIES_PREFIX + "lineSeparator"); + if(StringUtils.isNoneBlank(lineSeparator)){ + config.lineSeparator = LineSeparator.valueOf(lineSeparator); + } } private Properties defaultProperties() { @@ -783,7 +794,7 @@ public class Swagger2MarkupConfig { /** * Optionally prefix all anchors for unicity - * + *. * @param anchorPrefix anchor prefix. * @return this builder */ @@ -793,6 +804,18 @@ public class Swagger2MarkupConfig { return this; } + /** + * Specifies the line separator which should be used . + * + * @param lineSeparator the lineSeparator + * @return this builder + */ + public Builder withLineSeparator(LineSeparator lineSeparator) { + Validate.notNull(lineSeparator, "%s must no be null", "lineSeparator"); + config.lineSeparator = lineSeparator; + return this; + } + } } \ No newline at end of file diff --git a/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java b/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java index 4633b66f..a905311b 100644 --- a/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java +++ b/src/test/java/io/github/robwin/swagger2markup/config/Swagger2MarkupConfigTest.java @@ -46,8 +46,8 @@ public class Swagger2MarkupConfigTest { assertThat(config.getInlineSchemaDepthLevel()).isEqualTo(0); assertThat(config.getInterDocumentCrossReferencesPrefix()).isNull(); assertThat(config.getMarkupLanguage()).isEqualTo(MarkupLanguage.ASCIIDOC); - assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.AS_IS); - assertThat(config.getOperationOrdering()).isNull(); + assertThat(config.getOperationOrderBy()).isEqualTo(OrderBy.NATURAL); + assertThat(config.getOperationOrdering()).isNotNull(); assertThat(config.getOutputLanguage()).isEqualTo(Language.EN); assertThat(config.getOverviewDocument()).isEqualTo("overview"); assertThat(config.getParameterOrderBy()).isEqualTo(OrderBy.NATURAL);