@Test public void testOrderByNatural() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_ordering.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/ordering_natural"); FileUtils.deleteQuietly(outputDirectory.toFile()); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withTagOrdering(OrderBy.NATURAL) .withParameterOrdering(OrderBy.NATURAL) .withOperationOrdering(OrderBy.NATURAL) .withPathsGroupedBy(GroupBy.TAGS) .build(); //When 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/ordering_natural").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testOrderingNatural.html"); }
@Test public void testOrderByAsIs() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_ordering.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/ordering_asis"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withTagOrdering(OrderBy.AS_IS) .withParameterOrdering(OrderBy.AS_IS) .withOperationOrdering(OrderBy.AS_IS) .withDefinitionOrdering(OrderBy.AS_IS) .withPathsGroupedBy(GroupBy.TAGS) .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/ordering_asis").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testOrderingAsIs.html"); }
@Test public void testOrderByRegex() throws IOException, URISyntaxException { //Given Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_ordering_regex.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/ordering_regex"); FileUtils.deleteQuietly(outputDirectory.toFile()); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withTagOrdering(OrderBy.NATURAL) .withParameterOrdering(OrderBy.NATURAL) .withOperationOrdering(OrderBy.NATURAL) .withPathsGroupedBy(GroupBy.REGEX) .withHeaderRegex("\\/(\\w+)(\\/|\\w)*$") .build(); //When 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/ordering_regex").toURI()); DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testOrderingRegex.html"); }
builder.withOperationOrdering(OrderBy.CUSTOM); } catch (IllegalArgumentException e) { assertThat(e.getMessage()).isEqualTo("You must provide a custom comparator if orderBy == OrderBy.CUSTOM"); builder.withOperationOrdering(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING); assertThat(builder.config.getOperationOrderBy()).isEqualTo(OrderBy.CUSTOM); assertThat(builder.config.getOperationOrdering()).isEqualTo(Swagger2MarkupConfigBuilder.OPERATION_PATH_NATURAL_ORDERING);
@Override public String convertSwaggerToAsciiDoc(final String swaggerSchemaPath) { final File swaggerSchemaFile; LOG.info("Converting Swagger Schema to Ascii Doc..."); try { swaggerSchemaFile = getSchemaFile(swaggerSchemaPath); } catch (final FileNotFoundException | URISyntaxException e) { throw new SwaggerConfluenceConfigurationException("Error Locating Swagger Schema", e); } final String swaggerAsciiDoc; try { final Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder() .withMarkupLanguage(MarkupLanguage.ASCIIDOC) .withOutputLanguage(Language.EN) .withPathsGroupedBy(GroupBy.AS_IS) .withOperationOrdering(OrderBy.AS_IS) .build(); final String swaggerSchema = FileUtils.readFileToString(swaggerSchemaFile, StandardCharsets.UTF_8); swaggerAsciiDoc = Swagger2MarkupConverter.from(swaggerSchema) .withConfig(config) .build() .toString(); } catch (IOException e) { throw new SwaggerConfluenceInternalSystemException( "Error Converting Swagger Schema to AsciiDoc", e); } LOG.info("AsciiDoc Conversion Complete!"); return swaggerAsciiDoc; }