io.github.swagger2markup.Swagger2MarkupConfig Java Examples

The following examples show how to use io.github.swagger2markup.Swagger2MarkupConfig. 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: SwaggerJsonTest.java    From alcor with Apache License 2.0 7 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 #2
Source File: PathsDocument.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
/**
 * Builds a path operation depending on generation mode.
 *
 * @param operation operation
 */
private void buildOperation(MarkupDocBuilder markupDocBuilder, SwaggerPathOperation operation, Swagger2MarkupConfig config) {
    if (config.isSeparatedOperationsEnabled()) {
        MarkupDocBuilder pathDocBuilder = copyMarkupDocBuilder(markupDocBuilder);
        applyPathOperationComponent(pathDocBuilder, operation);
        java.nio.file.Path operationFile = context.getOutputPath().resolve(operationDocumentNameResolver.apply(operation));
        pathDocBuilder.writeToFileWithoutExtension(operationFile, StandardCharsets.UTF_8);
        if (logger.isDebugEnabled()) {
            logger.debug("Separate operation file produced : '{}'", operationFile);
        }
        buildOperationRef(markupDocBuilder, operation);

    } else {
        applyPathOperationComponent(markupDocBuilder, operation);
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Operation processed : '{}' (normalized id = '{}')", operation, normalizeName(operation.getId()));
    }
}
 
Example #3
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 #4
Source File: SwaggerToAsciiDocMarkdownConfluence.java    From springrestdoc with MIT License 6 votes vote down vote up
@Test
public void test() throws URISyntaxException {
    //Given
    Path file = Paths.get(SwaggerToAsciiDocMarkdownConfluence.class.getResource(resource).toURI());
    Path outputDirectory = Paths.get(BUILD_SWAGGER_2_MARKUP_PATH + outputPath);
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //When
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withPathsGroupedBy(GroupBy.TAGS)
            .withOutputLanguage(Language.EN)
            .withMarkupLanguage(markupLanguage)
            .build();

    Swagger2MarkupConverter.from(file)
            .withConfig(config)
            .build()
            .toFolder(outputDirectory);
}
 
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: 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 #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: 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 #9
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 #10
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 #11
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 #12
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 #13
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 #14
Source File: OperationDocumentNameResolverTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndPrefix() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences("prefix_")
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    String method = HttpMethod.GET.toString();
    String path = "/test";
    SwaggerPathOperation operation = new SwaggerPathOperation(method, path, path + " " + method.toLowerCase(),
            method + " " + path, new Operation());
    assertThat(new OperationDocumentNameResolver(context).apply(operation))
            .isEqualTo("paths.adoc");
}
 
Example #15
Source File: PathOperationComponentTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithPathParamExample() throws URISyntaxException {
    String COMPONENT_NAME = "path_operation_with_path_param_example";
    Path outputDirectory = getOutputFile(COMPONENT_NAME);
    FileUtils.deleteQuietly(outputDirectory.toFile());

    Map<String, String> configMap = new HashMap<>();
    configMap.put("swagger2markup.generatedExamplesEnabled", "true");  // enable example

    //Given
    Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
    Swagger swagger = converter.getContext().getSchema();

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

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

    //When
    markupDocBuilder = new PathOperationComponent(context,
            new DefinitionDocumentResolverFromOperation(context),
            new SecurityDocumentResolver(context)).
            apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}
 
Example #16
Source File: OperationDocumentNameResolverTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndMarkdown() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .withMarkupLanguage(MarkupLanguage.MARKDOWN)
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new OperationDocumentNameResolver(context).apply(operation))
            .isEqualTo("paths.md");
}
 
Example #17
Source File: PathOperationComponentTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithQueryParamExample() throws URISyntaxException {
    String COMPONENT_NAME = "path_operation_with_query_param_example";
    Path outputDirectory = getOutputFile(COMPONENT_NAME);
    FileUtils.deleteQuietly(outputDirectory.toFile());

    Map<String, String> configMap = new HashMap<>();
    configMap.put("swagger2markup.generatedExamplesEnabled", "true");  // enable example

    //Given
    Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(configMap).build();
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).withConfig(config) .build();
    Swagger swagger = converter.getContext().getSchema();

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

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

    //When
    markupDocBuilder = new PathOperationComponent(context,
            new DefinitionDocumentResolverFromOperation(context),
            new SecurityDocumentResolver(context)).
            apply(markupDocBuilder, PathOperationComponent.parameters(pathOperations.get(0)));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

    //Then
    Path expectedFile = getExpectedFile(COMPONENT_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME));
}
 
