@Test public void testWithGeneratedRecursiveExamples() throws IOException, URISyntaxException { // Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_recursion.json")); Path outputDirectory = Paths.get("build/test/asciidoc/generated_recursion_examples"); FileUtils.deleteQuietly(outputDirectory.toFile()); // When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withoutInlineSchema().withGeneratedExamples().build(); Swagger2MarkupConverter.from(swaggerJsonString).withConfig(config).build().toFolder(outputDirectory); // Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_recursion_examples").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedRecursiveExamples.html"); }
@Test public void testWithGeneratedExamples() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json")); Path outputDirectory = Paths.get("build/test/asciidoc/generated_examples"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(swaggerJsonString) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_examples").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedExamples.html"); }
@Test public void testWithGeneratedExamplesAndRequiredQueryParameters() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_examples_required_parameters.yaml")); Path outputDirectory = Paths.get("build/test/asciidoc/generated_examples_required_parameters"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(swaggerJsonString) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_examples_required_parameters").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedExamplesAndRequiredParameters.html"); }
@Test public void testWithGeneratedInlineResponseExamples() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_examples_inline_response.yaml")); Path outputDirectory = Paths.get("build/test/asciidoc/generated_examples_inline_response"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(swaggerJsonString) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/generated_examples_inline_response").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithGeneratedInlineResponseExamples.html"); }
@Test public void testExamplesInUrl() throws IOException, URISyntaxException { //Given String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_url_examples.yaml")); Path outputDirectory = Paths.get("build/test/asciidoc/url_examples"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withPageBreaks(new ArrayList<>(asList(PageBreakLocations.BEFORE_OPERATION, PageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST))) .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(swaggerJsonString) .withConfig(config) .build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/url_examples").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testExamplesInUrl.html"); } }
@Test public void testWithBasePathPrefix() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_examples.json").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/basepathprefix"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withBasePathPrefix() .withGeneratedExamples() .build(); Swagger2MarkupConverter.from(file).withConfig(config).build() .toFolder(outputDirectory); //Then String[] files = outputDirectory.toFile().list(); assertThat(files).hasSize(4).containsAll(expectedFiles); Path expectedFilesDirectory = Paths.get(AsciidocConverterTest.class.getResource("/expected/asciidoc/basepathprefix").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithBasePathPrefix.html"); }