io.github.swagger2markup.Swagger2MarkupConverter Java Examples

The following examples show how to use io.github.swagger2markup.Swagger2MarkupConverter. 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: ExternalDocsComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testExternalDocsComponent() throws URISyntaxException {
 //Given
 Path file = Paths.get(DefinitionComponentTest.class.getResource("/yaml/swagger_petstore_20160612.yaml").toURI());
 Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
 Swagger swagger = converter.getContext().getSchema();

 ExternalDocs externalDocs = swagger.getExternalDocs();
 Assert.assertNotNull(externalDocs);

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

 //When
 markupDocBuilder = new ExternalDocsComponent(context).apply(markupDocBuilder, ExternalDocsComponent.parameters(externalDocs, OverviewDocument.SECTION_TITLE_LEVEL));
 markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #3
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 #4
Source File: DefinitionComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefinitionComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(DefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSchema();

    Model petModel = swagger.getDefinitions().get("Pet");

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

    //When
    markupDocBuilder = new DefinitionComponent(context, new DefinitionDocumentResolverFromDefinition(context))
            .apply(markupDocBuilder, DefinitionComponent.parameters("Pet", petModel, 2));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #5
Source File: ParameterTableComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testParameterTableComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(ParameterTableComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).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 ParameterTableComponent(context, new DefinitionDocumentResolverFromOperation(context))
            .apply(markupDocBuilder, ParameterTableComponent.parameters(pathOperations.get(0), new ArrayList<>(), 3));

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #6
Source File: ResponsesComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testResponsesComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(ResponsesComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSchema();

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

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

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

    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #7
Source File: PropertiesTableComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testPropertiesTableComponent() throws URISyntaxException {
    //Given
    Path file = Paths.get(PropertiesTableComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSchema();

    Model petModel = swagger.getDefinitions().get("Pet");

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

    List<ObjectType> localDefinitions = new ArrayList<>();
    //When
    markupDocBuilder = new PropertiesTableComponent(context,
            new DefinitionDocumentResolverFromDefinition(context))
            .apply(markupDocBuilder, PropertiesTableComponent.parameters(petModel.getProperties(),
                    "Pet", localDefinitions));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #8
Source File: ConsumesComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testConsumesComponent() throws URISyntaxException {
    List<String> consumes = new ArrayList<>();
    consumes.add("application/json");
    consumes.add("application/xml");

    Swagger2MarkupConverter.SwaggerContext context = createContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    markupDocBuilder = new ConsumesComponent(context).apply(markupDocBuilder, ConsumesComponent.parameters(
            consumes, OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #9
Source File: TagsComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testTagsComponent() throws URISyntaxException {
    List<Tag> tags = new ArrayList<>();
    tags.add(new Tag().name("Tag1").description("description"));
    tags.add(new Tag().name("Tag2"));

    Swagger2MarkupConverter.SwaggerContext context = createContext();
    MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder();

    markupDocBuilder = new TagsComponent(context).apply(markupDocBuilder, TagsComponent.parameters(tags, OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8);

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

}
 
Example #10
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 #11
Source File: SwaggerUtils.java    From swagger-showdoc with Apache License 2.0 6 votes vote down vote up
private static String generateMd(Swagger swagger, String k, Path swaggerPath,String swaggerUiUrl){
    StringBuilder builder = new StringBuilder();

    Map<String, Path> paths = new HashMap<>();
    paths.put(k,swaggerPath);
    swagger.setPaths(paths);

    Swagger2MarkupConverter swagger2MarkupConverter = XforcceSwagger2MarkupConverter.from(swagger).withConfig(config).build();
    Swagger2MarkupConverter.Context context = swagger2MarkupConverter.getContext();
    XforcceSwagger2MarkupConverter xforcceSwagger2MarkupConverter = new XforcceSwagger2MarkupConverter(context);

    builder.append(xforcceSwagger2MarkupConverter.toString()).append("\n").append("#### 在线调试").append("\n").append("[模拟调用](").append(swaggerUiUrl).append(getExternalDocs(swaggerPath)).append(")");

    String s = SwaggerUtils.doPathWithParameter(swagger, swaggerPath);
    builder.append(s);
    return builder.toString();
}
 
Example #12
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 #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: 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 #15
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 #16
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 #17
Source File: SecuritySchemeDefinitionComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testSecuritySchemeDefinitionComponentWithApiKey() throws URISyntaxException {
    //Given
    Path file = Paths.get(SecuritySchemeDefinitionComponentTest.class.getResource("/yaml/swagger_petstore.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSchema();

    SecuritySchemeDefinition securitySchemeDefinition = swagger.getSecurityDefinitions().get("api_key");

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

    markupDocBuilder = new SecuritySchemeDefinitionComponent(context).apply(
            markupDocBuilder, SecuritySchemeDefinitionComponent.parameters("api_key",
                    securitySchemeDefinition,
                    OverviewDocument.SECTION_TITLE_LEVEL));
    markupDocBuilder.writeToFileWithoutExtension(apiKeyOutputDirectory, StandardCharsets.UTF_8);

    Path expectedFile = getExpectedFile(API_KEY_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, apiKeyOutputDirectory, getReportName(API_KEY_NAME));

}
 
Example #18
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 #19
Source File: OperationDocumentNameResolverTest.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 OperationDocumentNameResolver(context).apply(operation))
            .isEqualTo("paths.adoc");
}
 
Example #20
Source File: ParameterTableComponent.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
ParameterTableComponent(Swagger2MarkupConverter.SwaggerContext context,
                        DocumentResolver definitionDocumentResolver) {
    super(context);
    this.definitionDocumentResolver = Validate.notNull(definitionDocumentResolver, "DocumentResolver must not be null");
    this.tableComponent = new TableComponent(context);

}
 
Example #21
Source File: OperationDocumentNameResolverTest.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 OperationDocumentNameResolver(context).apply(operation))
            .isEqualTo("operations" + fileSeparator + "test_get.adoc");
}
 
Example #22
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");
        }
    }
 
Example #23
Source File: DefinitionsDocument.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
public DefinitionsDocument(Swagger2MarkupConverter.SwaggerContext context) {
    super(context);
    if (config.isSeparatedDefinitionsEnabled()) {
        if (logger.isDebugEnabled()) {
            logger.debug("Create separated definition files is enabled.");
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("Create separated definition files is disabled.");
        }
    }
    this.definitionDocumentNameResolver = new DefinitionDocumentNameResolver(context);
    this.definitionComponent = new DefinitionComponent(context, new DefinitionDocumentResolverFromDefinition(context));
    this.definitionDocumentResolverDefault = new DefinitionDocumentResolverDefault(context);
}
 
Example #24
Source File: DefinitionDocumentResolverDefaultTest.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 DefinitionDocumentResolverDefault(context).apply("DefinitionName"))
            .isEqualTo("prefix_definitions.adoc");
}
 
Example #25
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 #26
Source File: PathOperationComponentTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testInlineSchema() throws URISyntaxException {
    String COMPONENT_NAME = "path_operation_inline_schema";
    Path outputDirectory = getOutputFile(COMPONENT_NAME);
    FileUtils.deleteQuietly(outputDirectory.toFile());

    //Given
    Path file = Paths.get(PathOperationComponentTest.class.getResource("/yaml/swagger_inlineSchema.yaml").toURI());
    Swagger2MarkupConverter converter = Swagger2MarkupConverter.from(file).build();
    Swagger swagger = converter.getContext().getSchema();

    io.swagger.models.Path path = swagger.getPaths().get("/LaunchCommand");
    List<SwaggerPathOperation> pathOperations = PathUtils.toPathOperationsList("/LaunchCommand", 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 #27
Source File: DefinitionDocumentResolverDefaultTest.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 DefinitionDocumentResolverDefault(context).apply("DefinitionName")).isNull();
}
 
Example #28
Source File: DefinitionDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSeparatedDefinitionsAndInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder()
            .withSeparatedDefinitions()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentResolverDefault(context).apply("DefinitionName"))
            .isEqualTo("definitions" + fileSeparator + "DefinitionName.adoc");
}
 
Example #29
Source File: DefinitionDocumentResolverDefaultTest.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 DefinitionDocumentResolverDefault(context).apply("DefinitionName"))
            .isEqualTo("definitions.adoc");
}
 
Example #30
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");
}