Java Code Examples for io.github.swagger2markup.Swagger2MarkupConverter#SwaggerContext

The following examples show how to use io.github.swagger2markup.Swagger2MarkupConverter#SwaggerContext . 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: SecuritySchemeDefinitionComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testSecuritySchemeDefinitionComponentWithOAuth() 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("petstore_auth");

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

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

    Path expectedFile = getExpectedFile(O_AUTH_NAME);
    DiffUtils.assertThatFileIsEqual(expectedFile, oauthOutputDirectory, getReportName(O_AUTH_NAME));

}
 
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: LicenseInfoComponentTest.java    From swagger2markup with Apache License 2.0 6 votes vote down vote up
@Test
public void testLicenseInfoComponent() throws URISyntaxException {

    Info info = new Info()
            .license(new License().name("Apache 2.0").url("http://www.apache.org/licenses/LICENSE-2.0"))
            .termsOfService("Bla bla bla");

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

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

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

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

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

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

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

}
 
Example 5
Source File: SecurityDocumentResolverTest.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 SecurityDocumentResolver(context).apply("petstore_auth"))
            .isEqualTo("security.adoc");
}
 
Example 6
Source File: SecurityDocumentResolverTest.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 SecurityDocumentResolver(context).apply("petstore_auth"))
            .isEqualTo("security.md");
}
 
Example 7
Source File: OperationDocumentNameResolverTest.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 OperationDocumentNameResolver(context).apply(operation))
            .isEqualTo("paths.adoc");
}
 
Example 8
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 9
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 10
Source File: DefinitionDocumentNameResolverTest.java    From swagger2markup with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithInterDocumentCrossReferences() {
    Swagger2MarkupConfig config = (Swagger2MarkupConfig) new Swagger2MarkupConfigBuilder()
            .withInterDocumentCrossReferences()
            .build();
    Swagger2MarkupConverter.SwaggerContext context = createContext(config);
    context.setOutputPath(Paths.get("/tmp"));

    assertThat(new DefinitionDocumentNameResolver(context).apply("DefinitionName"))
            .isEqualTo("definitions.adoc");
}
 
Example 11
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 12
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 13
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 14
Source File: OperationDocumentNameResolver.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public OperationDocumentNameResolver(Swagger2MarkupConverter.SwaggerContext context) {
    super(context);
}
 
Example 15
Source File: ContextUtils.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public static Swagger2MarkupConverter.SwaggerContext createContext(Swagger2MarkupConfig config, Swagger swagger) {
    Swagger2MarkupExtensionRegistry extensionRegistry = new Swagger2MarkupExtensionRegistryBuilder().build();
    return new Swagger2MarkupConverter.SwaggerContext(config, extensionRegistry, swagger, null, new SwaggerLabels(config));
}
 
Example 16
Source File: DocumentResolver.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public DocumentResolver(Swagger2MarkupConverter.SwaggerContext context) {
    this.context = context;
    this.markupDocBuilder = context.createMarkupDocBuilder();
    this.config = context.getConfig();
}
 
Example 17
Source File: LicenseInfoComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public LicenseInfoComponent(Swagger2MarkupConverter.SwaggerContext context) {
    super(context);
}
 
Example 18
Source File: ProducesComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public ProducesComponent(Swagger2MarkupConverter.SwaggerContext context) {
    super(context);
}
 
Example 19
Source File: OperationDocumentResolverDefaultTest.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
@Test
public void testDefault() {
    Swagger2MarkupConverter.SwaggerContext context = createContext();

    assertThat(new OperationDocumentResolverDefault(context).apply(operation)).isNull();
}
 
Example 20
Source File: MarkupComponent.java    From swagger2markup with Apache License 2.0 4 votes vote down vote up
public MarkupComponent(Swagger2MarkupConverter.SwaggerContext context) {
    this.context = context;
    this.config = context.getConfig();
    this.extensionRegistry = context.getExtensionRegistry();
    this.labels = context.getLabels();
}