io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder Java Examples

The following examples show how to use io.github.swagger2markup.builder.Swagger2MarkupConfigBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testByTagsWithMissingTag() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_missing_tag.json").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/generated");
    FileUtils.deleteQuietly(outputDirectory.toFile());
    //When
    try {
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withPathsGroupedBy(GroupBy.TAGS)
                .build();

        Swagger2MarkupConverter.from(file)
                .withConfig(config)
                .build()
                .toFolder(outputDirectory);
        // If NullPointerException was not thrown, test would fail the specified message
        failBecauseExceptionWasNotThrown(NullPointerException.class);
    } catch (Exception e) {
        assertThat(e).hasMessage("Can't GroupBy.TAGS. Operation 'updatePet' has no tags");
    }
}
 
Example #2
Source File: SwaggerJsonTest.java    From alcor with Apache License 2.0 6 votes vote down vote up
@Test
public void createSpringfoxSwaggerJson() throws Exception{
    String outputDir = System.getProperty("io.springfox.staticdocs.outputDir");
    MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs")
        .accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andReturn();
    
    MockHttpServletResponse response = mvcResult.getResponse();
    String swaggerJson = response.getContentAsString();
    Files.createDirectories(Paths.get(outputDir));
    try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){
        writer.write(swaggerJson);
    }

    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
        .withGeneratedExamples()
        .withInterDocumentCrossReferences()
        .build();
    Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json"))
        .withConfig(config)
        .build()
        .toFile(Paths.get(outputDir, "swagger"));
}
 
Example #3
Source File: Swagger2MarkupTest.java    From SpringBootBucket with MIT License 6 votes vote down vote up
/**
     * 将swagger.yaml或swagger.json转换成漂亮的 AsciiDoc
     * 访问:http://localhost:9095/v2/api-docs
     * 将页面结果保存为src/main/resources/swagger.json
     */
    private void convertAsciidoc(String swaggerStr) {
//        Path localSwaggerFile = Paths.get(System.getProperty("swaggerOutputDir"), "swagger.json");
        Path outputFile = Paths.get(System.getProperty("asciiDocOutputDir"));
        Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
                .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
                .withOutputLanguage(Language.ZH)
                .withPathsGroupedBy(GroupBy.TAGS)
                .withGeneratedExamples()
                .withoutInlineSchema()
                .build();
        Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(swaggerStr)
                .withConfig(config)
                .build();
        converter.toFile(outputFile);
    }
 
Example #4
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithBasePathPrefix() throws 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");
}
 
Example #5
Source File: SwaggerJsonTest.java    From alcor with Apache License 2.0 6 votes vote down vote up
@Test
public void createSpringfoxSwaggerJson() throws Exception{
    String outputDir = System.getProperty("io.springfox.staticdocs.outputDir");
    MvcResult mvcResult = this.mockMvc.perform(get("/v2/api-docs")
        .accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andReturn();
    
    MockHttpServletResponse response = mvcResult.getResponse();
    String swaggerJson = response.getContentAsString();
    Files.createDirectories(Paths.get(outputDir));
    try(BufferedWriter writer = Files.newBufferedWriter(Paths.get(outputDir, "swagger.json"), StandardCharsets.UTF_8)){
        writer.write(swaggerJson);
    }

    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
        .withGeneratedExamples()
        .withInterDocumentCrossReferences()
        .build();
    Swagger2MarkupConverter.from(Paths.get(outputDir,"swagger.json"))
        .withConfig(config)
        .build()
        .toFile(Paths.get(outputDir, "swagger"));
}
 
Example #6
Source File: MarkdownConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferences() throws IOException, URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/markdown/idxref");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withMarkupLanguage(MarkupLanguage.MARKDOWN)
            .withInterDocumentCrossReferences()
            .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/markdown/idxref").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithInterDocumentCrossReferences.html");
}
 