Example #18
Source File: DefinitionDocumentResolverFromOperationTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndNoOutputPath() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);

    assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName"))
            .isNull();
}
 
Example #19
Source File: DefinitionDocumentResolverFromOperationTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName"))
            .isEqualTo("definitions.adoc");
}
 
Example #20
Source File: DefinitionDocumentResolverFromOperationTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSeparatedOperationsAndSeparatedDefinitionsAndInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedOperations()
            .withSeparatedDefinitions()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName"))
            .isEqualTo(".." + fileSeparator + "definitions" + fileSeparator + "DefinitionName.adoc");
}
 
Example #21
Source File: DefinitionDocumentResolverFromOperationTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSeparatedOperationsAndInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedOperations()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName"))
            .isEqualTo(".." + fileSeparator + "definitions.adoc");
}
 
Example #22
Source File: DefinitionDocumentResolverFromOperationTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSeparatedDefinitions() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedDefinitions()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);

    assertThat(new DefinitionDocumentResolverFromOperation(context).apply("DefinitionName")).isNull();
}
 
Example #23
Source File: OperationDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndMarkdown() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .withMarkupLanguage(MarkupLanguage.MARKDOWN)
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new OperationDocumentResolverDefault(context).apply(operation))
            .isEqualTo("paths.md");
}
 
Example #24
Source File: OperationDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndPrefix() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences("prefix_")
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new OperationDocumentResolverDefault(context).apply(operation))
            .isEqualTo("prefix_paths.adoc");
}
 
Example #25
Source File: OperationDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new OperationDocumentResolverDefault(context).apply(operation))
            .isEqualTo("paths.adoc");
}
 
Example #26
Source File: OperationDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSeparatedOperationsAndInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedOperations()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new OperationDocumentResolverDefault(context).apply(operation))
            .isEqualTo("operations" + fileSeparator + "test_get.adoc");
}
 
Example #27
Source File: DefinitionDocumentNameResolverTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndPrefix() {
    Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences("prefix_")
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName"))
            .isEqualTo("definitions.adoc");
}
 
Example #28
Source File: OperationDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSeparatedOperations() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedOperations()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);

    assertThat(new OperationDocumentResolverDefault(context).apply(operation)).isNull();
}
 
Example #29
Source File: DefinitionDocumentNameResolverTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferencesAndMarkdown() {
    Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .withMarkupLanguage(MarkupLanguage.MARKDOWN)
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName"))
            .isEqualTo("definitions.md");
}
 
Example #30
Source File: Application.java    From swagger2markup-cli with Apache License 2.0 5 votes vote down vote up
public void run() {

        Swagger2MarkupConfig swagger2MarkupConfig = null;
        if(StringUtils.isNotBlank(configFile)) {
            Configurations configs = new Configurations();
            Configuration config;
            try {
                config = configs.properties(configFile);
            } catch (ConfigurationException e) {
                throw new IllegalArgumentException("Failed to read configFile", e);
            }
            swagger2MarkupConfig = new Swagger2MarkupConfigBuilder(config).build();
        }
        Swagger2MarkupConverter.Builder converterBuilder = Swagger2MarkupConverter.from(URIUtils.create(swaggerInput));
        if(swagger2MarkupConfig != null){
            converterBuilder.withConfig(swagger2MarkupConfig);
        }
        Swagger2MarkupConverter converter = converterBuilder.build();

        if(StringUtils.isNotBlank(outputFile)){
            converter.toFile(Paths.get(outputFile).toAbsolutePath());
        }else if (StringUtils.isNotBlank(outputDir)){
            converter.toFolder(Paths.get(outputDir).toAbsolutePath());
        }else {
            throw new IllegalArgumentException("Either outputFile or outputDir option must be used");
        }
    }