Example #7
Source File: Swagger2ToDocTest.java    From singleton with Eclipse Public License 2.0 6 votes vote down vote up
@Before
public void generateAsciiDoc() throws Exception {
	MvcResult mvcResult = this.mockMvc.perform(get(this.groupPath + "v1").accept(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk()).andReturn();
	MockHttpServletResponse response = mvcResult.getResponse();
	Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withFlatBody().withListDelimiter()
			.withoutInlineSchema().withInterDocumentCrossReferences().withGeneratedExamples()
			.withPathsGroupedBy(GroupBy.TAGS).build();

	String swaggerJsonV1 = response.getContentAsString();
	Swagger2MarkupConverter.from(swaggerJsonV1).withConfig(config).build().toFolder(Paths.get(outputDirV1));

	mvcResult = this.mockMvc.perform(get(this.groupPath + "v2").accept(MediaType.APPLICATION_JSON))
			.andExpect(status().isOk()).andReturn();
	response = mvcResult.getResponse();
	String swaggerJsonV2 = response.getContentAsString();

	Swagger2MarkupConverter.from(swaggerJsonV2).withConfig(config).build().toFolder(Paths.get(outputDirV2));
}
 
Example #8
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithExamples() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json"), StandardCharsets.UTF_8);
    Path outputDirectory = Paths.get("build/test/asciidoc/examples");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .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/examples").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithExamples.html");
}
 
Example #9
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithGeneratedRecursiveExamples() throws IOException, URISyntaxException {
    // Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_recursion.json"), StandardCharsets.UTF_8);
    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");
}
 
Example #10
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithGeneratedExamplesAndRequiredQueryParameters() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_examples_required_parameters.yaml"), StandardCharsets.UTF_8);
    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");
}
 
Example #11
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithGeneratedInlineResponseExamples() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_examples_inline_response.yaml"), StandardCharsets.UTF_8);
    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");
}
 
Example #12
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithExamplesAndMimeTypesSuffix() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples_suffix.json"), StandardCharsets.UTF_8);
    Path outputDirectory = Paths.get("build/test/asciidoc/examples_suffix");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .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/examples_suffix").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithExamples.html");
}
 
Example #13
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithInlineSchema() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/inline_schema");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .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/inline_schema").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithInlineSchema.html");
}
 
Example #14
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithInlineSchemaAndFlatBody() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/inline_schema_flat_body");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withFlatBody()
            .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/inline_schema_flat_body").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithInlineSchemaAndFlatBody.html");
}
 
Example #15
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testGroupedByTags() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/group_by_tags");
    FileUtils.deleteQuietly(outputDirectory.toFile());
    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .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/group_by_tags").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testGroupedByTags.html");
}
 
Example #16
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithGeneratedExamples() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json"), StandardCharsets.UTF_8);
    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");
}
 
Example #17
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSeparatedDefinitions() throws IOException, URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/generated");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedDefinitions()
            .build();
    Swagger2MarkupConverter.from(file).withConfig(config).build()
            .toFolder(outputDirectory);

    //Then
    String[] files = outputDirectory.toFile().list();
    expectedFiles.add("definitions");
    assertThat(files).hasSize(5).containsAll(expectedFiles);

    Path definitionsDirectory = outputDirectory.resolve("definitions");
    String[] definitions = definitionsDirectory.toFile().list();
    assertThat(definitions).hasSize(5).containsAll(
            asList("Category.adoc", "Order.adoc", "Pet.adoc", "Tag.adoc", "User.adoc"));
}
 
Example #18
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithSeparatedOperations() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/generated");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withSeparatedOperations()
            .build();
    Swagger2MarkupConverter.from(file).withConfig(config).build()
            .toFolder(outputDirectory);

    //Then
    String[] files = outputDirectory.toFile().list();
    expectedFiles.add("operations");
    assertThat(files).hasSize(5).containsAll(expectedFiles);

    Path pathsDirectory = outputDirectory.resolve("operations");
    String[] paths = pathsDirectory.toFile().list();
    assertThat(paths).hasSize(18);
}
 
Example #19
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithAsciidocContentInTables() throws URISyntaxException {

    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore_with_adoc_content.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/generated");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withSwaggerMarkupLanguage(MarkupLanguage.ASCIIDOC)
            .build();

    Swagger2MarkupConverter.from(file).withConfig(config).build()
            .toFolder(outputDirectory);

    //Then
    String[] files = outputDirectory.toFile().list();
    assertThat(files).hasSize(4).containsAll(expectedFiles);

}
 
Example #20
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
private void testWithOutputLanguage(Language language, String outputFilename, String expected) throws IOException, URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/language");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withOutputLanguage(language)
            .build();
    Swagger2MarkupConverter.from(file)
            .withConfig(config)
            .build()
            .toFolder(outputDirectory);

    //Then
    assertThat(new String(Files.readAllBytes(outputDirectory.resolve(outputFilename)), StandardCharsets.UTF_8))
            .contains(expected);
}
 
Example #21
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithMaps() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_maps.json").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/maps");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withTagOrdering(OrderBy.AS_IS)
            .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/maps").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithMaps.html");
}
 
Example #22
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithEnums() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_enums.json").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/enums");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    Map<String, String> configMap = new HashMap<>();
    configMap.put("swagger2markup.generatedExamplesEnabled", "true");  // enable examples generation
    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder(configMap)
            .withMarkupLanguage(MarkupLanguage.ASCIIDOC)
            .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/enums").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithEnums.html");
}
 
Example #23
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithValidators() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_validators.json").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/validators");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .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/validators").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithValidators.html");
}
 
Example #24
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithPolymorphism() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/json/swagger_polymorphism.json").toURI());
    Path outputDirectory = Paths.get("build/test/asciidoc/polymorphism");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .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/polymorphism").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithPolymorphism.html");
}
 
Example #25
Source File: MarkdownConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testToFolder() throws IOException, URISyntaxException {
    //Given
    Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/markdown/to_folder");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withMarkupLanguage(MarkupLanguage.MARKDOWN)
            .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/markdown/to_folder").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testToFolder.html");
}
 
Example #26
Source File: BodyParameterComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testBodyParameterComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(AsciidocConverterTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder().withFlatBody().build();
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config).build();
    Swagger swagger = converter.getContext().getSchema();

    io.swagger.models.Path path = swagger.getPaths().get("/pets");
    List<SwaggerPathOperation> pathOperations = PathUtils.toPathOperationsList("/pets", path);

    Swagger2MarkupConverter.SwaggerContext context = converter.getContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    //When
    markupDocBuilder = new BodyParameterComponent(converter.getContext(),
            new DefinitionDocumentResolverFromOperation(context))
            .apply(markupDocBuilder, BodyParameterComponent.parameters(pathOperations.get(0), new ArrayList<>()));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));

}
 
Example #27
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithPageBreaks() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/json/swagger_examples.json"), StandardCharsets.UTF_8);
    Path outputDirectory = Paths.get("build/test/asciidoc/page_breaks");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withPageBreaks(new ArrayList<>(asList(PageBreakLocations.BEFORE_OPERATION, PageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST)))
            .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/page_breaks").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testWithPageBreaks.html");
}
 
Example #28
Source File: MarkdownConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testFreeFormWithEmptyCurlyBracket() throws IOException, URISyntaxException {
    //Given
    Path file = Paths.get(MarkdownConverterTest.class.getResource("/yaml/swagger_freeform_with_emtpy_curly_brackets.yaml").toURI());
    Path outputDirectory = Paths.get("build/test/markdown/freeform");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedDefinitions()
            .withMarkupLanguage(MarkupLanguage.MARKDOWN)
            .build();
    Swagger2MarkupConverter.from(file)
            .withConfig(config)
            .build()
            .toFolder(outputDirectory);

    // Then
    String[] files = outputDirectory.toFile().list();
    expectedFiles.add("definitions");
    assertThat(files).hasSize(5).containsAll(expectedFiles);

    Path expectedFilesDirectory = Paths.get(MarkdownConverterTest.class.getResource("/expected/markdown/freeform").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "freeform.html");

}
 
Example #29
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testExamplesInUrl() throws IOException, URISyntaxException {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_url_examples.yaml"), StandardCharsets.UTF_8);
    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");
}
 
Example #30
Source File: AsciidocConverterTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testRequestExamplesWithCurl() throws IOException, URISyntaxException  {
    //Given
    String swaggerJsonString = IOUtils.toString(getClass().getResourceAsStream("/yaml/swagger_url_examples.yaml"), StandardCharsets.UTF_8);
    Path outputDirectory = Paths.get("build/test/asciidoc/url_examples_using_curl");
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config =  new Swagger2MarkupConfigBuilder()
            .withPageBreaks(new ArrayList<>(asList(PageBreakLocations.BEFORE_OPERATION, PageBreakLocations.BEFORE_OPERATION_EXAMPLE_REQUEST)))
            .withRequestExamplesFormat("curl")
            .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_using_curl").toURI());
    DiffUtils.assertThatAllFilesAreEqual(expectedFilesDirectory, outputDirectory, "testExamplesInUrlUsingCurl.html");
}